From 4ba10139696352430c300b2c625759146abe1e0d Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Wed, 13 Jan 2021 09:12:03 +0100 Subject: [PATCH] Add more sections unit tests --- tests/SectionsTest.php | 50 ++++++++++++++++++++++++++++++++++++++++++ tests/TestCase.php | 8 +++++++ 2 files changed, 58 insertions(+) diff --git a/tests/SectionsTest.php b/tests/SectionsTest.php index a980b0e..9e702f9 100644 --- a/tests/SectionsTest.php +++ b/tests/SectionsTest.php @@ -2,6 +2,7 @@ namespace romanzipp\Seo\Test; +use romanzipp\Seo\Services\SeoService; use romanzipp\Seo\Structs\Meta; class SectionsTest extends TestCase @@ -54,4 +55,53 @@ public function testSectionsDoNotMatch() self::assertCount(1, seo()->section('secondary')->getStructs()); self::assertSame('secondary', (string) seo()->section('secondary')->getStruct(Meta::class)->getComputedAttribute('section')); } + + public function testSectionPassedAsParameterToHelper() + { + seo('secondary')->twitter('card', 'default'); + + self::assertSame( + seo()->section('secondary')->getStructs(), + seo('secondary')->getStructs() + ); + } + + public function testSectionSetterOnMutableInstance() + { + $seo = app(SeoService::class); + + $seo->section('secondary'); + + $seo->twitter('card', 'default'); + $seo->twitter('author', 'Roman'); + + self::assertCount(2, $seo->getStructs()); + + self::assertSame( + $seo->getStructs(), + seo('secondary')->getStructs() + ); + } + + public function testSectionRender() + { + seo()->twitter('card', 'default'); + + seo()->section('secondary')->twitter('card', 'secondary'); + + self::assertEquals( + '', + seo()->render()->toHtml() + ); + + self::assertEquals( + '', + seo()->section('secondary')->render()->toHtml() + ); + + self::assertEquals( + '', + seo('secondary')->render()->toHtml() + ); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index d6eac54..e78003c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,11 +4,19 @@ use Orchestra\Testbench\TestCase as BaseTestCase; use PHPUnit\Framework\Constraint\RegularExpression; +use romanzipp\Seo\Builders\StructBuilder; use romanzipp\Seo\Facades\Seo; use romanzipp\Seo\Providers\SeoServiceProvider; abstract class TestCase extends BaseTestCase { + public function setUp(): void + { + parent::setUp(); + + StructBuilder::$separator = PHP_EOL; + StructBuilder::$indent = null; + } protected function getPackageProviders($app) { return [