Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3a10245c7 | ||
|
|
623a150c91 | ||
|
|
5060a6641d | ||
|
|
41cd9291a6 | ||
|
|
818efc2e16 | ||
|
|
e6496328af | ||
|
|
137a2efcf1 | ||
|
|
32c27a54cd | ||
|
|
f9deb1da6f | ||
|
|
5feb06537d | ||
|
|
e1318fcfdd | ||
|
|
cecb65626c | ||
|
|
2c5db92f66 | ||
|
|
7e49960e8f | ||
|
|
f3b55c6033 | ||
|
|
a5f7464ee6 | ||
|
|
cd71ed1538 | ||
|
|
e2fcbee917 | ||
|
|
2dfc110b6c | ||
|
|
8997f1209d | ||
|
|
ac46825a97 | ||
|
|
33dd7bb48e | ||
|
|
779d075f79 | ||
|
|
29253c13a3 | ||
|
|
d621ce1357 | ||
|
|
9e2a40555a | ||
|
|
8f7bc4d097 | ||
|
|
cf13e067eb | ||
|
|
b39f510897 | ||
|
|
b4c0a3e26d | ||
|
|
e6bc7e5fea | ||
|
|
1810274c8a | ||
|
|
f380cdc14d | ||
|
|
0ac9642ebb | ||
|
|
2f6dc39ab3 | ||
|
|
422ba2ea8d | ||
|
|
b9322c703d | ||
|
|
e3d9fe169d | ||
|
|
06d4296d18 | ||
|
|
97fa90bf64 | ||
|
|
79f59a016c | ||
|
|
3841eb8c89 | ||
|
|
adf0d91e2c | ||
|
|
3688b0e433 | ||
|
|
b91158bae5 | ||
|
|
471a0aa5e4 | ||
|
|
291da712f4 | ||
|
|
a47a02b962 | ||
|
|
d7aba64b44 | ||
|
|
e6471f3be1 |
No files matched your search
+1
-2
@@ -1,9 +1,8 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
|
||||
sudo: false
|
||||
|
||||
|
||||
+53
-37
@@ -1,41 +1,57 @@
|
||||
{
|
||||
"name": "laravelcollective/html",
|
||||
"description": "HTML and Form Builders for the Laravel Framework",
|
||||
"license": "MIT",
|
||||
"homepage": "http://laravelcollective.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/LaravelCollective/html/issues",
|
||||
"source": "https://github.com/LaravelCollective/html"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Adam Engebretson",
|
||||
"email": "adam@laravelcollective.com"
|
||||
"name": "laravelcollective/html",
|
||||
"description": "HTML and Form Builders for the Laravel Framework",
|
||||
"license": "MIT",
|
||||
"homepage": "https://laravelcollective.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/LaravelCollective/html/issues",
|
||||
"source": "https://github.com/LaravelCollective/html"
|
||||
},
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.6.4",
|
||||
"illuminate/http": "5.4.*",
|
||||
"illuminate/routing": "5.4.*",
|
||||
"illuminate/session": "5.4.*",
|
||||
"illuminate/support": "5.4.*",
|
||||
"illuminate/view": "5.4.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/database": "5.4.*",
|
||||
"mockery/mockery": "~0.9.4",
|
||||
"phpunit/phpunit": "~5.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Collective\\Html\\": "src/"
|
||||
"authors": [
|
||||
{
|
||||
"name": "Adam Engebretson",
|
||||
"email": "adam@laravelcollective.com"
|
||||
},
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.3",
|
||||
"illuminate/http": "5.6.*",
|
||||
"illuminate/routing": "5.6.*",
|
||||
"illuminate/session": "5.6.*",
|
||||
"illuminate/support": "5.6.*",
|
||||
"illuminate/view": "5.6.*"
|
||||
},
|
||||
"files": [
|
||||
"src/helpers.php"
|
||||
]
|
||||
}
|
||||
"require-dev": {
|
||||
"illuminate/database": "5.6.*",
|
||||
"mockery/mockery": "~1.0",
|
||||
"phpunit/phpunit": "~5.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Collective\\Html\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"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
|
||||
}
|
||||
@@ -49,11 +49,11 @@ trait FormAccessible
|
||||
unset($keys[0]);
|
||||
$key = implode('.', $keys);
|
||||
|
||||
if ($this->hasFormMutator($key)) {
|
||||
if (method_exists($relatedModel, 'hasFormMutator') && $key !== '' && $relatedModel->hasFormMutator($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
|
||||
@@ -81,13 +81,13 @@ trait FormAccessible
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasFormMutator($key)
|
||||
public function hasFormMutator($key)
|
||||
{
|
||||
$methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
|
||||
$mutator = collect($methods)
|
||||
->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;
|
||||
|
||||
+71
-30
@@ -191,6 +191,16 @@ class FormBuilder
|
||||
$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.
|
||||
*
|
||||
@@ -517,7 +527,7 @@ class FormBuilder
|
||||
// the element. Then we'll create the final textarea elements HTML for us.
|
||||
$options = $this->html->attributes($options);
|
||||
|
||||
return $this->toHtmlString('<textarea' . $options . '>' . e($value). '</textarea>');
|
||||
return $this->toHtmlString('<textarea' . $options . '>' . e($value, false). '</textarea>');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,9 +572,10 @@ class FormBuilder
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $list
|
||||
* @param string $selected
|
||||
* @param string|bool $selected
|
||||
* @param array $selectAttributes
|
||||
* @param array $optionsAttributes
|
||||
* @param array $optgroupsAttributes
|
||||
*
|
||||
* @return \Illuminate\Support\HtmlString
|
||||
*/
|
||||
@@ -573,7 +584,8 @@ class FormBuilder
|
||||
$list = [],
|
||||
$selected = null,
|
||||
array $selectAttributes = [],
|
||||
array $optionsAttributes = []
|
||||
array $optionsAttributes = [],
|
||||
array $optgroupsAttributes = []
|
||||
) {
|
||||
$this->type = 'select';
|
||||
|
||||
@@ -599,8 +611,9 @@ class FormBuilder
|
||||
}
|
||||
|
||||
foreach ($list as $value => $display) {
|
||||
$optionAttributes = isset($optionsAttributes[$value]) ? $optionsAttributes[$value] : [];
|
||||
$html[] = $this->getSelectOption($display, $value, $selected, $optionAttributes);
|
||||
$optionAttributes = $optionsAttributes[$value] ?? [];
|
||||
$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
|
||||
@@ -675,13 +688,14 @@ class FormBuilder
|
||||
* @param string $value
|
||||
* @param string $selected
|
||||
* @param array $attributes
|
||||
* @param array $optgroupAttributes
|
||||
*
|
||||
* @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)) {
|
||||
return $this->optionGroup($display, $value, $selected, $attributes);
|
||||
return $this->optionGroup($display, $value, $selected, $optgroupAttributes, $attributes);
|
||||
}
|
||||
|
||||
return $this->option($display, $value, $selected, $attributes);
|
||||
@@ -694,18 +708,24 @@ class FormBuilder
|
||||
* @param string $label
|
||||
* @param string $selected
|
||||
* @param array $attributes
|
||||
* @param array $optionsAttributes
|
||||
* @param integer $level
|
||||
*
|
||||
* @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 = [];
|
||||
|
||||
$space = str_repeat(" ", $level);
|
||||
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);
|
||||
|
||||
$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' => '',
|
||||
];
|
||||
|
||||
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display) . '</option>');
|
||||
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display, false) . '</option>');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -762,8 +787,10 @@ class FormBuilder
|
||||
} elseif ($selected instanceof Collection) {
|
||||
return $selected->contains($value) ? 'selected' : null;
|
||||
}
|
||||
|
||||
return ((string) $value == (string) $selected) ? 'selected' : null;
|
||||
if (is_int($value) && is_bool($selected)) {
|
||||
return (bool)$value === $selected;
|
||||
}
|
||||
return ((string) $value === (string) $selected) ? 'selected' : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -844,7 +871,7 @@ class FormBuilder
|
||||
return $this->getRadioCheckedState($name, $value, $checked);
|
||||
|
||||
default:
|
||||
return $this->getValueAttribute($name) == $value;
|
||||
return $this->compareValues($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,7 +892,7 @@ class FormBuilder
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->missingOldAndModel($name) && !$request) {
|
||||
if ($this->missingOldAndModel($name) && is_null($request)) {
|
||||
return $checked;
|
||||
}
|
||||
|
||||
@@ -897,6 +924,20 @@ class FormBuilder
|
||||
return $checked;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -996,7 +1037,7 @@ class FormBuilder
|
||||
{
|
||||
$method = strtoupper($method);
|
||||
|
||||
return $method != 'GET' ? 'POST' : $method;
|
||||
return $method !== 'GET' ? 'POST' : $method;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1098,7 +1139,7 @@ class FormBuilder
|
||||
// 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
|
||||
// always have available on every form the developers creates for them.
|
||||
if ($method != 'GET') {
|
||||
if ($method !== 'GET') {
|
||||
$appendage .= $this->token();
|
||||
}
|
||||
|
||||
@@ -1140,7 +1181,7 @@ class FormBuilder
|
||||
|
||||
$old = $this->old($name);
|
||||
|
||||
if (! is_null($old) && $name != '_method') {
|
||||
if (! is_null($old) && $name !== '_method') {
|
||||
return $old;
|
||||
}
|
||||
|
||||
@@ -1151,7 +1192,7 @@ class FormBuilder
|
||||
if ($hasNullMiddleware
|
||||
&& is_null($old)
|
||||
&& is_null($value)
|
||||
&& !is_null($this->view->shared('errors'))
|
||||
&& ! is_null($this->view->shared('errors'))
|
||||
&& count($this->view->shared('errors')) > 0
|
||||
) {
|
||||
return null;
|
||||
@@ -1159,7 +1200,7 @@ class FormBuilder
|
||||
}
|
||||
|
||||
$request = $this->request($name);
|
||||
if (!is_null($request)) {
|
||||
if (! is_null($request) && $name != '_method') {
|
||||
return $request;
|
||||
}
|
||||
|
||||
@@ -1179,7 +1220,7 @@ class FormBuilder
|
||||
*/
|
||||
protected function request($name)
|
||||
{
|
||||
if (!isset($this->request)) {
|
||||
if (! isset($this->request)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1217,16 +1258,16 @@ class FormBuilder
|
||||
$key = $this->transformKey($name);
|
||||
$payload = $this->session->getOldInput($key);
|
||||
|
||||
if (!is_array($payload)) {
|
||||
if (! is_array($payload)) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
if (!in_array($this->type, ['select', 'checkbox'])) {
|
||||
if (!isset($this->payload[$key])) {
|
||||
if (! in_array($this->type, ['select', 'checkbox'])) {
|
||||
if (! isset($this->payload[$key])) {
|
||||
$this->payload[$key] = collect($payload);
|
||||
}
|
||||
|
||||
if (!empty($this->payload[$key])) {
|
||||
if (! empty($this->payload[$key])) {
|
||||
$value = $this->payload[$key]->shift();
|
||||
return $value;
|
||||
}
|
||||
@@ -1243,7 +1284,7 @@ class FormBuilder
|
||||
*/
|
||||
public function oldInputIsEmpty()
|
||||
{
|
||||
return (isset($this->session) && count($this->session->getOldInput()) == 0);
|
||||
return (isset($this->session) && count((array) $this->session->getOldInput()) === 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+13
-13
@@ -78,7 +78,7 @@ class HtmlBuilder
|
||||
{
|
||||
$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'];
|
||||
|
||||
$attributes = $attributes + $defaults;
|
||||
$attributes = array_merge($defaults, $attributes);
|
||||
|
||||
$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'];
|
||||
|
||||
$attributes = $attributes + $defaults;
|
||||
$attributes = array_merge($attributes, $defaults);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
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 = '';
|
||||
|
||||
if (count($list) == 0) {
|
||||
if (count($list) === 0) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ class HtmlBuilder
|
||||
if (is_array($value)) {
|
||||
return $this->nestedListing($key, $type, $value);
|
||||
} else {
|
||||
return '<li>' . e($value) . '</li>';
|
||||
return '<li>' . e($value, false) . '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,12 +451,12 @@ class HtmlBuilder
|
||||
}
|
||||
|
||||
// Treat boolean attributes as HTML properties
|
||||
if (is_bool($value) && $key != 'value') {
|
||||
if (is_bool($value) && $key !== 'value') {
|
||||
return $value ? $key : '';
|
||||
}
|
||||
|
||||
if (! is_null($value)) {
|
||||
return $key . '="' . e($value) . '"';
|
||||
return $key . '="' . e($value, false) . '"';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +511,7 @@ class HtmlBuilder
|
||||
|
||||
$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 = [])
|
||||
{
|
||||
$content = is_array($content) ? implode(PHP_EOL, $content) : $content;
|
||||
return $this->toHtmlString('<' . $tag . $this->attributes($attributes) . '>' . PHP_EOL . $this->toHtmlString($content) . PHP_EOL . '</' . $tag . '>' . PHP_EOL);
|
||||
$content = is_array($content) ? implode('', $content) : $content;
|
||||
return $this->toHtmlString('<' . $tag . $this->attributes($attributes) . '>' . $this->toHtmlString($content) . '</' . $tag . '>');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,10 +42,16 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase
|
||||
public function testItCanMutateValuesForForms()
|
||||
{
|
||||
$model = new ModelThatUsesForms($this->modelData);
|
||||
$user = new User(['name' => 'Anton']);
|
||||
$model->setRelation('user', $user);
|
||||
$this->formBuilder->setModel($model);
|
||||
|
||||
$this->assertEquals($model->getFormValue('string'), 'ponmlkjihgfedcba');
|
||||
$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()
|
||||
@@ -159,3 +165,18 @@ class ModelThatDoesntUseForms extends Model
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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 = $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(
|
||||
'encoded_html',
|
||||
['no_break_space' => ' ', 'ampersand' => '&', 'lower_than' => '<'],
|
||||
@@ -433,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()
|
||||
@@ -621,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'));
|
||||
|
||||
@@ -65,7 +65,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$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()
|
||||
@@ -83,17 +83,17 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$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 class="text-center">' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '</p>' . PHP_EOL, $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">' . PHP_EOL . '<img src="http://example.com/image1">' . PHP_EOL . '<img src="http://example.com/image2">' . PHP_EOL . '</div>' . PHP_EOL, $result4);
|
||||
$this->assertEquals('<p>Lorem ipsum dolor sit amet.</p>', $result1);
|
||||
$this->assertEquals('<p class="text-center">Lorem ipsum dolor sit amet.</p>', $result2);
|
||||
$this->assertEquals('<div class="row"><p>Lorem ipsum dolor sit amet.</p></div>', $result3);
|
||||
$this->assertEquals('<div class="row"><img src="http://example.com/image1"><img src="http://example.com/image2"></div>', $result4);
|
||||
}
|
||||
|
||||
public function testMetaOpenGraph()
|
||||
{
|
||||
$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()
|
||||
@@ -102,7 +102,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
|
||||
$target = $this->urlGenerator->to('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()
|
||||
@@ -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);
|
||||
|
||||
$result3 = $this->htmlBuilder->link("https://a.com/b?id=4¬_id=5", "URL which needs escaping");
|
||||
|
||||
$this->assertEquals('<a href="http://www.example.com" class="example-link"><span>Example.com</span></a>', $result1);
|
||||
$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&not_id=5">URL which needs escaping</a>', $result3);
|
||||
}
|
||||
|
||||
public function testMailto()
|
||||
|
||||
Reference in new issue
Block a user