Skip to content

Commit

Permalink
Adding addMany Method to Keywords Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Oct 17, 2015
1 parent 90f9684 commit ec7cb28
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Contracts/Entities/KeywordsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public static function make($keywords);
* @return self
*/
public function add($keyword);

/**
* Add many keywords to the content.
*
* @param array $keywords
*
* @return self
*/
public function addMany(array $keywords);
}
9 changes: 9 additions & 0 deletions src/Contracts/SeoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public function setKeywords($content);
*/
public function addKeyword($keyword);

/**
* Add many keywords.
*
* @param array $keywords
*
* @return self
*/
public function addKeywords(array $keywords);

/**
* Add a webmaster tool site verifier.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Entities/Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ public function add($keyword)
return $this;
}

/**
* Add many keywords to the content.
*
* @param array $keywords
*
* @return self
*/
public function addMany(array $keywords)
{
foreach ($keywords as $keyword) {
$this->add($keyword);
}

return $this;
}

/**
* Render the tag.
*
Expand Down
14 changes: 14 additions & 0 deletions src/SeoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ public function addKeyword($keyword)
return $this;
}

/**
* Add many keywords.
*
* @param array $keywords
*
* @return self
*/
public function addKeywords(array $keywords)
{
$this->keywords->addMany($keywords);

return $this;
}

/**
* Add a webmaster tool site verifier.
*
Expand Down
19 changes: 19 additions & 0 deletions tests/Entities/KeywordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ public function it_can_add_a_keyword()
$this->assertEquals($content, $this->keywords->getContent());
}

/** @test */
public function it_can_add_many_keywords()
{
$content = $this->getDefaultContent();

$this->keywords->set($content);

$this->assertCount(count($content), $this->keywords->getContent());
$this->assertEquals($content, $this->keywords->getContent());

$keywords = ['keyword-6', 'keyword-7', 'keyword-8'];
$content = array_merge($content, $keywords);

$this->keywords->addMany($keywords);

$this->assertCount(count($content), $this->keywords->getContent());
$this->assertEquals($content, $this->keywords->getContent());
}

/** @test */
public function it_can_render()
{
Expand Down
20 changes: 20 additions & 0 deletions tests/SeoMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ public function it_can_add_one_keyword()
$this->assertContains($expected, (string) $this->seoMeta);
}

/** @test */
public function it_can_add_many_keywords()
{
$keywords = ['keyword-1', 'keyword-2', 'keyword-3', 'keyword-4', 'keyword-5'];
$expected = '<meta name="keywords" content="' . implode(', ', $keywords) . '">';
$this->seoMeta->setKeywords($keywords);

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

$new = ['keyword-6', 'keyword-7', 'keyword-8'];
$keywords = array_merge($keywords, $new);
$expected = '<meta name="keywords" content="' . implode(', ', $keywords) . '">';

$this->seoMeta->addKeywords($new);

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

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

0 comments on commit ec7cb28

Please sign in to comment.