From b0eaebd894dd484ee5f3c8e9a21e0070bce58e11 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Mon, 12 Oct 2020 10:13:17 +0200 Subject: [PATCH] Add more array format tests --- tests/ArrayFormatTest.php | 146 +++++++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 33 deletions(-) diff --git a/tests/ArrayFormatTest.php b/tests/ArrayFormatTest.php index da36361..b8c8f0f 100644 --- a/tests/ArrayFormatTest.php +++ b/tests/ArrayFormatTest.php @@ -2,6 +2,7 @@ namespace romanzipp\Seo\Test; +use romanzipp\Seo\Structs\Link; use romanzipp\Seo\Structs\Meta; use romanzipp\Seo\Structs\Meta\Description; use romanzipp\Seo\Structs\Meta\OpenGraph; @@ -10,49 +11,85 @@ class ArrayFormatTest extends TestCase { - public function setUp(): void + // Title + + public function testTitleIndex() { - parent::setUp(); + seo()->addFromArray([ + 'title' => 'Foo', + ]); + + $this->assertCount(3, seo()->getStructs()); + + $this->assertInstanceOf(Title::class, $struct = seo()->getStruct(Title::class)); + $this->assertEquals('Foo', (string) $struct->getBody()); + + $this->assertInstanceOf(Twitter::class, $struct = seo()->getStruct(Twitter::class)); + $this->assertEquals('Foo', (string) $struct->getComputedAttribute('content')); + + $this->assertInstanceOf(OpenGraph::class, $struct = seo()->getStruct(OpenGraph::class)); + $this->assertEquals('Foo', (string) $struct->getComputedAttribute('content')); + } + public function testTitleIndexTagOnly() + { config([ 'seo.shorthand.title.tag' => true, 'seo.shorthand.title.opengraph' => false, 'seo.shorthand.title.twitter' => false, - 'seo.shorthand.description.tag' => true, - 'seo.shorthand.description.opengraph' => false, - 'seo.shorthand.description.twitter' => false, ]); - } - public function testAddingSingleSchema() - { seo()->addFromArray([ 'title' => 'Foo', ]); $this->assertCount(1, seo()->getStructs()); - $this->assertInstanceOf(Title::class, $title = seo()->getStruct(Title::class)); - $this->assertEquals('Foo', (string) $title->getBody()); + $this->assertInstanceOf(Title::class, $struct = seo()->getStruct(Title::class)); + $this->assertEquals('Foo', (string) $struct->getBody()); } - public function testAddingMultipleSingleSchemas() + // Description + + public function testDescriptionIndex() { seo()->addFromArray([ - 'title' => 'Foo', - 'description' => 'Bar', + 'description' => 'Foo', ]); - $this->assertCount(2, seo()->getStructs()); + $this->assertCount(3, seo()->getStructs()); + + $this->assertInstanceOf(Description::class, $struct = seo()->getStruct(Description::class)); + $this->assertEquals('Foo', (string) $struct->getComputedAttribute('content')); - $this->assertInstanceOf(Title::class, $title = seo()->getStruct(Title::class)); - $this->assertEquals('Foo', (string) $title->getBody()); + $this->assertInstanceOf(Twitter::class, $struct = seo()->getStruct(Twitter::class)); + $this->assertEquals('Foo', (string) $struct->getComputedAttribute('content')); + + $this->assertInstanceOf(OpenGraph::class, $struct = seo()->getStruct(OpenGraph::class)); + $this->assertEquals('Foo', (string) $struct->getComputedAttribute('content')); + } + + public function testDescriptionIndexTagOnly() + { + config([ + 'seo.shorthand.description.tag' => true, + 'seo.shorthand.description.opengraph' => false, + 'seo.shorthand.description.twitter' => false, + ]); + + seo()->addFromArray([ + 'description' => 'Foo', + ]); + + $this->assertCount(1, seo()->getStructs()); - $this->assertInstanceOf(Description::class, $description = seo()->getStruct(Description::class)); - $this->assertEquals('Bar', (string) $description->getComputedAttribute('content')); + $this->assertInstanceOf(Description::class, $struct = seo()->getStruct(Description::class)); + $this->assertEquals('Foo', (string) $struct->getComputedAttribute('content')); } - public function testAddingNestedSchema() + // Twitter + + public function testTwitterIndex() { seo()->addFromArray([ 'twitter' => [ @@ -67,29 +104,26 @@ public function testAddingNestedSchema() $this->assertEquals('summary', (string) $struct->getComputedAttribute('content')); } - public function testAddingMultipleNestedSchemas() + // OG + + public function testOpenGraphIndex() { seo()->addFromArray([ - 'twitter' => [ - 'card' => 'summary', - ], 'og' => [ 'locale' => 'de', ], ]); - $this->assertCount(2, seo()->getStructs()); - - $this->assertInstanceOf(Twitter::class, $twitter = seo()->getStruct(Twitter::class)); - $this->assertEquals('twitter:card', (string) $twitter->getComputedAttribute('name')); - $this->assertEquals('summary', (string) $twitter->getComputedAttribute('content')); + $this->assertCount(1, seo()->getStructs()); - $this->assertInstanceOf(OpenGraph::class, $og = seo()->getStruct(OpenGraph::class)); - $this->assertEquals('og:locale', (string) $og->getComputedAttribute('property')); - $this->assertEquals('de', (string) $og->getComputedAttribute('content')); + $this->assertInstanceOf(OpenGraph::class, $struct = seo()->getStruct(OpenGraph::class)); + $this->assertEquals('og:locale', (string) $struct->getComputedAttribute('property')); + $this->assertEquals('de', (string) $struct->getComputedAttribute('content')); } - public function testAddingAttributeSchema() + // Meta + + public function testMetaIndex() { seo()->addFromArray([ 'meta' => [ @@ -107,7 +141,7 @@ public function testAddingAttributeSchema() $this->assertEquals('Roman Zipp', (string) $struct->getComputedAttribute('content')); } - public function testAddingMultipleAttributeSchemas() + public function testMetaIndexMultiple() { seo()->addFromArray([ 'meta' => [ @@ -132,4 +166,50 @@ public function testAddingMultipleAttributeSchemas() $this->assertEquals('theme-color', (string) $struct->getComputedAttribute('name')); $this->assertEquals('#3053C6', (string) $struct->getComputedAttribute('content')); } + + // Link + + public function testLinkIndex() + { + seo()->addFromArray([ + 'link' => [ + [ + 'rel' => 'icon', + 'href' => '/favicon.ico', + ], + ], + ]); + + $this->assertCount(1, seo()->getStructs()); + + $this->assertInstanceOf(Link::class, $struct = seo()->getStruct(Link::class)); + $this->assertEquals('icon', (string) $struct->getComputedAttribute('rel')); + $this->assertEquals('/favicon.ico', (string) $struct->getComputedAttribute('href')); + } + + public function testLinkIndexMultiple() + { + seo()->addFromArray([ + 'link' => [ + [ + 'rel' => 'icon', + 'href' => '/favicon.ico', + ], + [ + 'rel' => 'preload', + 'href' => '/font.woff2', + ], + ], + ]); + + $this->assertCount(2, seo()->getStructs()); + + $this->assertInstanceOf(Link::class, $struct = seo()->getStructs()[0]); + $this->assertEquals('icon', (string) $struct->getComputedAttribute('rel')); + $this->assertEquals('/favicon.ico', (string) $struct->getComputedAttribute('href')); + + $this->assertInstanceOf(Link::class, $struct = seo()->getStructs()[1]); + $this->assertEquals('preload', (string) $struct->getComputedAttribute('rel')); + $this->assertEquals('/font.woff2', (string) $struct->getComputedAttribute('href')); + } }