Skip to content

Commit

Permalink
Updating the SeoMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Oct 12, 2015
1 parent 1d7af87 commit 58165c4
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Contracts/SeoMetaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,22 @@ public function getKeywords();
* @return self
*/
public function setKeywords($content);

/**
* Add a keyword.
*
* @param string $keyword
*
* @return self
*/
public function addKeyword($keyword);

/**
* Set the current URL.
*
* @param string $url
*
* @return self
*/
public function setUrl($url);
}
56 changes: 56 additions & 0 deletions src/SeoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Arcanedev\SeoHelper\Contracts\SeoMetaInterface;
use Arcanedev\SeoHelper\Entities\Description;
use Arcanedev\SeoHelper\Entities\Keywords;
use Arcanedev\SeoHelper\Entities\MiscTags;
use Arcanedev\SeoHelper\Entities\Title;

/**
Expand Down Expand Up @@ -38,6 +39,20 @@ class SeoMeta implements SeoMetaInterface
*/
protected $keywords;

/**
* MiscTags instance.
*
* @var MiscTags
*/
protected $misc;

/**
* Current URL.
*
* @var string
*/
protected $currentUrl = '';

/**
* SEO Helper configs.
*
Expand Down Expand Up @@ -68,6 +83,7 @@ private function init()
$this->title = new Title($this->getConfig('title', []));
$this->description = new Description($this->getConfig('description', []));
$this->keywords = new Keywords($this->getConfig('keywords', []));
$this->misc = new MiscTags($this->getConfig('misc', []));
}

/* ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -156,6 +172,35 @@ public function setKeywords($content)
return $this;
}

/**
* Add a keyword.
*
* @param string $keyword
*
* @return self
*/
public function addKeyword($keyword)
{
$this->keywords->add($keyword);

return $this;
}

/**
* Set the current URL.
*
* @param string $url
*
* @return self
*/
public function setUrl($url)
{
$this->currentUrl = $url;
$this->misc->setUrl($url);

return $this;
}

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
Expand All @@ -171,6 +216,7 @@ public function render()
$this->renderTitle(),
$this->renderDescription(),
$this->renderKeywords(),
$this->renderMisc(),
]));
}

Expand Down Expand Up @@ -204,6 +250,16 @@ public function renderKeywords()
return $this->keywords->render();
}

/**
* Render Miscellaneous tags.
*
* @return string
*/
public function renderMisc()
{
return $this->misc->render();
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions tests/SeoMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function setUp()

$configs = $this->app['config']->get('seo-helper');
$this->seoMeta = new SeoMeta($configs);

$this->seoMeta->setUrl($this->baseUrl);
}

public function tearDown()
Expand Down Expand Up @@ -125,4 +127,18 @@ public function it_can_set_and_get_and_render_keywords()
$this->seoMeta->setKeywords(null);
$this->assertEmpty($this->seoMeta->renderKeywords());
}

/** @test */
public function it_can_add_one_keyword()
{
$keywords = ['keyword-1', 'keyword-2', 'keyword-3', 'keyword-4', 'keyword-5'];
$this->seoMeta->setKeywords($keywords);

$this->assertEquals($keywords, $this->seoMeta->getKeywords());

$keywords[] = $keyword = 'keyword-6';
$this->seoMeta->addKeyword($keyword);

$this->assertEquals($keywords, $this->seoMeta->getKeywords());
}
}

0 comments on commit 58165c4

Please sign in to comment.