Skip to content

Commit

Permalink
Adding the setImage() method
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Feb 27, 2017
1 parent abd274e commit 9fef989
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
28 changes: 19 additions & 9 deletions src/Contracts/SeoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
interface SeoHelper extends Renderable
{
/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Getters & Setters
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/
/**
* Get SeoMeta instance.
Expand Down Expand Up @@ -79,6 +79,16 @@ public function setSeoTwitter(SeoTwitter $seoTwitter);
* @return self
*/
public function setTitle($title, $siteName = null, $separator = null);

/**
* Set the site name.
*
* @param string $siteName
*
* @return self
*/
public function setSiteName($siteName);

/**
* Set description.
*
Expand All @@ -98,17 +108,17 @@ public function setDescription($description);
public function setKeywords($keywords);

/**
* Set the site name.
* Set Image.
*
* @param string $siteName
* @param string $imageUrl
*
* @return self
* @return \Arcanedev\SeoHelper\SeoHelper
*/
public function setSiteName($siteName);
public function setImage($imageUrl);

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Render all seo tags with HtmlString object.
Expand Down
33 changes: 24 additions & 9 deletions src/SeoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*/
class SeoHelper implements SeoHelperContract
{
/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/
/**
* The SeoMeta instance.
Expand All @@ -38,9 +38,9 @@ class SeoHelper implements SeoHelperContract
*/
private $seoTwitter;

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Constructor
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/
/**
* Make SeoHelper instance.
Expand All @@ -59,9 +59,9 @@ public function __construct(
$this->setSeoTwitter($seoTwitter);
}

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Getters & Setters
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/
/**
* Get SeoMeta instance.
Expand Down Expand Up @@ -210,9 +210,24 @@ public function setKeywords($keywords)
return $this;
}

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
/**
* Set Image.
*
* @param string $imageUrl
*
* @return \Arcanedev\SeoHelper\SeoHelper
*/
public function setImage($imageUrl)
{
$this->openGraph()->setImage($imageUrl);
$this->twitter()->addImage($imageUrl);

return $this;
}

/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Render all seo tags.
Expand Down
17 changes: 17 additions & 0 deletions tests/SeoHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,23 @@ public function it_can_set_and_render_keywords()
$this->assertContains($expected, (string) $this->seoHelper);
}

/** @test */
public function it_can_set_and_render_image()
{
$this->seoHelper->setImage($imageUrl = 'http://localhost/assets/img/logo.png');

$expectations = [
'<meta property="og:image" content="'.$imageUrl.'">',
'<meta name="twitter:image" content="'.$imageUrl.'">'
];

$rendered = $this->seoHelper->render();

foreach ($expectations as $expected) {
$this->assertContains($expected, $rendered);
}
}

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

0 comments on commit 9fef989

Please sign in to comment.