Skip to content

Commit

Permalink
Adding more features to control metas
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Oct 13, 2015
1 parent 2c94c87 commit c02b850
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/SeoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,49 @@ public function setUrl($url)
return $this;
}

/**
* Add a meta tag.
*
* @param string $name
* @param string $content
*
* @return self
*/
public function addMeta($name, $content)
{
$this->misc->addMeta($name, $content);

return $this;
}

/**
* Add many meta tags.
*
* @param array $metas
*
* @return self
*/
public function addMetas(array $metas)
{
$this->misc->addMetas($metas);

return $this;
}

/**
* Remove a meta from the meta collection by key.
*
* @param string|array $names
*
* @return self
*/
public function removeMeta($names)
{
$this->misc->removeMeta($names);

return $this;
}

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
Expand Down
55 changes: 55 additions & 0 deletions tests/SeoMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,59 @@ public function it_can_add_one_keyword()

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

/** @test */
public function it_can_add_remove_and_render_a_misc_tag()
{
$output = $this->seoMeta->render();

$this->assertContains(
'<meta name="robots" content="noindex, nofollow">', $output
);

$this->assertContains(
'<link rel="canonical" href="' . $this->baseUrl . '">', $output
);

$this->seoMeta->removeMeta(['robots', 'canonical']);
$output = $this->seoMeta->render();

$this->assertNotContains(
'<meta name="robots" content="noindex, nofollow">', $output
);
$this->assertNotContains(
'<link rel="canonical" href="' . $this->baseUrl . '">', $output
);

$this->seoMeta->addMetas([
'copyright' => 'ARCANEDEV',
'expires' => 'never',
]);

$output = $this->seoMeta->render();

$this->assertContains('<meta name="copyright" content="ARCANEDEV">', $output);
$this->assertContains('<meta name="expires" content="never">', $output);

$this->seoMeta->removeMeta('copyright');

$this->assertNotContains(
'<meta name="copyright" content="ARCANEDEV">',
$this->seoMeta->render()
);

$this->seoMeta->removeMeta('expires');

$this->assertNotContains(
'<meta name="expires" content="never">',
$this->seoMeta->render()
);

$this->seoMeta->addMeta('viewport', 'width=device-width, initial-scale=1.0');

$this->assertContains(
'<meta name="viewport" content="width=device-width, initial-scale=1.0">',
$this->seoMeta->render()
);
}
}

0 comments on commit c02b850

Please sign in to comment.