Support boolean attributes

This commit is contained in:
Andrew Smith authored and Andrew Smith committed 2016-03-03 16:48:31 +10:00
1 parent 02c75dff24
commit 068dfb348d
2 files changed
+19 -4

No files matched your search

+6 -4
View File
@@ -420,11 +420,13 @@ class HtmlBuilder
*/
protected function attributeElement($key, $value)
{
// For numeric keys we will assume that the key and the value are the same
// as this will convert HTML attributes such as "required" to a correct
// form like required="required" instead of using incorrect numerics.
// For numeric keys we will assume that the value is a boolean attribute
// where the presence of the attribute represents a true value and the
// absence represents a false value.
// This will convert HTML attributes such as "required" to a correct
// form instead of using incorrect numerics.
if (is_numeric($key)) {
$key = $value;
return $value;
}
if (! is_null($value)) {
+13
View File
@@ -11,6 +11,10 @@ use Mockery as m;
class FormBuilderTest extends PHPUnit_Framework_TestCase
{
/**
* @var FormBuilder
*/
private $formBuilder;
/**
* Setup the test environment.
@@ -520,6 +524,15 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('<input class="span2" name="foo" type="color">', $form3);
}
public function testBooleanAttributes()
{
$input = $this->formBuilder->text('test', null, ['disabled']);
$this->assertEquals('<input disabled name="test" type="text">', $input);
$input = $this->formBuilder->textarea('test', null, ['readonly']);
$this->assertEquals('<textarea readonly name="test" cols="50" rows="10"></textarea>', $input);
}
protected function setModel(array $data, $object = true)
{
if ($object) {