From ef11b7dd2fe7561bb77a5abf657f0d8e7bd19d56 Mon Sep 17 00:00:00 2001 From: lanort Date: Mon, 14 Dec 2015 23:33:12 +0100 Subject: [PATCH 01/18] Update FormBuilder.php: fix to get selected value with 0 as index `getSelectedValue` returns always true if it receives a value (from an select input) of 0. To avoid that the strict parameter has to be set to true. This is because the following code does not work as might expected: "c16"] var_dump(in_array(0, [1=>"c16"])); // returns true --- src/FormBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index e948060..13aad94 100755 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -694,7 +694,7 @@ class FormBuilder protected function getSelectedValue($value, $selected) { if (is_array($selected)) { - return in_array($value, $selected) ? 'selected' : null; + return in_array($value, $selected, true) ? 'selected' : null; } return ((string) $value == (string) $selected) ? 'selected' : null; From 466aabedbdb67c02aabbb8408aac8841147c0ff0 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Tue, 15 Dec 2015 16:53:33 +1000 Subject: [PATCH 02/18] Add test for select optgroups --- tests/FormBuilderTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 9ee220c..50f326f 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -267,6 +267,27 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ['name' => 'select-name'] ); $this->assertEquals($select, ''); + + $select = $this->formBuilder->select( + 'size', + [ + 'Large sizes' => [ + 'L' => 'Large', + 'XL' => 'Extra Large', + ], + 'S' => 'Small', + ], + null, + [ + 'class' => 'class-name', + 'id' => 'select-id', + ] + ); + + $this->assertEquals( + $select, + '' + ); } public function testFormSelectRepopulation() From 6b68b0856c1cc6395b81274faaf1c675d89c97d9 Mon Sep 17 00:00:00 2001 From: Alexandre Butynski Date: Wed, 10 Feb 2016 13:45:37 +0100 Subject: [PATCH 03/18] Add PHP 7 to travis configuration --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d5e67c2..c574333 100755 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 5.5 - 5.6 + - 7.0 - hhvm sudo: false From 068dfb348d127dff10b0980fd9b826787d3817ef Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Tue, 15 Dec 2015 17:53:12 +1000 Subject: [PATCH 04/18] Support boolean attributes --- src/HtmlBuilder.php | 10 ++++++---- tests/FormBuilderTest.php | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index bcc5088..51ad68e 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -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)) { diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index ee8ac49..24fa70b 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -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('', $form3); } + public function testBooleanAttributes() + { + $input = $this->formBuilder->text('test', null, ['disabled']); + $this->assertEquals('', $input); + + $input = $this->formBuilder->textarea('test', null, ['readonly']); + $this->assertEquals('', $input); + } + protected function setModel(array $data, $object = true) { if ($object) { From 81c9ee7a7bc94437247826d2b61acfd5074cbb0b Mon Sep 17 00:00:00 2001 From: lanort Date: Thu, 3 Mar 2016 10:13:57 +0100 Subject: [PATCH 05/18] FormBuilderTest: testSelect: added test for '0'-key option Added assertion for the case, that the options for the select field contain a zero key, eg `['0' => 'All Sizes', 'L' => 'Large']` See also commit: https://github.com/LaravelCollective/html/pull/127/commits --- tests/FormBuilderTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index ee8ac49..eaa6fdc 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -260,6 +260,16 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ); $this->assertEquals($select, ''); + + $select = $this->formBuilder->select( + 'size', + ['0' => 'All Sizes', 'L' => 'Large', 'M' => 'Medium', 'S' => 'Small'], + ['M'], + ['multiple'] + ); + $this->assertEquals( + $select, + ''); $select = $this->formBuilder->select( 'size', From 0ba1bb0432d114d25905a922e20470a499df8d2e Mon Sep 17 00:00:00 2001 From: Zhang Yi Jiang Date: Tue, 12 Jul 2016 23:57:35 +0800 Subject: [PATCH 06/18] add unit tests to ensure presence of FormAccessible trait returns consistent results --- tests/FormAccessibleTest.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/FormAccessibleTest.php b/tests/FormAccessibleTest.php index 9add106..3d29a4b 100644 --- a/tests/FormAccessibleTest.php +++ b/tests/FormAccessibleTest.php @@ -27,6 +27,8 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase 'address' => [ 'street' => 'abcde st' ], + 'array' => [1, 2, 3,], + 'transform_key' => 'testing testing', 'created_at' => $this->now, 'updated_at' => $this->now, ]; @@ -51,6 +53,31 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase $model = new ModelThatUsesForms($this->modelData); $this->assertEquals($model->getFormValue('address.street'), 'abcde st'); } + + public function testItCanUseGetAccessorValuesWhenThereAreNoFormAccessors() + { + $model = new ModelThatUsesForms($this->modelData); + $this->formBuilder->setModel($model); + + $this->assertEquals($this->formBuilder->getValueAttribute('email'), 'mutated@tjshafer.com'); + } + + public function testItReturnsSameResultWithAndWithoutThisFeature() + { + $modelWithAccessor = new ModelThatUsesForms($this->modelData); + $modelWithoutAccessor = new ModelThatDoesntUseForms($this->modelData); + + $this->formBuilder->setModel($modelWithAccessor); + $valuesWithAccessor[] = $this->formBuilder->getValueAttribute('array'); + $valuesWithAccessor[] = $this->formBuilder->getValueAttribute('array[0]'); + $valuesWithAccessor[] = $this->formBuilder->getValueAttribute('transform.key'); + $this->formBuilder->setModel($modelWithoutAccessor); + $valuesWithoutAccessor[] = $this->formBuilder->getValueAttribute('array'); + $valuesWithoutAccessor[] = $this->formBuilder->getValueAttribute('array[0]'); + $valuesWithoutAccessor[] = $this->formBuilder->getValueAttribute('transform.key'); + + $this->assertEquals($valuesWithAccessor, $valuesWithoutAccessor); + } public function testItCanStillMutateValuesForViews() { @@ -96,6 +123,11 @@ class ModelThatUsesForms extends Model { return '1 second ago'; } + + public function getEmailAttribute($value) + { + return 'mutated@tjshafer.com'; + } } class ModelThatDoesntUseForms extends Model From 45fe4e7988fa53773167dc9b6d39f32916f45661 Mon Sep 17 00:00:00 2001 From: Victor Isadov Date: Sat, 13 Aug 2016 11:57:01 +0300 Subject: [PATCH 07/18] Add Request support --- src/FormBuilder.php | 17 ++++++++++++++++- tests/FormBuilderTest.php | 22 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 4e7cf0f..565931d 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -4,6 +4,7 @@ namespace Collective\Html; use DateTime; use BadMethodCallException; +use Illuminate\Http\Request; use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; use Illuminate\Contracts\View\Factory; @@ -67,6 +68,8 @@ class FormBuilder */ protected $labels = []; + public $request; + /** * The reserved form open attributes. * @@ -96,12 +99,13 @@ class FormBuilder * @param \Illuminate\Contracts\View\Factory $view * @param string $csrfToken */ - public function __construct(HtmlBuilder $html, UrlGenerator $url, Factory $view, $csrfToken) + public function __construct(HtmlBuilder $html, UrlGenerator $url, Factory $view, $csrfToken, Request $request = null) { $this->url = $url; $this->html = $html; $this->view = $view; $this->csrfToken = $csrfToken; + $this->request = $request; } /** @@ -1088,6 +1092,12 @@ class FormBuilder return $this->old($name); } + + $request_value = $this->request($name); + if (!is_null($request_value)) { + return $request_value; + } + if (! is_null($value)) { return $value; } @@ -1097,6 +1107,11 @@ class FormBuilder } } + protected function request($name) + { + return $this->request->input($this->transformKey($name)); + } + /** * Get the model value that should be assigned to the field. * diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 3e4eaad..babf01d 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -12,6 +12,11 @@ use Mockery as m; class FormBuilderTest extends PHPUnit_Framework_TestCase { + /** + * @var FormBuilder + */ + protected $formBuilder; + /** * Setup the test environment. */ @@ -20,7 +25,16 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->urlGenerator = new UrlGenerator(new RouteCollection(), Request::create('/foo', 'GET')); $this->viewFactory = m::mock(Factory::class); $this->htmlBuilder = new HtmlBuilder($this->urlGenerator, $this->viewFactory); - $this->formBuilder = new FormBuilder($this->htmlBuilder, $this->urlGenerator, $this->viewFactory, 'abc'); + + $request = Request::create('/foo', 'GET', [ + "text" => [ + "value" => 1 + ], + ]); + + $request = Request::createFromBase($request); + + $this->formBuilder = new FormBuilder($this->htmlBuilder, $this->urlGenerator, $this->viewFactory, 'abc', $request); } /** @@ -31,6 +45,12 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase m::close(); } + public function testRequestValue() + { + $text = $this->formBuilder->text("text[value]"); + $this->assertEquals('', $text); + } + public function testOpeningForm() { $form1 = $this->formBuilder->open(['method' => 'GET']); From 16264f1c8d724e23bf16b78074fc765f2545e527 Mon Sep 17 00:00:00 2001 From: Victor Isadov Date: Sat, 13 Aug 2016 12:26:27 +0300 Subject: [PATCH 08/18] Add tests and checkbox handling --- src/FormBuilder.php | 17 +++++++++++------ src/HtmlServiceProvider.php | 2 +- tests/FormBuilderTest.php | 15 +++++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 565931d..e53eb02 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -813,11 +813,13 @@ class FormBuilder */ protected function getCheckboxCheckedState($name, $value, $checked) { - if (isset($this->session) && ! $this->oldInputIsEmpty() && is_null($this->old($name))) { + $request = $this->request($name); + + if (isset($this->session) && ! $this->oldInputIsEmpty() && is_null($this->old($name)) && !$request) { return false; } - if ($this->missingOldAndModel($name)) { + if ($this->missingOldAndModel($name) && !$request) { return $checked; } @@ -1092,10 +1094,9 @@ class FormBuilder return $this->old($name); } - - $request_value = $this->request($name); - if (!is_null($request_value)) { - return $request_value; + $request = $this->request($name); + if (!is_null($request)) { + return $request; } if (! is_null($value)) { @@ -1109,6 +1110,10 @@ class FormBuilder protected function request($name) { + if(!isset($this->request)){ + return null; + } + return $this->request->input($this->transformKey($name)); } diff --git a/src/HtmlServiceProvider.php b/src/HtmlServiceProvider.php index c632e56..e3aa134 100755 --- a/src/HtmlServiceProvider.php +++ b/src/HtmlServiceProvider.php @@ -49,7 +49,7 @@ class HtmlServiceProvider extends ServiceProvider protected function registerFormBuilder() { $this->app->singleton('form', function ($app) { - $form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->getToken()); + $form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->getToken(), $app['request']); return $form->setSessionStore($app['session.store']); }); diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index babf01d..5762c6e 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -27,9 +27,11 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->htmlBuilder = new HtmlBuilder($this->urlGenerator, $this->viewFactory); $request = Request::create('/foo', 'GET', [ - "text" => [ - "value" => 1 + "person" => [ + "name" => "John", + "surname" => "Doe" ], + "aggree" => 1 ]); $request = Request::createFromBase($request); @@ -47,8 +49,13 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase public function testRequestValue() { - $text = $this->formBuilder->text("text[value]"); - $this->assertEquals('', $text); + $name = $this->formBuilder->text("person[name]"); + $surname = $this->formBuilder->text("person[surname]"); + $this->assertEquals('', $name); + $this->assertEquals('', $surname); + + $checkbox = $this->formBuilder->checkbox("aggree", 1); + $this->assertEquals('', $checkbox); } public function testOpeningForm() From c47d34b7de8f462f129833c7b95700d36a5c56e2 Mon Sep 17 00:00:00 2001 From: Victor Isadov Date: Sat, 13 Aug 2016 12:35:26 +0300 Subject: [PATCH 09/18] Test checkbox array --- src/FormBuilder.php | 9 ++++++++- tests/FormBuilderTest.php | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index e53eb02..11d3159 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -845,7 +845,9 @@ class FormBuilder */ protected function getRadioCheckedState($name, $value, $checked) { - if ($this->missingOldAndModel($name)) { + $request = $this->request($name); + + if ($this->missingOldAndModel($name) && !$request) { return $checked; } @@ -1108,6 +1110,11 @@ class FormBuilder } } + /** + * Get value from current Request + * @param $name + * @return array|null|string + */ protected function request($name) { if(!isset($this->request)){ diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 5762c6e..85abc99 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -26,12 +26,14 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->viewFactory = m::mock(Factory::class); $this->htmlBuilder = new HtmlBuilder($this->urlGenerator, $this->viewFactory); + // prepare request for test with some data $request = Request::create('/foo', 'GET', [ "person" => [ "name" => "John", "surname" => "Doe" ], - "aggree" => 1 + "aggree" => 1, + "checkbox_array" => [1,2,3] ]); $request = Request::createFromBase($request); @@ -54,8 +56,20 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('', $name); $this->assertEquals('', $surname); - $checkbox = $this->formBuilder->checkbox("aggree", 1); - $this->assertEquals('', $checkbox); + $checked = $this->formBuilder->checkbox("aggree", 1); + $unchecked = $this->formBuilder->checkbox("no_value", 1); + $this->assertEquals('', $checked); + $this->assertEquals('', $unchecked); + + $checked_array = $this->formBuilder->checkbox("checkbox_array[]", 1); + $unchecked_array = $this->formBuilder->checkbox("checkbox_array[]", 4); + $this->assertEquals('', $checked_array); + $this->assertEquals('', $unchecked_array); + + $checked = $this->formBuilder->radio("aggree", 1); + $unchecked = $this->formBuilder->radio("no_value", 1); + $this->assertEquals('', $checked); + $this->assertEquals('', $unchecked); } public function testOpeningForm() From e152172962bf4cf1bdb97ed0fb41b2bfecc8ed4c Mon Sep 17 00:00:00 2001 From: Victor Isadov Date: Sat, 13 Aug 2016 13:10:38 +0300 Subject: [PATCH 10/18] Make request protected --- src/FormBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 11d3159..fbf238a 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -68,7 +68,7 @@ class FormBuilder */ protected $labels = []; - public $request; + protected $request; /** * The reserved form open attributes. From 3f474b0bec868709995110503846a06c3882da6c Mon Sep 17 00:00:00 2001 From: Victor Isadov Date: Sat, 13 Aug 2016 13:25:29 +0300 Subject: [PATCH 11/18] Fix style --- src/FormBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index fbf238a..bf91e4a 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -1117,7 +1117,7 @@ class FormBuilder */ protected function request($name) { - if(!isset($this->request)){ + if (!isset($this->request)) { return null; } From 1add9b421ac013612595cf18581d7fd15e7c159f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Pallar=C3=A9s?= Date: Thu, 28 Apr 2016 14:06:22 +0200 Subject: [PATCH 12/18] Treat boolean attributes as HTML properties --- src/HtmlBuilder.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index 7306fc4..1d40f68 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -447,6 +447,11 @@ class HtmlBuilder if (is_numeric($key)) { $key = $value; } + + // Treat boolean attributes as HTML properties + if (is_bool($value)) { + return $value ? $key : ''; + } if (! is_null($value)) { return $key . '="' . e($value) . '"'; From dc15cf8463afb980049bc9aba5b0a7856435a746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Pallar=C3=A9s?= Date: Tue, 16 Aug 2016 09:24:57 +0200 Subject: [PATCH 13/18] Add test for boolean attributes --- tests/HtmlBuilderTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index 44baeb8..1406ad7 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -58,7 +58,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase $this->htmlBuilder->image('http://example.com/image1'), $this->htmlBuilder->image('http://example.com/image2'), ]; - + $result4 = $this->htmlBuilder->tag('div', $content, ['class' => 'row']); $this->assertEquals('

' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '

' . PHP_EOL, $result1); @@ -115,4 +115,15 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('<span>First Name Last</span>', $result1); $this->assertEquals('First Name Last', $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)); + } } From e8ca58357c00cbf6867d49b01eafc11a0d44c642 Mon Sep 17 00:00:00 2001 From: darthrevan13 Date: Tue, 27 Sep 2016 19:27:44 +0300 Subject: [PATCH 14/18] changed test unit to reflect placeholder changes --- tests/FormBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 3e4eaad..9115cc8 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -334,7 +334,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ['placeholder' => 'Select One...'] ); $this->assertEquals($select, - ''); + ''); $select = $this->formBuilder->select( 'size', @@ -343,7 +343,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ['placeholder' => 'Select One...'] ); $this->assertEquals($select, - ''); + ''); } public function testFormSelectYear() From 410943c5e19fbdee374d1ed9c59a43b2a365e66d Mon Sep 17 00:00:00 2001 From: darthrevan13 Date: Tue, 27 Sep 2016 19:52:22 +0300 Subject: [PATCH 15/18] changed select placeholder to major browser standards http://stackoverflow.com/a/8442831/1722248 --- src/FormBuilder.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 4e7cf0f..fe544b9 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -694,9 +694,13 @@ class FormBuilder protected function placeholderOption($display, $selected) { $selected = $this->getSelectedValue(null, $selected); - - $options = compact('selected'); - $options['value'] = ''; + + $options = [ + 'selected' => $selected, + 'disabled' => 'disabled', + 'hidden' => 'hidden', + 'value' => '' + ]; return $this->toHtmlString('html->attributes($options) . '>' . e($display) . ''); } From 89a9f40956595f7446cf687a22c791e65d413e19 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sun, 16 Oct 2016 09:45:18 +0200 Subject: [PATCH 16/18] Check if component/macro exists instead of relying on exceptions --- src/FormBuilder.php | 8 ++------ src/HtmlBuilder.php | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 4e7cf0f..f014b32 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -1197,16 +1197,12 @@ class FormBuilder */ public function __call($method, $parameters) { - try { + if (static::hasComponent($method)) { return $this->componentCall($method, $parameters); - } catch (BadMethodCallException $e) { - // } - try { + if (static::hasMacro($method)) { return $this->macroCall($method, $parameters); - } catch (BadMethodCallException $e) { - // } throw new BadMethodCallException("Method {$method} does not exist."); diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index 7306fc4..95e9fb7 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -546,16 +546,12 @@ class HtmlBuilder */ public function __call($method, $parameters) { - try { + if (static::hasComponent($method)) { return $this->componentCall($method, $parameters); - } catch (BadMethodCallException $e) { - // } - try { + if (static::hasMacro($method)) { return $this->macroCall($method, $parameters); - } catch (BadMethodCallException $e) { - // } throw new BadMethodCallException("Method {$method} does not exist."); From cd06dfffb3ed77bf98eddae2ef3248ad4149a038 Mon Sep 17 00:00:00 2001 From: darthrevan13 Date: Sun, 19 Feb 2017 13:54:13 +0200 Subject: [PATCH 17/18] Update FormBuilderTest.php --- tests/FormBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index b85ebb6..40754e6 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -365,7 +365,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ['placeholder' => 'Select the  '] ); $this->assertEquals($select, - '' + '' ); } From 28df2ea235f3111e60e236aaf7e8e12dc75f0178 Mon Sep 17 00:00:00 2001 From: mlantz Date: Sat, 20 May 2017 15:04:52 -0400 Subject: [PATCH 18/18] Removing the double escape --- src/FormBuilder.php | 10 +++++----- src/HtmlBuilder.php | 16 ++-------------- tests/FormBuilderTest.php | 6 +++--- tests/HtmlBuilderTest.php | 4 ++-- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 0e8db0f..5ec62db 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -485,7 +485,7 @@ class FormBuilder // the element. Then we'll create the final textarea elements HTML for us. $options = $this->html->attributes($options); - return $this->toHtmlString('' . $this->html->escapeAll($value). ''); + return $this->toHtmlString('' . $value. ''); } /** @@ -662,7 +662,7 @@ class FormBuilder $html[] = $this->option($display, $value, $selected); } - return $this->toHtmlString('' . implode('', $html) . ''); + return $this->toHtmlString('' . implode('', $html) . ''); } /** @@ -680,7 +680,7 @@ class FormBuilder $options = ['value' => $value, 'selected' => $selected]; - return $this->toHtmlString('html->attributes($options) . '>' . $this->html->escapeAll($display) . ''); + return $this->toHtmlString('html->attributes($options) . '>' . e($display) . ''); } /** @@ -694,7 +694,7 @@ class FormBuilder protected function placeholderOption($display, $selected) { $selected = $this->getSelectedValue(null, $selected); - + $options = [ 'selected' => $selected, 'disabled' => 'disabled', @@ -702,7 +702,7 @@ class FormBuilder 'value' => '' ]; - return $this->toHtmlString('html->attributes($options) . '>' . $this->html->escapeAll($display) . ''); + return $this->toHtmlString('html->attributes($options) . '>' . e($display) . ''); } /** diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index e6bc518..e531792 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -53,18 +53,6 @@ class HtmlBuilder return htmlentities($value, ENT_QUOTES, 'UTF-8', false); } - /** - * Convert all applicable characters to HTML entities. - * - * @param string $value - * - * @return string - */ - public function escapeAll($value) - { - return htmlentities($value, ENT_QUOTES, 'UTF-8'); - } - /** * Convert entities to HTML characters. * @@ -399,7 +387,7 @@ class HtmlBuilder if (is_array($value)) { return $this->nestedListing($key, $type, $value); } else { - return '
  • ' . $this->escapeAll($value) . '
  • '; + return '
  • ' . e($value) . '
  • '; } } @@ -461,7 +449,7 @@ class HtmlBuilder } if (! is_null($value)) { - return $key . '="' . $this->escapeAll($value) . '"'; + return $key . '="' . e($value) . '"'; } } diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 40754e6..705673e 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -245,7 +245,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('', $form2); $this->assertEquals('', $form3); $this->assertEquals('', $form4); - $this->assertEquals('', $form5); + $this->assertEquals('', $form5); } public function testSelect() @@ -312,7 +312,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals( $select, - '' + '' ); } @@ -365,7 +365,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ['placeholder' => 'Select the  '] ); $this->assertEquals($select, - '' + '' ); } diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index 747c89a..3510c4e 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -47,7 +47,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase $ol = $this->htmlBuilder->ol($list, $attributes); - $this->assertEquals('
    1. foo
    2. bar
    3. &amp;
    ', $ol); + $this->assertEquals('
    1. foo
    2. bar
    3. &
    ', $ol); } public function testUl() @@ -58,7 +58,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase $ul = $this->htmlBuilder->ul($list, $attributes); - $this->assertEquals('
    • foo
    • bar
    • &amp;
    ', $ul); + $this->assertEquals('
    • foo
    • bar
    • &
    ', $ul); } public function testMeta()