Merge pull request #14 from martinbean/meta

Create meta helper
This commit is contained in:
Adam Engebretson committed 2015-03-10 10:59:48 -05:00
commit 9af2030538
2 files changed
+55 -25

No files matched your search

+17
View File
@@ -399,4 +399,21 @@ class HtmlBuilder {
return $safe; 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;
}
} }
+38 -25
View File
@@ -10,36 +10,49 @@ use Illuminate\Routing\RouteCollection;
class HtmlBuilderTest extends PHPUnit_Framework_TestCase { class HtmlBuilderTest extends PHPUnit_Framework_TestCase {
/** /**
* Setup the test environment. * Setup the test environment.
*/ */
public function setUp() public function setUp()
{ {
$this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET')); $this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET'));
$this->htmlBuilder = new HtmlBuilder($this->urlGenerator); $this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
} }
/**
* Destroy the test environment.
*/
public function tearDown()
{
m::close();
}
/** public function testDl()
* Destroy the test environment. {
*/ $list = [
public function tearDown() 'foo' => 'bar',
{ 'bing' => 'baz'
m::close(); ];
}
public function testDl() $attributes = ['class' => 'example'];
{
$list = [
'foo' => 'bar',
'bing' => 'baz'
];
$attributes = ['class' => 'example']; $result = $this->htmlBuilder->dl($list, $attributes);
$result = $this->htmlBuilder->dl($list, $attributes); $this->assertEquals('<dl class="example"><dt>foo</dt><dd>bar</dd><dt>bing</dt><dd>baz</dd></dl>', $result);
}
$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);
}
} }