Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68caec9e82 | ||
|
|
ed7cbf7824 | ||
|
|
327cff9376 | ||
|
|
4f3ba9fac1 | ||
|
|
a89479d89b | ||
|
|
b299ad2c41 | ||
|
|
050af9862b | ||
|
|
360cb180f7 |
No files matched your search
+8
-8
@@ -19,16 +19,16 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.1.3",
|
"php": ">=7.1.3",
|
||||||
"illuminate/http": "5.6.*",
|
"illuminate/http": "5.7.*",
|
||||||
"illuminate/routing": "5.6.*",
|
"illuminate/routing": "5.7.*",
|
||||||
"illuminate/session": "5.6.*",
|
"illuminate/session": "5.7.*",
|
||||||
"illuminate/support": "5.6.*",
|
"illuminate/support": "5.7.*",
|
||||||
"illuminate/view": "5.6.*"
|
"illuminate/view": "5.7.*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"illuminate/database": "5.6.*",
|
"illuminate/database": "5.7.*",
|
||||||
"mockery/mockery": "~1.0",
|
"mockery/mockery": "~1.0",
|
||||||
"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.7-dev"
|
||||||
},
|
},
|
||||||
"laravel": {
|
"laravel": {
|
||||||
"providers": [
|
"providers": [
|
||||||
|
|||||||
+102
-18
@@ -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.
|
||||||
*
|
*
|
||||||
@@ -329,6 +329,20 @@ class FormBuilder
|
|||||||
return $this->input('password', $name, '', $options);
|
return $this->input('password', $name, '', $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a range input field.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\HtmlString
|
||||||
|
*/
|
||||||
|
public function range($name, $value = null, $options = [])
|
||||||
|
{
|
||||||
|
return $this->input('range', $name, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a hidden input field.
|
* Create a hidden input field.
|
||||||
*
|
*
|
||||||
@@ -464,6 +478,10 @@ class FormBuilder
|
|||||||
*/
|
*/
|
||||||
public function time($name, $value = null, $options = [])
|
public function time($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
|
if ($value instanceof DateTime) {
|
||||||
|
$value = $value->format('H:i');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->input('time', $name, $value, $options);
|
return $this->input('time', $name, $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,6 +499,24 @@ class FormBuilder
|
|||||||
return $this->input('url', $name, $value, $options);
|
return $this->input('url', $name, $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a week input field.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\HtmlString
|
||||||
|
*/
|
||||||
|
public function week($name, $value = null, $options = [])
|
||||||
|
{
|
||||||
|
if ($value instanceof DateTime) {
|
||||||
|
$value = $value->format('Y-\WW');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->input('week', $name, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a file input field.
|
* Create a file input field.
|
||||||
*
|
*
|
||||||
@@ -769,7 +805,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) . ' hidden="hidden">' . e($display, false) . '</option>');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -871,7 +907,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 +960,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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -982,6 +1004,24 @@ class FormBuilder
|
|||||||
return $this->input('image', $name, null, $attributes);
|
return $this->input('image', $name, null, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a month input field.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\HtmlString
|
||||||
|
*/
|
||||||
|
public function month($name, $value = null, $options = [])
|
||||||
|
{
|
||||||
|
if ($value instanceof DateTime) {
|
||||||
|
$value = $value->format('Y-m');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->input('month', $name, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a color input field.
|
* Create a color input field.
|
||||||
*
|
*
|
||||||
@@ -1026,6 +1066,50 @@ class FormBuilder
|
|||||||
return $this->toHtmlString('<button' . $this->html->attributes($options) . '>' . $value . '</button>');
|
return $this->toHtmlString('<button' . $this->html->attributes($options) . '>' . $value . '</button>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a datalist box field.
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param array $list
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\HtmlString
|
||||||
|
*/
|
||||||
|
public function datalist($id, $list = [])
|
||||||
|
{
|
||||||
|
$this->type = 'datalist';
|
||||||
|
|
||||||
|
$attributes['id'] = $id;
|
||||||
|
|
||||||
|
$html = [];
|
||||||
|
|
||||||
|
if ($this->isAssociativeArray($list)) {
|
||||||
|
foreach ($list as $value => $display) {
|
||||||
|
$html[] = $this->option($display, $value, null, []);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($list as $value) {
|
||||||
|
$html[] = $this->option($value, $value, null, []);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$attributes = $this->html->attributes($attributes);
|
||||||
|
|
||||||
|
$list = implode('', $html);
|
||||||
|
|
||||||
|
return $this->toHtmlString("<datalist{$attributes}>{$list}</datalist>");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if an array is associative.
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isAssociativeArray($array)
|
||||||
|
{
|
||||||
|
return (array_values($array) !== $array);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the form action method.
|
* Parse the form action method.
|
||||||
*
|
*
|
||||||
|
|||||||
+1
-1
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
{
|
{
|
||||||
@@ -74,12 +74,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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+69
-20
@@ -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
|
||||||
@@ -229,6 +229,17 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="password" value="">', $form2);
|
$this->assertEquals('<input class="span2" name="foo" type="password" value="">', $form2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormRange()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->range('foo');
|
||||||
|
$form2 = $this->formBuilder->range('foo', 1);
|
||||||
|
$form3 = $this->formBuilder->range('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="range">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="range" value="1">', $form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="range">', $form3);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormHidden()
|
public function testFormHidden()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->hidden('foo');
|
$form1 = $this->formBuilder->hidden('foo');
|
||||||
@@ -240,6 +251,18 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="hidden">', $form3);
|
$this->assertEquals('<input class="span2" name="foo" type="hidden">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormMonth()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->month('foo');
|
||||||
|
$form2 = $this->formBuilder->month('foo', \Carbon\Carbon::now());
|
||||||
|
$form3 = $this->formBuilder->month('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="month">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="month" value="' . \Carbon\Carbon::now()->format('Y-m') . '">',
|
||||||
|
$form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="month">', $form3);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormSearch()
|
public function testFormSearch()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->search('foo');
|
$form1 = $this->formBuilder->search('foo');
|
||||||
@@ -310,6 +333,29 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="time">', $form3);
|
$this->assertEquals('<input class="span2" name="foo" type="time">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormUrl()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->url('foo');
|
||||||
|
$form2 = $this->formBuilder->url('foo', 'http://foobar.com');
|
||||||
|
$form3 = $this->formBuilder->url('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="url">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="url" value="http://foobar.com">', $form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="url">', $form3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormWeek()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->week('foo');
|
||||||
|
$form2 = $this->formBuilder->week('foo', \Carbon\Carbon::now());
|
||||||
|
$form3 = $this->formBuilder->week('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="week">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="week" value="' . \Carbon\Carbon::now()->format('Y-\WW') . '">',
|
||||||
|
$form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="week">', $form3);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormFile()
|
public function testFormFile()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->file('foo');
|
$form1 = $this->formBuilder->file('foo');
|
||||||
@@ -467,7 +513,7 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$select = $this->formBuilder->select('avc', [1 => 'Yes', 0 => 'No'], true, ['placeholder' => 'Select']);
|
$select = $this->formBuilder->select('avc', [1 => 'Yes', 0 => 'No'], true, ['placeholder' => 'Select']);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'<select name="avc"><option value="">Select</option><option value="1" selected>Yes</option><option value="0" >No</option></select>',
|
'<select name="avc"><option value="" hidden="hidden">Select</option><option value="1" selected>Yes</option><option value="0" >No</option></select>',
|
||||||
$select
|
$select
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -516,7 +562,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',
|
||||||
@@ -525,7 +571,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',
|
||||||
@@ -534,7 +580,7 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase
|
|||||||
['placeholder' => 'Select the ']
|
['placeholder' => 'Select the ']
|
||||||
);
|
);
|
||||||
$this->assertEquals($select,
|
$this->assertEquals($select,
|
||||||
'<select name="encoded_html"><option selected="selected" value="">Select the </option><option value="no_break_space"> </option><option value="ampersand">&</option><option value="lower_than"><</option></select>'
|
'<select name="encoded_html"><option selected="selected" value="" hidden="hidden">Select the </option><option value="no_break_space"> </option><option value="ampersand">&</option><option value="lower_than"><</option></select>'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,21 +704,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'));
|
||||||
@@ -729,6 +760,24 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="color">', $form3);
|
$this->assertEquals('<input class="span2" name="foo" type="color">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDatalist()
|
||||||
|
{
|
||||||
|
// Associative array with string keys.
|
||||||
|
$genders = ['M' => 'Male', 'F' => 'Female'];
|
||||||
|
$datalist = $this->formBuilder->datalist('genders', $genders);
|
||||||
|
$this->assertEquals('<datalist id="genders"><option value="M">Male</option><option value="F">Female</option></datalist>', $datalist);
|
||||||
|
|
||||||
|
// Associative array with numeric Keys
|
||||||
|
$genders = [5 => 'Male', 6 => 'Female'];
|
||||||
|
$datalist = $this->formBuilder->datalist('genders', $genders);
|
||||||
|
$this->assertEquals('<datalist id="genders"><option value="5">Male</option><option value="6">Female</option></datalist>', $datalist);
|
||||||
|
|
||||||
|
// Not associative array.
|
||||||
|
$genders = ['Male', 'Female'];
|
||||||
|
$datalist = $this->formBuilder->datalist('genders', $genders);
|
||||||
|
$this->assertEquals('<datalist id="genders"><option value="Male">Male</option><option value="Female">Female</option></datalist>', $datalist);
|
||||||
|
}
|
||||||
|
|
||||||
public function testBooleanAttributes()
|
public function testBooleanAttributes()
|
||||||
{
|
{
|
||||||
$input = $this->formBuilder->text('test', null, ['disabled']);
|
$input = $this->formBuilder->text('test', null, ['disabled']);
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user