Skip to content

Commit

Permalink
Adding setSiteName() method for OpenGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Oct 19, 2015
1 parent 758bfce commit 5f293ae
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Contracts/Entities/OpenGraphInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Contracts/SeoOpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Entities/OpenGraph/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/SeoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/SeoOpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Entities/OpenGraph/GraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<meta property="og:site_name" content="' . $siteName . '">';

$this->assertContains($expected, $this->og->render());
$this->assertContains($expected, (string) $this->og);
}
}
1 change: 1 addition & 0 deletions tests/SeoHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function it_can_set_and_render_title()
$expectations = [
"<title>$title $separator $siteName</title>",
'<meta property="og:title" content="' . $title . '">',
'<meta property="og:site_name" content="' . $siteName . '">',
'<meta name="twitter:title" content="' . $title . '">',
];

Expand Down
13 changes: 13 additions & 0 deletions tests/SeoOpenGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<meta property="og:site_name" content="' . $siteName . '">';

$this->assertContains($expected, $this->seoOpenGraph->render());
$this->assertContains($expected, (string) $this->seoOpenGraph);
}

/** @test */
public function it_can_add_and_render_property()
{
Expand Down

0 comments on commit 5f293ae

Please sign in to comment.