Compare commits

..
3 Commits
Author SHA1 Message Date
Matt Lantz 8956f00475 Merge pull request #188 from skyrpex/patch-1
Treat boolean attributes as HTML properties
2016-12-13 09:28:46 -05:00
Cristian Pallarés dc15cf8463 Add test for boolean attributes 2016-08-16 09:34:49 +02:00
Cristian Pallarés 1add9b421a Treat boolean attributes as HTML properties 2016-08-16 09:32:41 +02:00
5 changed files with 28 additions and 12 deletions

No files matched your search

+1 -1
View File
@@ -1,9 +1,9 @@
language: php language: php
php: php:
- 5.5
- 5.6 - 5.6
- 7.0 - 7.0
- 7.1
- hhvm - hhvm
sudo: false sudo: false
+9 -9
View File
@@ -18,17 +18,17 @@
} }
], ],
"require": { "require": {
"php": ">=5.6.4", "php": ">=5.5.9",
"illuminate/http": "5.3.*", "illuminate/http": "5.2.*",
"illuminate/routing": "5.3.*", "illuminate/routing": "5.2.*",
"illuminate/session": "5.3.*", "illuminate/session": "5.2.*",
"illuminate/support": "5.3.*", "illuminate/support": "5.2.*",
"illuminate/view": "5.3.*" "illuminate/view": "5.2.*"
}, },
"require-dev": { "require-dev": {
"illuminate/database": "5.3.*", "illuminate/database": "5.2.*",
"mockery/mockery": "~0.9.4", "mockery/mockery": "~0.9",
"phpunit/phpunit": "~5.4" "phpunit/phpunit": "~4.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
+1 -1
View File
@@ -55,7 +55,7 @@ trait FormAccessible
$methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC); $methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC);
$mutator = collect($methods) $mutator = collect($methods)
->first(function (ReflectionMethod $method) use ($key) { ->first(function ($index, ReflectionMethod $method) use ($key) {
return $method->getName() == 'form' . Str::studly($key) . 'Attribute'; return $method->getName() == 'form' . Str::studly($key) . 'Attribute';
}); });
+5
View File
@@ -447,6 +447,11 @@ class HtmlBuilder
if (is_numeric($key)) { if (is_numeric($key)) {
$key = $value; $key = $value;
} }
// Treat boolean attributes as HTML properties
if (is_bool($value)) {
return $value ? $key : '';
}
if (! is_null($value)) { if (! is_null($value)) {
return $key . '="' . e($value) . '"'; return $key . '="' . e($value) . '"';
+12 -1
View File
@@ -58,7 +58,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$this->htmlBuilder->image('http://example.com/image1'), $this->htmlBuilder->image('http://example.com/image1'),
$this->htmlBuilder->image('http://example.com/image2'), $this->htmlBuilder->image('http://example.com/image2'),
]; ];
$result4 = $this->htmlBuilder->tag('div', $content, ['class' => 'row']); $result4 = $this->htmlBuilder->tag('div', $content, ['class' => 'row']);
$this->assertEquals('<p>' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '</p>' . PHP_EOL, $result1); $this->assertEquals('<p>' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '</p>' . PHP_EOL, $result1);
@@ -115,4 +115,15 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('<a href="mailto:person@example.com" class="example-link">&lt;span&gt;First Name Last&lt;/span&gt;</a>', $result1); $this->assertEquals('<a href="mailto:person@example.com" class="example-link">&lt;span&gt;First Name Last&lt;/span&gt;</a>', $result1);
$this->assertEquals('<a href="mailto:person@example.com" class="example-link"><span>First Name Last</span></a>', $result2); $this->assertEquals('<a href="mailto:person@example.com" class="example-link"><span>First Name Last</span></a>', $result2);
} }
public function testBooleanAttributes()
{
$result1 = $this->htmlBuilder->attributes(['my-property' => true]);
$result2 = $this->htmlBuilder->attributes(['my-property' => false]);
$this->assertEquals('my-property', trim($result1));
$this->assertEquals('', trim($result2));
}
} }