Compare commits

..
5 Commits
Author SHA1 Message Date
Tom Shafer 04c596a699 Update composer.json 2018-03-23 17:39:21 -07:00
Tom Shafer 3b177c17aa Update composer.json 2018-03-23 17:38:57 -07:00
Tortue Torche 33984f5e87 [5.5] Fix form method of hidden input '_method' is preserved on next request (#505)
This fix was merged in the pull request https://github.com/LaravelCollective/html/pull/460
But the pull request https://github.com/LaravelCollective/html/pull/471 accidentally revert this fix
2018-03-22 07:00:50 -07:00
Anderson Friaça b79edc7acf [5.5] Validation in select field for boolean value of selected option (#490)
* [5.5] Validation in select field for boolean value of selected option

* Adjustment
2018-02-12 06:19:55 -08:00
Tom Shafer 215f20b8c2 Update composer.json 2018-02-08 08:25:51 -08:00
8 changed files with 36 additions and 89 deletions

No files matched your search

+1 -1
View File
@@ -1,8 +1,8 @@
language: php language: php
php: php:
- 7.0
- 7.1 - 7.1
- 7.2
sudo: false sudo: false
+10 -10
View File
@@ -18,17 +18,17 @@
} }
], ],
"require": { "require": {
"php": ">=7.1.3", "php": ">=7.0.0",
"illuminate/http": "5.6.*", "illuminate/http": "5.5.*",
"illuminate/routing": "5.6.*", "illuminate/routing": "5.5.*",
"illuminate/session": "5.6.*", "illuminate/session": "5.5.*",
"illuminate/support": "5.6.*", "illuminate/support": "5.5.*",
"illuminate/view": "5.6.*" "illuminate/view": "5.5.*"
}, },
"require-dev": { "require-dev": {
"illuminate/database": "5.6.*", "illuminate/database": "5.5.*",
"mockery/mockery": "~1.0", "mockery/mockery": "~0.9.4",
"phpunit/phpunit": "~7.1" "phpunit/phpunit": "~5.4"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@@ -40,7 +40,7 @@
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "5.6-dev" "dev-master": "5.5-dev"
}, },
"laravel": { "laravel": {
"providers": [ "providers": [
+3 -3
View File
@@ -49,11 +49,11 @@ trait FormAccessible
unset($keys[0]); unset($keys[0]);
$key = implode('.', $keys); $key = implode('.', $keys);
if (method_exists($relatedModel, 'hasFormMutator') && $key !== '' && $relatedModel->hasFormMutator($key)) { if ($this->hasFormMutator($key)) {
return $relatedModel->getFormValue($key); return $relatedModel->getFormValue($key);
} }
return data_get($relatedModel, empty($key)? null: $key); return data_get($relatedModel, $key);
} }
// No form mutator, let the model resolve this // No form mutator, let the model resolve this
@@ -81,7 +81,7 @@ trait FormAccessible
* *
* @return bool * @return bool
*/ */
public function hasFormMutator($key) protected function hasFormMutator($key)
{ {
$methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC); $methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC);
+14 -31
View File
@@ -190,7 +190,7 @@ class FormBuilder
{ {
$this->model = $model; $this->model = $model;
} }
/** /**
* Get the current model instance on the form builder. * Get the current model instance on the form builder.
* *
@@ -527,7 +527,7 @@ class FormBuilder
// the element. Then we'll create the final textarea elements HTML for us. // the element. Then we'll create the final textarea elements HTML for us.
$options = $this->html->attributes($options); $options = $this->html->attributes($options);
return $this->toHtmlString('<textarea' . $options . '>' . e($value, false). '</textarea>'); return $this->toHtmlString('<textarea' . $options . '>' . e($value). '</textarea>');
} }
/** /**
@@ -709,23 +709,20 @@ class FormBuilder
* @param string $selected * @param string $selected
* @param array $attributes * @param array $attributes
* @param array $optionsAttributes * @param array $optionsAttributes
* @param integer $level
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [], $level = 0) protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [])
{ {
$html = []; $html = [];
$space = str_repeat("&nbsp;", $level);
foreach ($list as $value => $display) { foreach ($list as $value => $display) {
$optionAttributes = $optionsAttributes[$value] ?? []; $optionAttributes = $optionsAttributes[$value] ?? [];
if (is_array($display)) {
$html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level+5); $html[] = $this->option($display, $value, $selected, $optionAttributes);
} else {
$html[] = $this->option($space.$display, $value, $selected, $optionAttributes);
}
} }
return $this->toHtmlString('<optgroup label="' . e($space.$label, false) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
return $this->toHtmlString('<optgroup label="' . e($label) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
} }
/** /**
@@ -746,7 +743,7 @@ class FormBuilder
$string = '<option' . $this->html->attributes($options) . '>'; $string = '<option' . $this->html->attributes($options) . '>';
if ($display !== null) { if ($display !== null) {
$string .= e($display, false) . '</option>'; $string .= e($display) . '</option>';
} }
return $this->toHtmlString($string); return $this->toHtmlString($string);
@@ -769,7 +766,7 @@ class FormBuilder
'value' => '', 'value' => '',
]; ];
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display, false) . '</option>'); return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display) . '</option>');
} }
/** /**
@@ -871,7 +868,7 @@ class FormBuilder
return $this->getRadioCheckedState($name, $value, $checked); return $this->getRadioCheckedState($name, $value, $checked);
default: default:
return $this->compareValues($name, $value); return $this->getValueAttribute($name) === $value;
} }
} }
@@ -924,21 +921,7 @@ class FormBuilder
return $checked; return $checked;
} }
return $this->compareValues($name, $value); return $this->getValueAttribute($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;
} }
/** /**
@@ -1200,7 +1183,7 @@ class FormBuilder
} }
$request = $this->request($name); $request = $this->request($name);
if (! is_null($request) && $name != '_method') { if (! is_null($request) && $name !== '_method') {
return $request; return $request;
} }
@@ -1284,7 +1267,7 @@ class FormBuilder
*/ */
public function oldInputIsEmpty() public function oldInputIsEmpty()
{ {
return (isset($this->session) && count((array) $this->session->getOldInput()) === 0); return (isset($this->session) && count($this->session->getOldInput()) === 0);
} }
/** /**
+3 -3
View File
@@ -94,7 +94,7 @@ class HtmlBuilder
{ {
$defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet']; $defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'];
$attributes = array_merge($defaults, $attributes); $attributes = array_merge($attributes, $defaults);
$attributes['href'] = $this->url->asset($url, $secure); $attributes['href'] = $this->url->asset($url, $secure);
@@ -387,7 +387,7 @@ class HtmlBuilder
if (is_array($value)) { if (is_array($value)) {
return $this->nestedListing($key, $type, $value); return $this->nestedListing($key, $type, $value);
} else { } else {
return '<li>' . e($value, false) . '</li>'; return '<li>' . e($value) . '</li>';
} }
} }
@@ -456,7 +456,7 @@ class HtmlBuilder
} }
if (! is_null($value)) { if (! is_null($value)) {
return $key . '="' . e($value, false) . '"'; return $key . '="' . e($value) . '"';
} }
} }
+3 -24
View File
@@ -12,7 +12,7 @@ use Illuminate\Routing\UrlGenerator;
use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Capsule\Manager as Capsule;
use Mockery as m; use Mockery as m;
class FormAccessibleTest extends PHPUnit\Framework\TestCase class FormAccessibleTest extends PHPUnit_Framework_TestCase
{ {
public function setUp() public function setUp()
{ {
@@ -42,16 +42,10 @@ class FormAccessibleTest extends PHPUnit\Framework\TestCase
public function testItCanMutateValuesForForms() public function testItCanMutateValuesForForms()
{ {
$model = new ModelThatUsesForms($this->modelData); $model = new ModelThatUsesForms($this->modelData);
$user = new User(['name' => 'Anton']);
$model->setRelation('user', $user);
$this->formBuilder->setModel($model); $this->formBuilder->setModel($model);
$this->assertEquals($model->getFormValue('string'), 'ponmlkjihgfedcba'); $this->assertEquals($model->getFormValue('string'), 'ponmlkjihgfedcba');
$this->assertEquals($model->getFormValue('created_at'), $this->now->timestamp); $this->assertEquals($model->getFormValue('created_at'), $this->now->timestamp);
$this->assertEquals($user, $model->getFormValue('user'));
$this->assertEquals('Get name: Anton', $model->getFormValue('user')->name);
$this->assertEquals('Get name for form: Anton', $model->getFormValue('user.name'));
} }
public function testItCanMutateRelatedValuesForForms() public function testItCanMutateRelatedValuesForForms()
@@ -74,12 +68,12 @@ class FormAccessibleTest extends PHPUnit\Framework\TestCase
$model = new ModelThatUsesForms($this->modelData); $model = new ModelThatUsesForms($this->modelData);
$this->assertEquals($model->getFormValue('address.street'), 'abcde st'); $this->assertEquals($model->getFormValue('address.street'), 'abcde st');
} }
public function testItCanUseGetAccessorValuesWhenThereAreNoFormAccessors() public function testItCanUseGetAccessorValuesWhenThereAreNoFormAccessors()
{ {
$model = new ModelThatUsesForms($this->modelData); $model = new ModelThatUsesForms($this->modelData);
$this->formBuilder->setModel($model); $this->formBuilder->setModel($model);
$this->assertEquals($this->formBuilder->getValueAttribute('email'), 'mutated@tjshafer.com'); $this->assertEquals($this->formBuilder->getValueAttribute('email'), 'mutated@tjshafer.com');
} }
@@ -165,18 +159,3 @@ class ModelThatDoesntUseForms extends Model
return '1 second ago'; return '1 second ago';
} }
} }
class User extends Model
{
use FormAccessible;
public function formNameAttribute($value)
{
return 'Get name for form: ' . $value;
}
public function getNameAttribute($value)
{
return 'Get name: ' . $value;
}
}
+1 -16
View File
@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\App;
use Illuminate\Session\Store; use Illuminate\Session\Store;
use Mockery as m; use Mockery as m;
class FormBuilderTest extends PHPUnit\Framework\TestCase class FormBuilderTest extends PHPUnit_Framework_TestCase
{ {
/** /**
* @var FormBuilder * @var FormBuilder
@@ -658,21 +658,6 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase
$this->assertEquals('<input class="span2" name="foo" type="radio" value="foobar">', $form4); $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() public function testFormRadioRepopulation()
{ {
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session')); $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 Illuminate\Routing\UrlGenerator;
use Mockery as m; use Mockery as m;
class HtmlBuilderTest extends PHPUnit\Framework\TestCase class HtmlBuilderTest extends PHPUnit_Framework_TestCase
{ {
/** /**