Create meta helper

This commit is contained in:
Martin Bean committed 2015-03-09 22:22:57 +00:00
1 parent 0d4c5f4e9d
commit 3c2e8c162f
2 files changed
+31 -1

No files matched your search

+17
View File
@@ -399,4 +399,21 @@ class HtmlBuilder {
return $safe;
}
/**
* Generate a meta tag.
*
* @param string $name
* @param string $content
* @param array $attributes
* @return string
*/
public function meta($name, $content, array $attributes = [])
{
$defaults = compact('name', 'content');
$attributes = array_merge($defaults, $attributes);
return '<meta'.$this->attributes($attributes).'>'.PHP_EOL;
}
}
+14 -1
View File
@@ -19,7 +19,6 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase {
$this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
}
/**
* Destroy the test environment.
*/
@@ -42,4 +41,18 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('<dl class="example"><dt>foo</dt><dd>bar</dd><dt>bing</dt><dd>baz</dd></dl>', $result);
}
public function testMeta()
{
$result = $this->htmlBuilder->meta('description', 'Lorem ipsum dolor sit amet.');
$this->assertEquals('<meta name="description" content="Lorem ipsum dolor sit amet.">'.PHP_EOL, $result);
}
public function testMetaOpenGraph()
{
$result = $this->htmlBuilder->meta(null, 'website', ['property' => 'og:type']);
$this->assertEquals('<meta content="website" property="og:type">'.PHP_EOL, $result);
}
}