From edf2607c28f7a14c4c5a082cf05efdf9542fe925 Mon Sep 17 00:00:00 2001 From: Boly38 Date: Thu, 31 May 2018 14:10:30 +0200 Subject: [PATCH] improve WebSite context - add publisher,inLanguage, dateCreated, dateModified, datePublished - add unit tests --- src/ContextTypes/WebSite.php | 5 ++ tests/ContextTypes/ArticleTest.php | 22 +++++++++ tests/ContextTypes/WebSiteTest.php | 74 ++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 5 deletions(-) diff --git a/src/ContextTypes/WebSite.php b/src/ContextTypes/WebSite.php index 8ae51d2..5033909 100644 --- a/src/ContextTypes/WebSite.php +++ b/src/ContextTypes/WebSite.php @@ -15,7 +15,12 @@ class WebSite extends AbstractContext 'image' => null, 'name' => null, 'url' => null, + 'publisher' => Organization::class, 'keywords' => null, + 'inLanguage' => null, + 'dateCreated' => null, + 'dateModified' => null, + 'datePublished' => null, 'sameAs' => null, ]; } \ No newline at end of file diff --git a/tests/ContextTypes/ArticleTest.php b/tests/ContextTypes/ArticleTest.php index 448cf00..f990aa9 100644 --- a/tests/ContextTypes/ArticleTest.php +++ b/tests/ContextTypes/ArticleTest.php @@ -36,6 +36,8 @@ class ArticleTest extends TestCase 'height' => 60, ] ], + 'keywords' => 'Lorem,ipsum,dolor', + 'inLanguage' => 'en', 'dateCreated' => '2013-10-04T00:00', 'dateModified' => '2013-10-04T00:00', 'datePublished' => '2013-10-04T00:00', @@ -130,6 +132,26 @@ public function shouldHavePublisherObject() ], $context->getProperty('publisher')); } + /** + * @test + */ + public function shouldHaveKeywords() + { + $context = $this->make(); + + $this->assertEquals('Lorem,ipsum,dolor', $context->getProperty('keywords')); + } + + /** + * @test + */ + public function shouldHaveInLanguage() + { + $context = $this->make(); + + $this->assertEquals('en', $context->getProperty('inLanguage')); + } + /** * @test */ diff --git a/tests/ContextTypes/WebSiteTest.php b/tests/ContextTypes/WebSiteTest.php index 184a552..f17abee 100644 --- a/tests/ContextTypes/WebSiteTest.php +++ b/tests/ContextTypes/WebSiteTest.php @@ -10,11 +10,24 @@ class WebSiteTest extends TestCase protected $attributes = [ 'about' => 'The subject matter of the content.', - 'headline' => 'Headline of the article.', + 'headline' => 'Headline of the website.', 'image' => 'https://og.github.com/mark/github-mark@1200x630.png', 'name' => 'The name of the item.', 'url' => 'https://schema.org/WebSite', + 'publisher' => [ + 'name' => 'Google', + 'logo' => [ + '@type' => 'ImageObject', + 'url' => 'https://google.com/logo.jpg', + 'width' => 600, + 'height' => 60, + ] + ], 'keywords' => 'about,headline,image,name,url', + 'inLanguage' => 'en', + 'dateCreated' => '2013-10-04T00:00', + 'dateModified' => '2013-10-04T00:00', + 'datePublished' => '2013-10-04T00:00', 'sameAs' => 'https://schema.org/sameAs', ]; @@ -25,9 +38,60 @@ public function shouldGetProperties() { $context = $this->make(); - $this->assertEquals(array_merge([ - '@context' => 'http://schema.org', - '@type' => 'WebSite', - ], $this->attributes), $context->getProperties()); + $attributesPlus = $this->attributes; + $attributesPlus['@context'] = 'http://schema.org'; + $attributesPlus["@type"] = 'WebSite'; + $attributesPlus["publisher"]["@type"] = 'Organization'; + + $this->assertEquals($context->getProperties(), $attributesPlus); + } + + /** + * @test + */ + public function shouldHaveHeadline() + { + $context = $this->make(); + + $this->assertEquals('Headline of the website.', $context->getProperty('headline')); + } + + /** + * @test + */ + public function shouldHavePublisherObject() + { + $context = $this->make(); + + $this->assertEquals([ + '@type' => 'Organization', + 'name' => 'Google', + 'logo' => [ + '@type' => 'ImageObject', + 'url' => 'https://google.com/logo.jpg', + 'height' => 60, + 'width' => 600, + ], + ], $context->getProperty('publisher')); + } + + /** + * @test + */ + public function shouldHaveKeywords() + { + $context = $this->make(); + + $this->assertEquals('about,headline,image,name,url', $context->getProperty('keywords')); + } + + /** + * @test + */ + public function shouldHaveInLanguage() + { + $context = $this->make(); + + $this->assertEquals('en', $context->getProperty('inLanguage')); } } \ No newline at end of file