Merge pull request #7 from devinfd/5.0
Proposal: add a dl method to HtmlBuilder
This commit is contained in:
commit
d6157b709b
2 files changed
+68
No files matched your search
@@ -239,6 +239,29 @@ class HtmlBuilder {
|
|||||||
return $this->listing('ul', $list, $attributes);
|
return $this->listing('ul', $list, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a description list of items.
|
||||||
|
*
|
||||||
|
* @param array $list
|
||||||
|
* @param array $attributes
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function dl(array $list, array $attributes = [])
|
||||||
|
{
|
||||||
|
$attributes = $this->attributes($attributes);
|
||||||
|
|
||||||
|
$html = "<dl{$attributes}>";
|
||||||
|
|
||||||
|
foreach ($list as $key => $value)
|
||||||
|
{
|
||||||
|
$html .= "<dt>$key</dt><dd>$value</dd>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= '</dl>';
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a listing HTML element.
|
* Create a listing HTML element.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Session\Store;
|
||||||
|
use Mockery as m;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Collective\Html\FormBuilder;
|
||||||
|
use Collective\Html\HtmlBuilder;
|
||||||
|
use Illuminate\Routing\UrlGenerator;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user