From 5f293aea5a7f1b9503f856daaba111cd2f713255 Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Mon, 19 Oct 2015 18:41:36 +0100 Subject: [PATCH] Adding setSiteName() method for OpenGraph --- src/Contracts/Entities/OpenGraphInterface.php | 9 +++++++++ src/Contracts/SeoOpenGraph.php | 9 +++++++++ src/Entities/OpenGraph/Graph.php | 14 ++++++++++++++ src/SeoHelper.php | 1 + src/SeoOpenGraph.php | 14 ++++++++++++++ tests/Entities/OpenGraph/GraphTest.php | 13 +++++++++++++ tests/SeoHelperTest.php | 1 + tests/SeoOpenGraphTest.php | 13 +++++++++++++ 8 files changed, 74 insertions(+) diff --git a/src/Contracts/Entities/OpenGraphInterface.php b/src/Contracts/Entities/OpenGraphInterface.php index 87d9064..d4d0a40 100644 --- a/src/Contracts/Entities/OpenGraphInterface.php +++ b/src/Contracts/Entities/OpenGraphInterface.php @@ -68,6 +68,15 @@ public function setUrl($url); */ public function setImage($image); + /** + * Set site name property. + * + * @param string $siteName + * + * @return self + */ + public function setSiteName($siteName); + /** * Add an open graph property. * diff --git a/src/Contracts/SeoOpenGraph.php b/src/Contracts/SeoOpenGraph.php index 58720f5..4559221 100644 --- a/src/Contracts/SeoOpenGraph.php +++ b/src/Contracts/SeoOpenGraph.php @@ -77,6 +77,15 @@ public function setUrl($url); */ public function setImage($image); + /** + * Set site name property. + * + * @param string $siteName + * + * @return self + */ + public function setSiteName($siteName); + /** * Add an open graph property. * diff --git a/src/Entities/OpenGraph/Graph.php b/src/Entities/OpenGraph/Graph.php index 4c6d290..04fc029 100644 --- a/src/Entities/OpenGraph/Graph.php +++ b/src/Entities/OpenGraph/Graph.php @@ -144,6 +144,20 @@ public function setImage($image) return $this; } + /** + * Set site name property. + * + * @param string $siteName + * + * @return self + */ + public function setSiteName($siteName) + { + $this->addProperty('site_name', $siteName); + + return $this; + } + /** * Add an open graph property. * diff --git a/src/SeoHelper.php b/src/SeoHelper.php index 9fe5d96..dbe92b8 100644 --- a/src/SeoHelper.php +++ b/src/SeoHelper.php @@ -159,6 +159,7 @@ public function setTitle($title, $siteName = null, $separator = null) { $this->meta()->setTitle($title, $siteName, $separator); $this->openGraph()->setTitle($title); + $this->openGraph()->setSiteName($siteName); $this->twitter()->setTitle($title); return $this; diff --git a/src/SeoOpenGraph.php b/src/SeoOpenGraph.php index bbd8c1c..aedd319 100644 --- a/src/SeoOpenGraph.php +++ b/src/SeoOpenGraph.php @@ -148,6 +148,20 @@ public function setImage($image) return $this; } + /** + * Set site name property. + * + * @param string $siteName + * + * @return self + */ + public function setSiteName($siteName) + { + $this->openGraph->setSiteName($siteName); + + return $this; + } + /** * Add an open graph property. * diff --git a/tests/Entities/OpenGraph/GraphTest.php b/tests/Entities/OpenGraph/GraphTest.php index 752a9ad..c5b7ea5 100644 --- a/tests/Entities/OpenGraph/GraphTest.php +++ b/tests/Entities/OpenGraph/GraphTest.php @@ -141,4 +141,17 @@ public function it_can_set_and_render_image() $this->assertContains($expected, $this->og->render()); $this->assertContains($expected, (string) $this->og); } + + /** @test */ + public function it_can_set_and_render_site_name() + { + $siteName = 'My site name'; + + $this->og->setSiteName($siteName); + + $expected = ''; + + $this->assertContains($expected, $this->og->render()); + $this->assertContains($expected, (string) $this->og); + } } diff --git a/tests/SeoHelperTest.php b/tests/SeoHelperTest.php index 655a0be..d03ebec 100644 --- a/tests/SeoHelperTest.php +++ b/tests/SeoHelperTest.php @@ -114,6 +114,7 @@ public function it_can_set_and_render_title() $expectations = [ "$title $separator $siteName", '', + '', '', ]; diff --git a/tests/SeoOpenGraphTest.php b/tests/SeoOpenGraphTest.php index febb2b5..81f288e 100644 --- a/tests/SeoOpenGraphTest.php +++ b/tests/SeoOpenGraphTest.php @@ -158,6 +158,19 @@ public function it_can_set_and_render_image() $this->assertContains($expected, (string) $this->seoOpenGraph); } + /** @test */ + public function it_can_set_and_render_site_name() + { + $siteName = 'My site name'; + + $this->seoOpenGraph->setSiteName($siteName); + + $expected = ''; + + $this->assertContains($expected, $this->seoOpenGraph->render()); + $this->assertContains($expected, (string) $this->seoOpenGraph); + } + /** @test */ public function it_can_add_and_render_property() {