Compare commits

...
45 Commits
Author SHA1 Message Date
Max Mitschke e6496328af Added Laravel 5.6 stable support (#484)
* Laravel 5.6 stable support

* fixed bug where opt group attributes where passed to option, added opt group attributes to opt group

* dropped php 7.0 because Laravel minimum requirement is now php 7.1.3
2018-02-08 08:16:30 -08:00
Vendin 137a2efcf1 Getting relation data for model accessor (#474) 2018-02-05 08:22:47 -07:00
Tom Shafer 32c27a54cd Merge branch 'master' of github.com:LaravelCollective/html 2018-02-05 08:09:36 -07:00
Tom Shafer f9deb1da6f Merge branch '5.5' of github.com:LaravelCollective/html 2018-02-05 08:09:29 -07:00
ThunderbirdsX3 5feb06537d Fix placeholder not hide in select list. (#473)
* Update test.

* Fix place holder show in select list.
2018-02-05 07:59:23 -07:00
Vendin e1318fcfdd Getting data for a form from a relation (#472) 2018-02-05 07:58:09 -07:00
Lluís Bayer Soler cecb65626c Nested optgroups (#470)
* fix optionGroup and added a function to handle recursively the arrays

* simplify recursively

* fix codestyle

* fix codestyle

* add new parameter annotation
2018-02-05 07:04:30 -07:00
Luiz Gustavo Martins 2c5db92f66 Fix some inputs treated like nestedModel when using an accessor (#471)
* 5.6 Prep

* Added $optgroupsAttributes parameter to select method.

* escape HTML entities in `src`-attribute

* Style fixes. Replaced == with ===.
2018-02-05 07:04:02 -07:00
Tom Shafer 7e49960e8f Merge pull request #421 from thetar/patch-1
Adds getModel()
2018-02-05 06:45:48 -07:00
Tom Shafer f3b55c6033 Merge pull request #442 from izniburak/5.5-array_merge
+ operator doesn't merge. Replaced by array_merge method.
2018-02-05 06:43:39 -07:00
Tom Shafer a5f7464ee6 Merge pull request #469 from crishoj/5.5
Proposal: Escape HTML entities in `src`-attribute
2018-02-05 06:41:39 -07:00
Tom Shafer cd71ed1538 Merge branch '5.5'
# Conflicts:
#	src/FormBuilder.php
2018-02-04 15:06:18 -07:00
Tom Shafer e2fcbee917 Merge pull request #460 from tortuetorche/5.5
[5.5] Form method of hidden input '_method' is preserved on next request
2018-02-04 15:03:46 -07:00
Tom Shafer 2dfc110b6c Merge pull request #416 from djh101/master
Added $optgroupsAttributes parameter to select method.
2018-02-04 14:59:15 -07:00
Tom Shafer 8997f1209d Merge branch '5.5' 2018-02-04 14:46:24 -07:00
Tom Shafer ac46825a97 Merge pull request #453 from mvaraujo/patch-1
#452
2018-02-04 14:41:29 -07:00
Tom Shafer 33dd7bb48e Merge pull request #448 from peterparkers/patch-1
Update composer.json
2018-02-04 14:38:05 -07:00
Tom Shafer 779d075f79 Merge pull request #458 from nickurt/patch-1
Remove PHP_EOL statements by HTML-tags ..
2018-02-04 14:37:47 -07:00
nickurt 29253c13a3 fixed tests .. 2018-01-03 14:50:42 +01:00
nickurt d621ce1357 remove php_eol statements by html-tags #456 2018-01-03 14:25:43 +01:00
Tortue Torche 9e2a40555a Merge branch 'patch-1' into 5.5 2017-12-22 14:09:39 +01:00
Marcus Vinicius Araujo 8f7bc4d097 #452
This shall be occuring for check-boxes. Please, check'em for us.
2017-12-18 17:23:46 -02:00
Phurinat Puekkham cf13e067eb Update composer.json
more secure
2017-12-04 19:40:08 +07:00
İzni Burak Demirtaş b39f510897 + operator doesn't merge. Replaced by array_merge method. 2017-10-26 10:37:42 +03:00
Drew b4c0a3e26d Style fixes. Replaced == with ===. 2017-09-18 16:28:31 -07:00
Tony e6bc7e5fea Adds getModel()
It would be nice to be able to get the model before setting a new one (maybe in a partial) and having the original model to set back at the end of the partial.
2017-09-14 10:51:14 -05:00
Christian Rishøj 1810274c8a escape HTML entities in src-attribute 2017-09-14 11:42:34 +07:00
Drew f380cdc14d Added $optgroupsAttributes parameter to select method. 2017-09-08 21:20:14 -07:00
Matt Lantz 0ac9642ebb Merge branch '5.5' 2017-08-31 10:47:12 -04:00
Matt Lantz 2f6dc39ab3 Merge branch '5.4' into 5.5 2017-08-31 10:46:03 -04:00
Matt Lantz 422ba2ea8d Drop branch alias 2017-08-31 10:44:19 -04:00
Matt Lantz b9322c703d 5.6 Prep 2017-08-31 10:38:54 -04:00
Matt Lantz e3d9fe169d Merge pull request #409 from cmizzi/master
Use stable laravel 5.5 version
2017-08-31 10:34:34 -04:00
Cyril Mizzi 06d4296d18 use stable laravel 5.5 version 2017-08-30 15:00:04 +02:00
mlantz 97fa90bf64 Merge branch 'yajra-patch-composer' 2017-08-12 11:48:49 -04:00
mlantz 79f59a016c Merge branch 'patch-composer' of https://github.com/yajra/html into yajra-patch-composer 2017-08-12 11:48:33 -04:00
Matt Lantz 3841eb8c89 Merge pull request #357 from rinvex/patch-1
Support Auto-Discovery
2017-08-12 11:44:36 -04:00
Matt Lantz adf0d91e2c Merge pull request #394 from sroutier/master
Fix getToken() for token().
2017-08-12 11:17:57 -04:00
Tortue Torche 3688b0e433 Form method of hidden input '_method' is preserved on next request
E.G. When you submitted data across a form with a 'PATCH' method and then in a second submit you use a form with a 'DELETE' method, the FormBuilder::getValueAttribute() method use the previous value of the hidden input '_method'.
So the value is replaced by 'PATCH' instead of the 'DELETE' value.
2017-08-09 14:23:33 +02:00
Sebastien Routier b91158bae5 Fix getToken() for token(). 2017-08-04 19:26:20 -04:00
Arjay Angeles 471a0aa5e4 Add branch alias for 5.5.x-dev.
Add support for auto discovery.
2017-06-24 13:04:09 +08:00
Abdelrahman Omran 291da712f4 Support Auto-Discovery 2017-06-14 14:03:27 +02:00
mlantz a47a02b962 Corrections for master 2017-05-21 23:44:19 -04:00
mlantz d7aba64b44 Master version fix 2017-05-21 23:38:47 -04:00
mlantz e6471f3be1 Master updates 2017-05-21 23:35:56 -04:00
8 changed files with 160 additions and 66 deletions

No files matched your search

-2
View File
@@ -1,8 +1,6 @@
language: php language: php
php: php:
- 5.6
- 7.0
- 7.1 - 7.1
sudo: false sudo: false
+24 -8
View File
@@ -2,7 +2,7 @@
"name": "laravelcollective/html", "name": "laravelcollective/html",
"description": "HTML and Form Builders for the Laravel Framework", "description": "HTML and Form Builders for the Laravel Framework",
"license": "MIT", "license": "MIT",
"homepage": "http://laravelcollective.com", "homepage": "https://laravelcollective.com",
"support": { "support": {
"issues": "https://github.com/LaravelCollective/html/issues", "issues": "https://github.com/LaravelCollective/html/issues",
"source": "https://github.com/LaravelCollective/html" "source": "https://github.com/LaravelCollective/html"
@@ -18,15 +18,15 @@
} }
], ],
"require": { "require": {
"php": ">=5.6.4", "php": ">=7.1.3",
"illuminate/http": "5.4.*", "illuminate/http": "5.6.*",
"illuminate/routing": "5.4.*", "illuminate/routing": "5.6.*",
"illuminate/session": "5.4.*", "illuminate/session": "5.6.*",
"illuminate/support": "5.4.*", "illuminate/support": "5.6.*",
"illuminate/view": "5.4.*" "illuminate/view": "5.6.*"
}, },
"require-dev": { "require-dev": {
"illuminate/database": "5.4.*", "illuminate/database": "5.6.*",
"mockery/mockery": "~0.9.4", "mockery/mockery": "~0.9.4",
"phpunit/phpunit": "~5.4" "phpunit/phpunit": "~5.4"
}, },
@@ -37,5 +37,21 @@
"files": [ "files": [
"src/helpers.php" "src/helpers.php"
] ]
},
"extra": {
"branch-alias": {
"dev-master": "5.6-dev"
},
"laravel": {
"providers": [
"Collective\\Html\\HtmlServiceProvider"
],
"aliases": {
"Form": "Collective\\Html\\FormFacade",
"Html": "Collective\\Html\\HtmlFacade"
} }
}
},
"minimum-stability": "dev",
"prefer-stable": true
} }
+4 -4
View File
@@ -49,11 +49,11 @@ trait FormAccessible
unset($keys[0]); unset($keys[0]);
$key = implode('.', $keys); $key = implode('.', $keys);
if ($this->hasFormMutator($key)) { if (method_exists($relatedModel, 'hasFormMutator') && $key !== '' && $relatedModel->hasFormMutator($key)) {
return $relatedModel->getFormValue($key); return $relatedModel->getFormValue($key);
} }
return data_get($relatedModel, $key); return data_get($relatedModel, empty($key)? null: $key);
} }
// No form mutator, let the model resolve this // No form mutator, let the model resolve this
@@ -81,13 +81,13 @@ trait FormAccessible
* *
* @return bool * @return bool
*/ */
protected function hasFormMutator($key) public function hasFormMutator($key)
{ {
$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 (ReflectionMethod $method) use ($key) {
return $method->getName() == 'form' . Str::studly($key) . 'Attribute'; return $method->getName() === 'form' . Str::studly($key) . 'Attribute';
}); });
return (bool) $mutator; return (bool) $mutator;
+54 -29
View File
@@ -191,6 +191,16 @@ class FormBuilder
$this->model = $model; $this->model = $model;
} }
/**
* Get the current model instance on the form builder.
*
* @return mixed $model
*/
public function getModel()
{
return $this->model;
}
/** /**
* Close the current form. * Close the current form.
* *
@@ -517,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). '</textarea>'); return $this->toHtmlString('<textarea' . $options . '>' . e($value, false). '</textarea>');
} }
/** /**
@@ -565,6 +575,7 @@ class FormBuilder
* @param string $selected * @param string $selected
* @param array $selectAttributes * @param array $selectAttributes
* @param array $optionsAttributes * @param array $optionsAttributes
* @param array $optgroupsAttributes
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
@@ -573,7 +584,8 @@ class FormBuilder
$list = [], $list = [],
$selected = null, $selected = null,
array $selectAttributes = [], array $selectAttributes = [],
array $optionsAttributes = [] array $optionsAttributes = [],
array $optgroupsAttributes = []
) { ) {
$this->type = 'select'; $this->type = 'select';
@@ -599,8 +611,9 @@ class FormBuilder
} }
foreach ($list as $value => $display) { foreach ($list as $value => $display) {
$optionAttributes = isset($optionsAttributes[$value]) ? $optionsAttributes[$value] : []; $optionAttributes = $optionsAttributes[$value] ?? [];
$html[] = $this->getSelectOption($display, $value, $selected, $optionAttributes); $optgroupAttributes = $optgroupsAttributes[$value] ?? [];
$html[] = $this->getSelectOption($display, $value, $selected, $optionAttributes, $optgroupAttributes);
} }
// Once we have all of this HTML, we can join this into a single element after // Once we have all of this HTML, we can join this into a single element after
@@ -675,13 +688,14 @@ class FormBuilder
* @param string $value * @param string $value
* @param string $selected * @param string $selected
* @param array $attributes * @param array $attributes
* @param array $optgroupAttributes
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
public function getSelectOption($display, $value, $selected, array $attributes = []) public function getSelectOption($display, $value, $selected, array $attributes = [], array $optgroupAttributes = [])
{ {
if (is_array($display)) { if (is_array($display)) {
return $this->optionGroup($display, $value, $selected, $attributes); return $this->optionGroup($display, $value, $selected, $optgroupAttributes, $attributes);
} }
return $this->option($display, $value, $selected, $attributes); return $this->option($display, $value, $selected, $attributes);
@@ -694,18 +708,24 @@ class FormBuilder
* @param string $label * @param string $label
* @param string $selected * @param string $selected
* @param array $attributes * @param array $attributes
* @param array $optionsAttributes
* @param integer $level
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
protected function optionGroup($list, $label, $selected, array $attributes = []) protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [], $level = 0)
{ {
$html = []; $html = [];
$space = str_repeat("&nbsp;", $level);
foreach ($list as $value => $display) { foreach ($list as $value => $display) {
$html[] = $this->option($display, $value, $selected, $attributes); $optionAttributes = $optionsAttributes[$value] ?? [];
if (is_array($display)) {
$html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level+5);
} else {
$html[] = $this->option($space.$display, $value, $selected, $optionAttributes);
} }
}
return $this->toHtmlString('<optgroup label="' . e($label) . '">' . implode('', $html) . '</optgroup>'); return $this->toHtmlString('<optgroup label="' . e($space.$label, false) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
} }
/** /**
@@ -722,9 +742,14 @@ class FormBuilder
{ {
$selected = $this->getSelectedValue($value, $selected); $selected = $this->getSelectedValue($value, $selected);
$options = ['value' => $value, 'selected' => $selected] + $attributes; $options = array_merge(['value' => $value, 'selected' => $selected], $attributes);
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display) . '</option>'); $string = '<option' . $this->html->attributes($options) . '>';
if ($display !== null) {
$string .= e($display, false) . '</option>';
}
return $this->toHtmlString($string);
} }
/** /**
@@ -744,7 +769,7 @@ class FormBuilder
'value' => '', 'value' => '',
]; ];
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display) . '</option>'); return $this->toHtmlString('<option' . $this->html->attributes($options) . ' hidden="hidden">' . e($display, false) . '</option>');
} }
/** /**
@@ -763,7 +788,7 @@ class FormBuilder
return $selected->contains($value) ? 'selected' : null; return $selected->contains($value) ? 'selected' : null;
} }
return ((string) $value == (string) $selected) ? 'selected' : null; return ((string) $value === (string) $selected) ? 'selected' : null;
} }
/** /**
@@ -844,7 +869,7 @@ class FormBuilder
return $this->getRadioCheckedState($name, $value, $checked); return $this->getRadioCheckedState($name, $value, $checked);
default: default:
return $this->getValueAttribute($name) == $value; return $this->getValueAttribute($name) === $value;
} }
} }
@@ -865,7 +890,7 @@ class FormBuilder
return false; return false;
} }
if ($this->missingOldAndModel($name) && !$request) { if ($this->missingOldAndModel($name) && is_null($request)) {
return $checked; return $checked;
} }
@@ -897,7 +922,7 @@ class FormBuilder
return $checked; return $checked;
} }
return $this->getValueAttribute($name) == $value; return $this->getValueAttribute($name) === $value;
} }
/** /**
@@ -996,7 +1021,7 @@ class FormBuilder
{ {
$method = strtoupper($method); $method = strtoupper($method);
return $method != 'GET' ? 'POST' : $method; return $method !== 'GET' ? 'POST' : $method;
} }
/** /**
@@ -1098,7 +1123,7 @@ class FormBuilder
// If the method is something other than GET we will go ahead and attach the // If the method is something other than GET we will go ahead and attach the
// CSRF token to the form, as this can't hurt and is convenient to simply // CSRF token to the form, as this can't hurt and is convenient to simply
// always have available on every form the developers creates for them. // always have available on every form the developers creates for them.
if ($method != 'GET') { if ($method !== 'GET') {
$appendage .= $this->token(); $appendage .= $this->token();
} }
@@ -1140,7 +1165,7 @@ class FormBuilder
$old = $this->old($name); $old = $this->old($name);
if (! is_null($old) && $name != '_method') { if (! is_null($old) && $name !== '_method') {
return $old; return $old;
} }
@@ -1151,7 +1176,7 @@ class FormBuilder
if ($hasNullMiddleware if ($hasNullMiddleware
&& is_null($old) && is_null($old)
&& is_null($value) && is_null($value)
&& !is_null($this->view->shared('errors')) && ! is_null($this->view->shared('errors'))
&& count($this->view->shared('errors')) > 0 && count($this->view->shared('errors')) > 0
) { ) {
return null; return null;
@@ -1159,7 +1184,7 @@ class FormBuilder
} }
$request = $this->request($name); $request = $this->request($name);
if (!is_null($request)) { if (! is_null($request)) {
return $request; return $request;
} }
@@ -1179,7 +1204,7 @@ class FormBuilder
*/ */
protected function request($name) protected function request($name)
{ {
if (!isset($this->request)) { if (! isset($this->request)) {
return null; return null;
} }
@@ -1217,16 +1242,16 @@ class FormBuilder
$key = $this->transformKey($name); $key = $this->transformKey($name);
$payload = $this->session->getOldInput($key); $payload = $this->session->getOldInput($key);
if (!is_array($payload)) { if (! is_array($payload)) {
return $payload; return $payload;
} }
if (!in_array($this->type, ['select', 'checkbox'])) { if (! in_array($this->type, ['select', 'checkbox'])) {
if (!isset($this->payload[$key])) { if (! isset($this->payload[$key])) {
$this->payload[$key] = collect($payload); $this->payload[$key] = collect($payload);
} }
if (!empty($this->payload[$key])) { if (! empty($this->payload[$key])) {
$value = $this->payload[$key]->shift(); $value = $this->payload[$key]->shift();
return $value; return $value;
} }
@@ -1243,7 +1268,7 @@ class FormBuilder
*/ */
public function oldInputIsEmpty() public function oldInputIsEmpty()
{ {
return (isset($this->session) && count($this->session->getOldInput()) == 0); return (isset($this->session) && count($this->session->getOldInput()) === 0);
} }
/** /**
+13 -13
View File
@@ -78,7 +78,7 @@ class HtmlBuilder
{ {
$attributes['src'] = $this->url->asset($url, $secure); $attributes['src'] = $this->url->asset($url, $secure);
return $this->toHtmlString('<script' . $this->attributes($attributes) . '></script>' . PHP_EOL); return $this->toHtmlString('<script' . $this->attributes($attributes) . '></script>');
} }
/** /**
@@ -94,11 +94,11 @@ class HtmlBuilder
{ {
$defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet']; $defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'];
$attributes = $attributes + $defaults; $attributes = array_merge($attributes, $defaults);
$attributes['href'] = $this->url->asset($url, $secure); $attributes['href'] = $this->url->asset($url, $secure);
return $this->toHtmlString('<link' . $this->attributes($attributes) . '>' . PHP_EOL); return $this->toHtmlString('<link' . $this->attributes($attributes) . '>');
} }
/** /**
@@ -132,11 +132,11 @@ class HtmlBuilder
{ {
$defaults = ['rel' => 'shortcut icon', 'type' => 'image/x-icon']; $defaults = ['rel' => 'shortcut icon', 'type' => 'image/x-icon'];
$attributes = $attributes + $defaults; $attributes = array_merge($attributes, $defaults);
$attributes['href'] = $this->url->asset($url, $secure); $attributes['href'] = $this->url->asset($url, $secure);
return $this->toHtmlString('<link' . $this->attributes($attributes) . '>' . PHP_EOL); return $this->toHtmlString('<link' . $this->attributes($attributes) . '>');
} }
/** /**
@@ -162,7 +162,7 @@ class HtmlBuilder
$title = $this->entities($title); $title = $this->entities($title);
} }
return $this->toHtmlString('<a href="' . $url . '"' . $this->attributes($attributes) . '>' . $title . '</a>'); return $this->toHtmlString('<a href="' . $this->entities($url) . '"' . $this->attributes($attributes) . '>' . $title . '</a>');
} }
/** /**
@@ -357,7 +357,7 @@ class HtmlBuilder
{ {
$html = ''; $html = '';
if (count($list) == 0) { if (count($list) === 0) {
return $html; return $html;
} }
@@ -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) . '</li>'; return '<li>' . e($value, false) . '</li>';
} }
} }
@@ -451,12 +451,12 @@ class HtmlBuilder
} }
// Treat boolean attributes as HTML properties // Treat boolean attributes as HTML properties
if (is_bool($value) && $key != 'value') { if (is_bool($value) && $key !== 'value') {
return $value ? $key : ''; return $value ? $key : '';
} }
if (! is_null($value)) { if (! is_null($value)) {
return $key . '="' . e($value) . '"'; return $key . '="' . e($value, false) . '"';
} }
} }
@@ -511,7 +511,7 @@ class HtmlBuilder
$attributes = array_merge($defaults, $attributes); $attributes = array_merge($defaults, $attributes);
return $this->toHtmlString('<meta' . $this->attributes($attributes) . '>' . PHP_EOL); return $this->toHtmlString('<meta' . $this->attributes($attributes) . '>');
} }
/** /**
@@ -525,8 +525,8 @@ class HtmlBuilder
*/ */
public function tag($tag, $content, array $attributes = []) public function tag($tag, $content, array $attributes = [])
{ {
$content = is_array($content) ? implode(PHP_EOL, $content) : $content; $content = is_array($content) ? implode('', $content) : $content;
return $this->toHtmlString('<' . $tag . $this->attributes($attributes) . '>' . PHP_EOL . $this->toHtmlString($content) . PHP_EOL . '</' . $tag . '>' . PHP_EOL); return $this->toHtmlString('<' . $tag . $this->attributes($attributes) . '>' . $this->toHtmlString($content) . '</' . $tag . '>');
} }
/** /**
+21
View File
@@ -42,10 +42,16 @@ 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()
@@ -159,3 +165,18 @@ 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;
}
}
+34 -3
View File
@@ -402,6 +402,37 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
'<select class="class-name" id="select-id" name="size"><optgroup label="Large sizes"><option value="L">Large</option><option value="XL">Extra Large</option></optgroup><option value="S">Small</option></select>' '<select class="class-name" id="select-id" name="size"><optgroup label="Large sizes"><option value="L">Large</option><option value="XL">Extra Large</option></optgroup><option value="S">Small</option></select>'
); );
$select = $this->formBuilder->select(
'size',
[
'Large sizes' => [
'L' => 'Large',
'XL' => 'Extra Large',
],
'M' => 'Medium',
'Small sizes' => [
'S' => 'Small',
'XS' => 'Extra Small',
],
],
null,
[],
[
'Large sizes' => [
'L' => ['disabled']
],
'M' => ['disabled'],
],
[
'Small sizes' => ['disabled'],
]
);
$this->assertEquals(
$select,
'<select name="size"><optgroup label="Large sizes"><option value="L" disabled>Large</option><option value="XL">Extra Large</option></optgroup><option value="M" disabled>Medium</option><optgroup label="Small sizes" disabled><option value="S">Small</option><option value="XS">Extra Small</option></optgroup></select>'
);
$select = $this->formBuilder->select( $select = $this->formBuilder->select(
'encoded_html', 'encoded_html',
['no_break_space' => '&nbsp;', 'ampersand' => '&amp;', 'lower_than' => '&lt;'], ['no_break_space' => '&nbsp;', 'ampersand' => '&amp;', 'lower_than' => '&lt;'],
@@ -479,7 +510,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select One...'] ['placeholder' => 'Select One...']
); );
$this->assertEquals($select, $this->assertEquals($select,
'<select name="size"><option selected="selected" value="">Select One...</option><option value="L">Large</option><option value="S">Small</option></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 = $this->formBuilder->select( $select = $this->formBuilder->select(
'size', 'size',
@@ -488,7 +519,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select One...'] ['placeholder' => 'Select One...']
); );
$this->assertEquals($select, $this->assertEquals($select,
'<select name="size"><option value="">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></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 = $this->formBuilder->select( $select = $this->formBuilder->select(
'encoded_html', 'encoded_html',
@@ -497,7 +528,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select the &nbsp;'] ['placeholder' => 'Select the &nbsp;']
); );
$this->assertEquals($select, $this->assertEquals($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>' '<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>'
); );
} }
+10 -7
View File
@@ -65,7 +65,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
{ {
$result = $this->htmlBuilder->meta('description', 'Lorem ipsum dolor sit amet.'); $result = $this->htmlBuilder->meta('description', 'Lorem ipsum dolor sit amet.');
$this->assertEquals('<meta name="description" content="Lorem ipsum dolor sit amet.">' . PHP_EOL, $result); $this->assertEquals('<meta name="description" content="Lorem ipsum dolor sit amet.">', $result);
} }
public function testTag() public function testTag()
@@ -83,17 +83,17 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$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>Lorem ipsum dolor sit amet.</p>', $result1);
$this->assertEquals('<p class="text-center">' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '</p>' . PHP_EOL, $result2); $this->assertEquals('<p class="text-center">Lorem ipsum dolor sit amet.</p>', $result2);
$this->assertEquals('<div class="row">' . PHP_EOL . '<p>Lorem ipsum dolor sit amet.</p>' . PHP_EOL . '</div>' . PHP_EOL, $result3); $this->assertEquals('<div class="row"><p>Lorem ipsum dolor sit amet.</p></div>', $result3);
$this->assertEquals('<div class="row">' . PHP_EOL . '<img src="http://example.com/image1">' . PHP_EOL . '<img src="http://example.com/image2">' . PHP_EOL . '</div>' . PHP_EOL, $result4); $this->assertEquals('<div class="row"><img src="http://example.com/image1"><img src="http://example.com/image2"></div>', $result4);
} }
public function testMetaOpenGraph() public function testMetaOpenGraph()
{ {
$result = $this->htmlBuilder->meta(null, 'website', ['property' => 'og:type']); $result = $this->htmlBuilder->meta(null, 'website', ['property' => 'og:type']);
$this->assertEquals('<meta content="website" property="og:type">' . PHP_EOL, $result); $this->assertEquals('<meta content="website" property="og:type">', $result);
} }
public function testFavicon() public function testFavicon()
@@ -102,7 +102,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$target = $this->urlGenerator->to('bar.ico'); $target = $this->urlGenerator->to('bar.ico');
$result = $this->htmlBuilder->favicon('http://foo.com/bar.ico'); $result = $this->htmlBuilder->favicon('http://foo.com/bar.ico');
$this->assertEquals('<link rel="shortcut icon" type="image/x-icon" href="' . $target . '">' . PHP_EOL, $result); $this->assertEquals('<link rel="shortcut icon" type="image/x-icon" href="' . $target . '">', $result);
} }
public function testComponentRegistration() public function testComponentRegistration()
@@ -118,8 +118,11 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$result2 = $this->htmlBuilder->link("http://www.example.com", "<span>Example.com</span>", ["class" => "example-link"], null, false); $result2 = $this->htmlBuilder->link("http://www.example.com", "<span>Example.com</span>", ["class" => "example-link"], null, false);
$result3 = $this->htmlBuilder->link("https://a.com/b?id=4&not_id=5", "URL which needs escaping");
$this->assertEquals('<a href="http://www.example.com" class="example-link">&lt;span&gt;Example.com&lt;/span&gt;</a>', $result1); $this->assertEquals('<a href="http://www.example.com" class="example-link">&lt;span&gt;Example.com&lt;/span&gt;</a>', $result1);
$this->assertEquals('<a href="http://www.example.com" class="example-link"><span>Example.com</span></a>', $result2); $this->assertEquals('<a href="http://www.example.com" class="example-link"><span>Example.com</span></a>', $result2);
$this->assertEquals('<a href="https://a.com/b?id=4&amp;not_id=5">URL which needs escaping</a>', $result3);
} }
public function testMailto() public function testMailto()