From 3c2e8c162f9807aa084b1d22d3ee5fe023483b0e Mon Sep 17 00:00:00 2001 From: Martin Bean Date: Tue, 3 Mar 2015 17:35:18 +0000 Subject: [PATCH] Create meta helper --- src/HtmlBuilder.php | 17 +++++++++++ tests/HtmlBuilderTest.php | 63 +++++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index 6b8f41f..44954d3 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -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 'attributes($attributes).'>'.PHP_EOL; + } + } diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index f78d5b8..2f2cc75 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -10,36 +10,49 @@ use Illuminate\Routing\RouteCollection; class HtmlBuilderTest extends PHPUnit_Framework_TestCase { - /** - * Setup the test environment. - */ - public function setUp() - { - $this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET')); - $this->htmlBuilder = new HtmlBuilder($this->urlGenerator); - } + /** + * Setup the test environment. + */ + public function setUp() + { + $this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET')); + $this->htmlBuilder = new HtmlBuilder($this->urlGenerator); + } + /** + * Destroy the test environment. + */ + public function tearDown() + { + m::close(); + } - /** - * Destroy the test environment. - */ - public function tearDown() - { - m::close(); - } + public function testDl() + { + $list = [ + 'foo' => 'bar', + 'bing' => 'baz' + ]; - public function testDl() - { - $list = [ - 'foo' => 'bar', - 'bing' => 'baz' - ]; + $attributes = ['class' => 'example']; - $attributes = ['class' => 'example']; + $result = $this->htmlBuilder->dl($list, $attributes); - $result = $this->htmlBuilder->dl($list, $attributes); + $this->assertEquals('
foo
bar
bing
baz
', $result); + } - $this->assertEquals('
foo
bar
bing
baz
', $result); - } + public function testMeta() + { + $result = $this->htmlBuilder->meta('description', 'Lorem ipsum dolor sit amet.'); + + $this->assertEquals(''.PHP_EOL, $result); + } + + public function testMetaOpenGraph() + { + $result = $this->htmlBuilder->meta(null, 'website', ['property' => 'og:type']); + + $this->assertEquals(''.PHP_EOL, $result); + } } \ No newline at end of file