Compare commits

...
5 Commits
Author SHA1 Message Date
Gabriel Caruso 38f2c6ff0d Update to PHPUnit 7.1 (#511) 2018-04-26 09:09:18 -07:00
Adrian Crisan b3a10245c7 Fix the issue where defaults has a higher priority then the attributes (#509) 2018-04-09 07:09:32 -07:00
ilyadrv 623a150c91 Placeholder for select element not hidden anymore (#493) (#499)
* Placeholder for select element not hidden anymore (#493)

* Fix tests for placeholder select element without hidden attribue
2018-03-16 09:57:31 -07:00
Devin 5060a6641d Fixed bug with radio button not being checked (#501)
* Fixed bug with radio button not being checked

Fixes: https://github.com/LaravelCollective/html/issues/496

Loose comparison needs to be done because Laravel model casting may be in affect and therfore 1 == true and 0 == false.

* typo
2018-03-16 09:57:16 -07:00
Anderson Friaça 41cd9291a6 [5.6] Validation in select field for boolean value of selected option (#491) 2018-02-12 06:19:42 -08:00
6 changed files with 50 additions and 13 deletions

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@
"require-dev": {
"illuminate/database": "5.6.*",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~5.4"
"phpunit/phpunit": "~7.1"
},
"autoload": {
"psr-4": {
+21 -5
View File
@@ -572,7 +572,7 @@ class FormBuilder
*
* @param string $name
* @param array $list
* @param string $selected
* @param string|bool $selected
* @param array $selectAttributes
* @param array $optionsAttributes
* @param array $optgroupsAttributes
@@ -769,7 +769,7 @@ class FormBuilder
'value' => '',
];
return $this->toHtmlString('<option' . $this->html->attributes($options) . ' hidden="hidden">' . e($display, false) . '</option>');
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display, false) . '</option>');
}
/**
@@ -787,7 +787,9 @@ class FormBuilder
} elseif ($selected instanceof Collection) {
return $selected->contains($value) ? 'selected' : null;
}
if (is_int($value) && is_bool($selected)) {
return (bool)$value === $selected;
}
return ((string) $value === (string) $selected) ? 'selected' : null;
}
@@ -869,7 +871,7 @@ class FormBuilder
return $this->getRadioCheckedState($name, $value, $checked);
default:
return $this->getValueAttribute($name) === $value;
return $this->compareValues($name, $value);
}
}
@@ -922,7 +924,21 @@ class FormBuilder
return $checked;
}
return $this->getValueAttribute($name) === $value;
return $this->compareValues($name, $value);
}
/**
* Determine if the provide value loosely compares to the value assigned to the field.
* Use loose comparison because Laravel model casting may be in affect and therefore
* 1 == true and 0 == false.
*
* @param string $name
* @param string $value
* @return bool
*/
protected function compareValues($name, $value)
{
return $this->getValueAttribute($name) == $value;
}
/**
+1 -1
View File
@@ -94,7 +94,7 @@ class HtmlBuilder
{
$defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'];
$attributes = array_merge($attributes, $defaults);
$attributes = array_merge($defaults, $attributes);
$attributes['href'] = $this->url->asset($url, $secure);
+1 -1
View File
@@ -12,7 +12,7 @@ use Illuminate\Routing\UrlGenerator;
use Illuminate\Database\Capsule\Manager as Capsule;
use Mockery as m;
class FormAccessibleTest extends PHPUnit_Framework_TestCase
class FormAccessibleTest extends PHPUnit\Framework\TestCase
{
public function setUp()
{
+25 -4
View File
@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\App;
use Illuminate\Session\Store;
use Mockery as m;
class FormBuilderTest extends PHPUnit_Framework_TestCase
class FormBuilderTest extends PHPUnit\Framework\TestCase
{
/**
* @var FormBuilder
@@ -464,6 +464,12 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
'<select name="countries"><option value="1" selected="selected">L</option><option value="2">M</option></select>',
$result
);
$select = $this->formBuilder->select('avc', [1 => 'Yes', 0 => 'No'], true, ['placeholder' => 'Select']);
$this->assertEquals(
'<select name="avc"><option value="">Select</option><option value="1" selected>Yes</option><option value="0" >No</option></select>',
$select
);
}
public function testSelectCollection()
@@ -510,7 +516,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select One...']
);
$this->assertEquals($select,
'<select name="size"><option selected="selected" value="" hidden="hidden">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>');
'<select name="size"><option selected="selected" value="">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>');
$select = $this->formBuilder->select(
'size',
@@ -519,7 +525,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select One...']
);
$this->assertEquals($select,
'<select name="size"><option value="" hidden="hidden">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
'<select name="size"><option value="">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
$select = $this->formBuilder->select(
'encoded_html',
@@ -528,7 +534,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select the &nbsp;']
);
$this->assertEquals($select,
'<select name="encoded_html"><option selected="selected" value="" hidden="hidden">Select the &nbsp;</option><option value="no_break_space">&nbsp;</option><option value="ampersand">&amp;</option><option value="lower_than">&lt;</option></select>'
'<select name="encoded_html"><option selected="selected" value="">Select the &nbsp;</option><option value="no_break_space">&nbsp;</option><option value="ampersand">&amp;</option><option value="lower_than">&lt;</option></select>'
);
}
@@ -652,6 +658,21 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('<input class="span2" name="foo" type="radio" value="foobar">', $form4);
}
public function testFormRadioWithAttributeCastToBoolean()
{
$this->setModel(['itemA' => true, 'itemB' => false]);
$radio1 = $this->formBuilder->radio('itemA', 1);
$radio2 = $this->formBuilder->radio('itemA', 0);
$radio3 = $this->formBuilder->radio('itemB', 1);
$radio4 = $this->formBuilder->radio('itemB', 0);
$this->assertEquals('<input checked="checked" name="itemA" type="radio" value="1">', $radio1);
$this->assertEquals('<input name="itemA" type="radio" value="0">', $radio2);
$this->assertEquals('<input name="itemB" type="radio" value="1">', $radio3);
$this->assertEquals('<input checked="checked" name="itemB" type="radio" value="0">', $radio4);
}
public function testFormRadioRepopulation()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
+1 -1
View File
@@ -7,7 +7,7 @@ use Illuminate\Routing\RouteCollection;
use Illuminate\Routing\UrlGenerator;
use Mockery as m;
class HtmlBuilderTest extends PHPUnit_Framework_TestCase
class HtmlBuilderTest extends PHPUnit\Framework\TestCase
{
/**