Create meta helper
This commit is contained in:
1 parent
0d4c5f4e9d
commit
3c2e8c162f
2 files changed
+55
-25
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
+38
-25
@@ -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('<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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user