Skip to content

Commit

Permalink
Merge pull request #14 from martinbean/meta
Browse files Browse the repository at this point in the history
Create meta helper
  • Loading branch information
adamgoose committed Mar 10, 2015
2 parents 3125f06 + 3c2e8c1 commit 9af2030
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 31 deletions.
17 changes: 17 additions & 0 deletions src/HtmlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,21 @@ public function obfuscate($value)
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;
}

}
75 changes: 44 additions & 31 deletions tests/HtmlBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,49 @@

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);
}


/**
* Destroy the test environment.
*/
public function tearDown()
{
m::close();
}

public function testDl()
{
$list = [
'foo' => 'bar',
'bing' => 'baz'
];

$attributes = ['class' => 'example'];

$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);
}
/**
* 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();
}

public function testDl()
{
$list = [
'foo' => 'bar',
'bing' => 'baz'
];

$attributes = ['class' => 'example'];

$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);
}

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);
}

}

0 comments on commit 9af2030

Please sign in to comment.