From c7473787ecb7b422696ac203da155e58a499b767 Mon Sep 17 00:00:00 2001 From: Thach Nguyen Date: Sat, 24 Feb 2018 04:59:26 +0700 Subject: [PATCH] Make source code compatible with PHP 5.3 / Laravel 4.0 --- .travis.yml | 15 +- composer.json | 8 +- src/Bllim/Laravalid/FormBuilder.php | 6 +- .../Laravalid/LaravalidServiceProvider.php | 10 +- .../Laravalid/converter/Base/Container.php | 6 +- .../Laravalid/converter/Base/Converter.php | 22 +-- .../Laravalid/converter/Base/Message.php | 4 +- src/Bllim/Laravalid/converter/Base/Route.php | 8 +- .../converter/JqueryValidation/Message.php | 48 ++--- .../converter/JqueryValidation/Rule.php | 52 ++--- src/config/config.php | 4 +- tests/Bllim/Laravalid/FormBuilderTest.php | 58 +++--- tests/Bllim/Laravalid/ServiceProviderTest.php | 29 ++- .../Laravalid/converter/ConverterTest.php | 184 +++++++++--------- .../Bllim/Laravalid/converter/MessageTest.php | 92 ++++----- tests/Bllim/Laravalid/converter/RouteTest.php | 34 ++-- tests/Bllim/Laravalid/converter/RuleTest.php | 176 ++++++++--------- 17 files changed, 386 insertions(+), 370 deletions(-) diff --git a/.travis.yml b/.travis.yml index f60bbe0..cb469fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,21 @@ php: - 5.6 - hhvm +matrix: + include: + - php: 5.3 + dist: precise + allow_failures: + - php: hhvm + fast_finish: true + +cache: + directories: + - vendor + - $HOME/.composer/cache + before_script: - travis_retry composer self-update - - travis_retry composer install --prefer-source --no-interaction --dev + - travis_retry composer install --no-interaction --no-progress script: phpunit diff --git a/composer.json b/composer.json index 080a6c8..ac82e0d 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,10 @@ } ], "require": { - "php": ">=5.4.0", - "illuminate/config": "~4.2", - "illuminate/html": "~4.2", - "illuminate/support": "~4.2", + "php": ">=5.3.0", + "illuminate/config": "~4.0", + "illuminate/html": "~4.0", + "illuminate/support": "~4.0", "illuminate/validation": "~4.0", "illuminate/routing": "~4.0", "illuminate/translation": "~4.0" diff --git a/src/Bllim/Laravalid/FormBuilder.php b/src/Bllim/Laravalid/FormBuilder.php index da82b30..019ea71 100644 --- a/src/Bllim/Laravalid/FormBuilder.php +++ b/src/Bllim/Laravalid/FormBuilder.php @@ -88,7 +88,7 @@ public function model($model, array $options = array(), $rules = null) /** * {@inheritdoc} */ - public function input($type, $name, $value = null, $options = []) + public function input($type, $name, $value = null, $options = array()) { $options += $this->getValidationAttributes($name, $type); return parent::input($type, $name, $value, $options); @@ -97,7 +97,7 @@ public function input($type, $name, $value = null, $options = []) /** * {@inheritdoc} */ - public function textarea($name, $value = null, $options = []) + public function textarea($name, $value = null, $options = array()) { $options += $this->getValidationAttributes($name); return parent::textarea($name, $value, $options); @@ -106,7 +106,7 @@ public function textarea($name, $value = null, $options = []) /** * {@inheritdoc} */ - public function select($name, $list = [], $selected = null, $options = []) + public function select($name, $list = array(), $selected = null, $options = array()) { $options += $this->getValidationAttributes($name); return parent::select($name, $list, $selected, $options); diff --git a/src/Bllim/Laravalid/LaravalidServiceProvider.php b/src/Bllim/Laravalid/LaravalidServiceProvider.php index 709a65c..aed4555 100644 --- a/src/Bllim/Laravalid/LaravalidServiceProvider.php +++ b/src/Bllim/Laravalid/LaravalidServiceProvider.php @@ -24,7 +24,7 @@ public function boot() $routeName = $app['config']->get('laravalid::route', 'laravalid'); $app['router']->any($routeName . '/{rule}', function ($rule) use ($app) { - return $app['laravalid']->converter()->route()->convert($rule, [$app['request']->all()]); + return $app['laravalid']->converter()->route()->convert($rule, array($app['request']->all())); })->where('rule', '[\w-]+'); } @@ -35,14 +35,14 @@ public function register() { // try to register the HTML builder instance if (!$this->app->bound('html')) { - $this->app->bindShared('html', function($app) + $this->app->singleton('html', $this->app->share(function($app) { return new \Illuminate\Html\HtmlBuilder($app['url']); - }); + })); } // register the new form builder instance - $this->app->bindShared('laravalid', function ($app) { + $this->app->singleton('laravalid', $this->app->share(function ($app) { /* @var $app \Illuminate\Container\Container */ $plugin = $app['config']->get('laravalid::plugin'); $converterClass = (strpos($plugin, '\\') === false ? 'Bllim\Laravalid\Converter\\' : '') . $plugin . '\Converter'; @@ -52,7 +52,7 @@ public function register() $form = new FormBuilder($app['html'], $app['url'], $session->getToken(), new $converterClass($app)); return $form->setSessionStore($session); - }); + })); } /** diff --git a/src/Bllim/Laravalid/converter/Base/Container.php b/src/Bllim/Laravalid/converter/Base/Container.php index 098f006..92211bf 100644 --- a/src/Bllim/Laravalid/converter/Base/Container.php +++ b/src/Bllim/Laravalid/converter/Base/Container.php @@ -11,9 +11,9 @@ abstract class Container { - protected $customMethods = []; + protected $customMethods = array(); - public function convert($name, $parameters = []) + public function convert($name, $parameters = array()) { $methodName = strtolower($name); @@ -24,7 +24,7 @@ public function convert($name, $parameters = []) if (method_exists($this, $methodName)) { - return call_user_func_array([$this, $methodName], $parameters); + return call_user_func_array(array($this, $methodName), $parameters); } return null; diff --git a/src/Bllim/Laravalid/converter/Base/Converter.php b/src/Bllim/Laravalid/converter/Base/Converter.php index 942837e..eedcc92 100644 --- a/src/Bllim/Laravalid/converter/Base/Converter.php +++ b/src/Bllim/Laravalid/converter/Base/Converter.php @@ -37,29 +37,29 @@ abstract class Converter { * * @var array */ - protected $validationRules = []; + protected $validationRules = array(); - protected static $multiParamRules = [ + protected static $multiParamRules = array( 'between', 'digits_between', 'in', 'not_in', 'mimes', 'required_if', 'required_with', 'required_with_all', 'required_without', 'required_without_all', 'exists', 'unique', - ]; + ); /** * Rules which specify input type is file * * @var array */ - protected static $fileRules = ['image', 'mimes']; + protected static $fileRules = array('image', 'mimes'); /** * Rules which specify input type is numeric * * @var array */ - protected static $numericRules = ['integer', 'numeric', 'digits', 'digits_between']; + protected static $numericRules = array('integer', 'numeric', 'digits', 'digits_between'); /** * @var bool @@ -114,7 +114,7 @@ public function set($rules) */ public function reset() { - $this->validationRules = []; + $this->validationRules = array(); } /** @@ -154,18 +154,18 @@ protected function checkValidationRule($inputName) public function convert($inputName, $inputType = null) { if (!$this->checkValidationRule($inputName)) { - return []; + return array(); } $rules = $this->getValidationRule($inputName); $type = $this->getTypeOfInput($rules); - $outputAttributes = []; + $outputAttributes = array(); foreach ($rules as $rule) { $parsedRule = $this->parseValidationRule($rule); - $ruleAttributes = $this->rule()->convert($parsedRule['name'], [$parsedRule, $inputName, $type]); + $ruleAttributes = $this->rule()->convert($parsedRule['name'], array($parsedRule, $inputName, $type)); if (!empty($ruleAttributes)) { $outputAttributes = $this->rule()->mergeOutputAttributes($outputAttributes, $ruleAttributes, $inputType); @@ -174,7 +174,7 @@ public function convert($inputName, $inputType = null) if ($this->useLaravelMessages) { - $messageAttributes = $this->message()->convert($parsedRule['name'], [$parsedRule, $inputName, $type]); + $messageAttributes = $this->message()->convert($parsedRule['name'], array($parsedRule, $inputName, $type)); // if empty message attributes if (empty($messageAttributes) && !empty($ruleAttributes)) @@ -251,7 +251,7 @@ protected function getDefaultErrorMessage($laravelRule, $attribute) { // getting user friendly validation message $message = $this->message()->getValidationMessage($attribute, $laravelRule); - return ['data-msg-' . $laravelRule => $message]; + return array('data-msg-' . $laravelRule => $message); } } \ No newline at end of file diff --git a/src/Bllim/Laravalid/converter/Base/Message.php b/src/Bllim/Laravalid/converter/Base/Message.php index a1fc457..c1cc6dd 100644 --- a/src/Bllim/Laravalid/converter/Base/Message.php +++ b/src/Bllim/Laravalid/converter/Base/Message.php @@ -34,7 +34,7 @@ public function __construct($translator) * @return string * @see Illuminate\Validation\Validator::getMessage() */ - public function getValidationMessage($attribute, $rule, $data = [], $type = null) + public function getValidationMessage($attribute, $rule, $data = array(), $type = null) { $path = Str::snake($rule); if ($type !== null) @@ -49,7 +49,7 @@ public function getValidationMessage($attribute, $rule, $data = [], $type = null $niceName = $this->getValidationAttribute($attribute); - return $this->translator->get('validation.' . $path, $data + ['attribute' => $niceName]); + return $this->translator->get('validation.' . $path, $data + array('attribute' => $niceName)); } protected function getValidationAttribute($attribute) diff --git a/src/Bllim/Laravalid/converter/Base/Route.php b/src/Bllim/Laravalid/converter/Base/Route.php index a204753..05b3d2b 100644 --- a/src/Bllim/Laravalid/converter/Base/Route.php +++ b/src/Bllim/Laravalid/converter/Base/Route.php @@ -30,15 +30,15 @@ public function __construct($validatorFactory, $encrypter) $this->encrypter = $encrypter; } - public function convert($name, $parameters = []) + public function convert($name, $parameters = array()) { if (!is_null($result = parent::convert($name, $parameters))) return $result; - return $this->defaultRoute($name, reset($parameters) ?: []); + return $this->defaultRoute($name, reset($parameters) ?: array()); } - protected function defaultRoute($name, $parameters = []) + protected function defaultRoute($name, $parameters = array()) { $params = $this->decryptParameters($parameters); @@ -60,7 +60,7 @@ protected function defaultRoute($name, $parameters = []) protected function decryptParameters(array &$parameters) { - $params = empty($parameters['params']) ? [] + $params = empty($parameters['params']) ? array() : (is_array($parameters['params']) ? $parameters['params'] : array($parameters['params'])); unset($parameters['params'], $parameters['_']); diff --git a/src/Bllim/Laravalid/converter/JqueryValidation/Message.php b/src/Bllim/Laravalid/converter/JqueryValidation/Message.php index c84cc2e..f6c8d93 100644 --- a/src/Bllim/Laravalid/converter/JqueryValidation/Message.php +++ b/src/Bllim/Laravalid/converter/JqueryValidation/Message.php @@ -5,21 +5,21 @@ class Message extends \Bllim\Laravalid\Converter\Base\Message { public function ip($parsedRule, $attribute) { $message = $this->getValidationMessage($attribute, $parsedRule['name']); - return ['data-msg-ipv4' => $message]; + return array('data-msg-ipv4' => $message); } public function same($parsedRule, $attribute) { $other = $this->getValidationAttribute(reset($parsedRule['parameters'])); $message = $this->getValidationMessage($attribute, $parsedRule['name'], compact('other')); - return ['data-msg-equalto' => $message]; + return array('data-msg-equalto' => $message); } public function different($parsedRule, $attribute) { $other = $this->getValidationAttribute(reset($parsedRule['parameters'])); $message = $this->getValidationMessage($attribute, $parsedRule['name'], compact('other')); - return ['data-msg-notequalto' => $message]; + return array('data-msg-notequalto' => $message); } public function alpha($parsedRule, $attribute) @@ -35,71 +35,71 @@ public function alpha_num($parsedRule, $attribute) public function regex($parsedRule, $attribute) { $message = $this->getValidationMessage($attribute, $parsedRule['name']); - return ['data-msg-pattern' => $message]; + return array('data-msg-pattern' => $message); } public function image($parsedRule, $attribute) { $message = $this->getValidationMessage($attribute, $parsedRule['name']); - return ['data-msg-accept' => $message]; + return array('data-msg-accept' => $message); } public function before($parsedRule, $attribute) { - $message = $this->getValidationMessage($attribute, $parsedRule['name'], ['date' => '{0}']); - return ['data-msg-max' => $message]; + $message = $this->getValidationMessage($attribute, $parsedRule['name'], array('date' => '{0}')); + return array('data-msg-max' => $message); } public function after($parsedRule, $attribute) { - $message = $this->getValidationMessage($attribute, $parsedRule['name'], ['date' => '{0}']); - return ['data-msg-min' => $message]; + $message = $this->getValidationMessage($attribute, $parsedRule['name'], array('date' => '{0}')); + return array('data-msg-min' => $message); } public function numeric($parsedRule, $attribute) { $message = $this->getValidationMessage($attribute, $parsedRule['name']); - return ['data-msg-number' => $message]; + return array('data-msg-number' => $message); } public function max($parsedRule, $attribute, $type) { - $message = $this->getValidationMessage($attribute, $parsedRule['name'], ['max' => '{0}'], $type); + $message = $this->getValidationMessage($attribute, $parsedRule['name'], array('max' => '{0}'), $type); switch ($type) { case 'numeric': - return ['data-msg-max' => $message]; + return array('data-msg-max' => $message); break; default: - return ['data-msg-maxlength' => $message]; + return array('data-msg-maxlength' => $message); break; } } public function min($parsedRule, $attribute, $type) { - $message = $this->getValidationMessage($attribute, $parsedRule['name'], ['min' => '{0}'], $type); + $message = $this->getValidationMessage($attribute, $parsedRule['name'], array('min' => '{0}'), $type); switch ($type) { case 'numeric': - return ['data-msg-min' => $message]; + return array('data-msg-min' => $message); break; default: - return ['data-msg-minlength' => $message]; + return array('data-msg-minlength' => $message); break; } } public function between($parsedRule, $attribute, $type) { - $message = $this->getValidationMessage($attribute, $parsedRule['name'], ['min' => '{0}', 'max' => '{1}'], $type); + $message = $this->getValidationMessage($attribute, $parsedRule['name'], array('min' => '{0}', 'max' => '{1}'), $type); switch ($type) { case 'numeric': - return ['data-msg-range' => $message]; + return array('data-msg-range' => $message); break; default: - return ['data-msg-rangelength' => $message/*, 'data-msg-maxlength' => $message*/]; + return array('data-msg-rangelength' => $message/*, 'data-msg-maxlength' => $message*/); break; } } @@ -107,7 +107,7 @@ public function between($parsedRule, $attribute, $type) public function unique($parsedRule, $attribute) { $message = $this->getValidationMessage($attribute, $parsedRule['name']); - return ['data-msg-remote' => $message]; + return array('data-msg-remote' => $message); } public function exists($parsedRule, $attribute) @@ -117,9 +117,9 @@ public function exists($parsedRule, $attribute) public function required_with($parsedRule, $attribute) { - $values = implode(', ', array_map([$this, 'getValidationAttribute'], $parsedRule['parameters'])); + $values = implode(', ', array_map(array($this, 'getValidationAttribute'), $parsedRule['parameters'])); $message = $this->getValidationMessage($attribute, $parsedRule['name'], compact('values')); - return ['data-msg-required' => $message]; + return array('data-msg-required' => $message); } public function required_without($parsedRule, $attribute) @@ -134,8 +134,8 @@ public function active_url($parsedRule, $attribute) public function mimes($parsedRule, $attribute) { - $message = $this->getValidationMessage($attribute, $parsedRule['name'], ['values' => implode(', ', $parsedRule['parameters'])]); - return ['data-msg-accept' => $message]; + $message = $this->getValidationMessage($attribute, $parsedRule['name'], array('values' => implode(', ', $parsedRule['parameters']))); + return array('data-msg-accept' => $message); } } diff --git a/src/Bllim/Laravalid/converter/JqueryValidation/Rule.php b/src/Bllim/Laravalid/converter/JqueryValidation/Rule.php index 8004901..d1a5de4 100644 --- a/src/Bllim/Laravalid/converter/JqueryValidation/Rule.php +++ b/src/Bllim/Laravalid/converter/JqueryValidation/Rule.php @@ -4,44 +4,44 @@ class Rule extends \Bllim\Laravalid\Converter\Base\Rule { public function email() { - return ['data-rule-email' => 'true']; + return array('data-rule-email' => 'true'); } public function required() { - return ['required' => 'required']; + return array('required' => 'required'); } public function url() { - return ['data-rule-url' => 'true']; + return array('data-rule-url' => 'true'); } public function integer() { - return ['data-rule-integer' => 'true']; + return array('data-rule-integer' => 'true'); } public function numeric() { - return ['data-rule-number' => 'true']; + return array('data-rule-number' => 'true'); } public function ip() { - return ['data-rule-ipv4' => 'true']; + return array('data-rule-ipv4' => 'true'); } public function same($parsedRule) { $value = vsprintf(':input[name=\'%1$s\']', $parsedRule['parameters']); - return ['data-rule-equalto' => $value]; + return array('data-rule-equalto' => $value); } public function different($parsedRule) { $value = vsprintf(':input[name=\'%1$s\']', $parsedRule['parameters']); - return ['data-rule-notequalto' => $value]; + return array('data-rule-notequalto' => $value); } public function regex($parsedRule) @@ -52,37 +52,37 @@ public function regex($parsedRule) $rule = substr($rule, 1, -1); } - return ['pattern' => $rule]; + return array('pattern' => $rule); } public function alpha() { - return ['pattern' => '^[A-Za-z_.-]+$']; + return array('pattern' => '^[A-Za-z_.-]+$'); } public function alpha_num() { - return ['pattern' => '^[A-Za-z0-9_.-]+$']; + return array('pattern' => '^[A-Za-z0-9_.-]+$'); } public function image() { - return ['accept' => 'image/*']; + return array('accept' => 'image/*'); } public function date() { - return ['data-rule-date' => 'true']; + return array('data-rule-date' => 'true'); } public function before($parsedRule) { - return ['max' => reset($parsedRule['parameters'])]; + return array('max' => reset($parsedRule['parameters'])); } public function after($parsedRule) { - return ['min' => reset($parsedRule['parameters'])]; + return array('min' => reset($parsedRule['parameters'])); } /** @@ -98,11 +98,11 @@ public function min($parsedRule, $attribute, $type) switch ($type) { case 'numeric': - return ['min' => reset($parsedRule['parameters'])]; + return array('min' => reset($parsedRule['parameters'])); break; default: - return ['minlength' => reset($parsedRule['parameters'])]; + return array('minlength' => reset($parsedRule['parameters'])); break; } } @@ -112,11 +112,11 @@ public function max($parsedRule, $attribute, $type) switch ($type) { case 'numeric': - return ['max' => reset($parsedRule['parameters'])]; + return array('max' => reset($parsedRule['parameters'])); break; default: - return ['maxlength' => reset($parsedRule['parameters'])]; + return array('maxlength' => reset($parsedRule['parameters'])); break; } } @@ -126,11 +126,11 @@ public function between($parsedRule, $attribute, $type) switch ($type) { case 'numeric': - return ['data-rule-range' => vsprintf('%1$s,%2$s', $parsedRule['parameters'])]; + return array('data-rule-range' => vsprintf('%1$s,%2$s', $parsedRule['parameters'])); break; default: - return ['data-rule-rangelength' => vsprintf('%1$s,%2$s', $parsedRule['parameters']), 'maxlength' => vsprintf('%2$s', $parsedRule['parameters'])]; + return array('data-rule-rangelength' => vsprintf('%1$s,%2$s', $parsedRule['parameters']), 'maxlength' => vsprintf('%2$s', $parsedRule['parameters'])); break; } } @@ -140,7 +140,7 @@ protected function remote($method, $parsedRule) $param = implode(',', $parsedRule['parameters']); $encryptedParam = empty($param) ? '' : $this->encrypter->encrypt($param); - return ['data-rule-remote' => $this->routeUrl . '/' . $method . '?params=' . $encryptedParam]; + return array('data-rule-remote' => $this->routeUrl . '/' . $method . '?params=' . $encryptedParam); } public function unique($parsedRule) @@ -160,7 +160,7 @@ public function required_with($parsedRule) . '\']:not(:checkbox):not(:radio):filled,input:enabled[name=\'' . implode('\']:checked,input:enabled[name=\'', $parsedRule['parameters']) . '\']:checked'; - return ['data-rule-required' => $value]; + return array('data-rule-required' => $value); } public function required_without($parsedRule) @@ -170,7 +170,7 @@ public function required_without($parsedRule) . '\']:not(:checkbox):not(:radio):blank,input:enabled[name=\'' . implode('\']:unchecked,input:enabled[name=\'', $parsedRule['parameters']) . '\']:unchecked'; - return ['data-rule-required' => $value]; + return array('data-rule-required' => $value); } public function active_url($parsedRule) @@ -181,7 +181,7 @@ public function active_url($parsedRule) public function mimes($parsedRule) { // TODO: detect mime-type from extensions then sort and group by - return ['accept' => '.' . implode(',.', $parsedRule['parameters'])]; + return array('accept' => '.' . implode(',.', $parsedRule['parameters'])); } public function mergeOutputAttributes(array $outputAttributes, array &$ruleAttributes, $inputType = null) @@ -205,7 +205,7 @@ public function mergeOutputAttributes(array $outputAttributes, array &$ruleAttri if (isset($mRule['data'])) $rule['data'] = isset($rule['data']) ? ($rule['data'] + $mRule['data']) : $mRule['data']; - $outputAttributes['data-rule-remote'] = empty($rule['data']) ? $rule['url'] : json_encode($rule, JSON_UNESCAPED_SLASHES); + $outputAttributes['data-rule-remote'] = empty($rule['data']) ? $rule['url'] : str_replace('\/', '/', json_encode($rule)); unset($outputAttributes['data-msg-remote'], $ruleAttributes['data-rule-remote']); } } diff --git a/src/config/config.php b/src/config/config.php index 22fd887..54f26ed 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -1,7 +1,7 @@ true, 'plugin' => 'JqueryValidation', 'route' => 'laravalid' -]; \ No newline at end of file +); \ No newline at end of file diff --git a/tests/Bllim/Laravalid/FormBuilderTest.php b/tests/Bllim/Laravalid/FormBuilderTest.php index 0ca05ed..0ac68df 100644 --- a/tests/Bllim/Laravalid/FormBuilderTest.php +++ b/tests/Bllim/Laravalid/FormBuilderTest.php @@ -21,9 +21,13 @@ protected function setUp() $app = Converter\ConverterTest::initApplicationMock($this); $this->converter = ($this->getName(false) == 'testIntegration') ? new Converter\JqueryValidation\Converter($app) - : $this->getMock(__NAMESPACE__ . '\Converter\Base\Converter', ['set', 'reset', 'convert'], [], '', false); + : $this->getMock(__NAMESPACE__ . '\Converter\Base\Converter', array('set', 'reset', 'convert'), array(), '', false); $this->form = new FormBuilder(new HtmlBuilder($url = $app['url']), $url, '_csrf_token', $this->converter); + + $session = $this->getMock('Illuminate\Session\Store', array('get'), array(), '', false); + $this->form->setSessionStore($session); + $session->expects($this->any())->method('get')->willReturnArgument(1); } /** @@ -45,11 +49,11 @@ public function testRawAttributeName($paramValue, $expectedValue) public function dataForTestRawAttributeName() { return array( - ['Bar', 'Bar'], - ['bar_Foo[]', 'bar_Foo'], - ['Foo[][1]', 'Foo'], - ['foo[1][]', 'foo'], - ['Foo[Bar][0]', 'Foo'], + array('Bar', 'Bar'), + array('bar_Foo[]', 'bar_Foo'), + array('Foo[][1]', 'Foo'), + array('foo[1][]', 'foo'), + array('Foo[Bar][0]', 'Foo'), ); } @@ -64,8 +68,8 @@ public function testSetValidation() public function testOpen() { - $this->converter->expects($this->once())->method('set')->with($rules = ['bar']); - $html = $this->form->open(['url' => '/', 'method' => 'get'], $rules); + $this->converter->expects($this->once())->method('set')->with($rules = array('bar')); + $html = $this->form->open(array('url' => '/', 'method' => 'get'), $rules); $this->assertEquals('
', $html); } @@ -73,9 +77,9 @@ public function testOpen() public function testModel() { $this->converter->expects($this->exactly(2))->method('set') - ->withConsecutive([$rules = ['foo' => true]], [null]); + ->withConsecutive(array($rules = array('foo' => true)), array(null)); - $html = $this->form->model(new \stdClass(), ['url' => '/', 'method' => 'get'], $rules); + $html = $this->form->model(new \stdClass(), array('url' => '/', 'method' => 'get'), $rules); $this->assertEquals('', $html); } @@ -89,8 +93,8 @@ public function testClose() public function testInput() { $this->converter->expects($this->exactly(2))->method('convert') - ->withConsecutive(['foo', 'date'], ['bar', 'url']) - ->willReturnOnConsecutiveCalls(['foo' => 'date'], []); + ->withConsecutive(array('foo', 'date'), array('bar', 'url')) + ->willReturnOnConsecutiveCalls(array('foo' => 'date'), array()); $html = $this->form->input('date', 'foo[]'); $this->assertStringEndsWith('>', $html); @@ -107,7 +111,7 @@ public function testInput() public function testTextArea() { - $this->converter->expects($this->once())->method('convert')->with('bar', null)->willReturn([]); + $this->converter->expects($this->once())->method('convert')->with('bar', null)->willReturn(array()); $html = $this->form->textarea('bar[]'); $this->assertStringEndsWith('>', $html); @@ -117,7 +121,7 @@ public function testTextArea() public function testSelect() { - $this->converter->expects($this->once())->method('convert')->with('bar_foo', null)->willReturn([]); + $this->converter->expects($this->once())->method('convert')->with('bar_foo', null)->willReturn(array()); $html = $this->form->select('bar_foo'); $this->assertStringEndsWith('>', $html); @@ -128,7 +132,7 @@ public function testSelect() public function testCheckbox() { $this->converter->expects($this->exactly(2))->method('convert') - ->withConsecutive(['foo', 'checkbox'], ['bar', 'radio'])->willReturn([]); + ->withConsecutive(array('foo', 'checkbox'), array('bar', 'radio'))->willReturn(array()); $html = $this->form->checkbox('foo[]'); $this->assertStringEndsWith('>', $html); @@ -145,12 +149,12 @@ public function testCheckbox() } static $validationRules = array( - 'uid' => ['required', 'min:3', 'max:30', 'alpha_num', 'exists:users,uid'], + 'uid' => array('required', 'min:3', 'max:30', 'alpha_num', 'exists:users,uid'), 'email' => 'required|max:255|email|unique:users,email', - 'url' => ['required', 'max:255', 'url', 'unique:users,url', 'active_url'], + 'url' => array('required', 'max:255', 'url', 'unique:users,url', 'active_url'), 'name' => 'max:255|alpha', // - 'pwd' => ['min:6', 'max:15', 'regex:/^[0-9]+[xX][0-9]+$/'], + 'pwd' => array('min:6', 'max:15', 'regex:/^[0-9]+[xX][0-9]+$/'), 'confirm_pwd' => 'min:6|max:15|same:pwd', // 'first_name' => 'required_with:name|max:100|different:name', @@ -176,7 +180,7 @@ public function testCheckbox() public function testIntegration() { - $html = $this->form->model(new \stdClass(), ['url' => '/'], static::$validationRules); + $html = $this->form->model(new \stdClass(), array('url' => '/'), static::$validationRules); $this->assertEquals('', $html); $this->assertEquals(static::$validationRules, $this->converter->getValidationRules()); @@ -189,7 +193,7 @@ public function testIntegration() $this->assertContains(' pattern="^[A-Za-z0-9_.-]+$" data-msg-pattern="The UID may only contain letters and numbers."', $html); $this->assertContains(' data-rule-remote="/laravalid/exists?params=dXNlcnMsdWlk" data-msg-remote="The UID did not exist."', $html); - $html = $this->form->email('email', null, ['placeholder' => 'Email']); + $html = $this->form->email('email', null, array('placeholder' => 'Email')); $this->assertStringEndsWith(' name="email" type="email">', $html); $this->assertStringStartsWith('assertContains(' required="required" data-msg-required="The email field is required."', $html); @@ -252,7 +256,7 @@ public function testIntegration() $this->assertContains(' data-rule-url="true" data-msg-url="The photo format is invalid."', $html); $this->assertContains(' data-rule-remote="/laravalid/active_url?params=YW5vbg" data-msg-remote="The photo is not a valid URL."', $html); - $html = $this->form->select('gender', ['Female', 'Male']);// unsupported: boolean + $html = $this->form->select('gender', array('Female', 'Male'));// unsupported: boolean $this->assertEquals('', $html); $html = $this->form->input('date', 'birthdate'); @@ -268,10 +272,10 @@ public function testIntegration() $this->assertStringStartsWith('assertContains(' data-rule-rangelength="20,30" maxlength="30" data-msg-rangelength="The phone must be between {0} and {1} characters."', $html); - $html = $this->form->select('country', ['US' => 'US', 'VN' => 'VN']);// unsupported: in + $html = $this->form->select('country', array('US' => 'US', 'VN' => 'VN'));// unsupported: in $this->assertEquals('', $html); - $html = $this->form->number('rating'); + $html = method_exists($this->form, 'number') ? $this->form->number('rating') : $this->form->input('number', 'rating'); $this->assertStringEndsWith(' name="rating" type="number">', $html); $this->assertStringStartsWith('assertNotContains(' data-rule-numeric=', $html); @@ -279,14 +283,14 @@ public function testIntegration() $this->assertContains(' data-msg-number="The rating must be a number."', $html); $this->assertContains(' data-rule-range="0,100" data-msg-range="The rating must be between {0} and {1}."', $html); - $html = $this->form->number('duration'); + $html = method_exists($this->form, 'number') ? $this->form->number('duration') : $this->form->input('number', 'duration'); $this->assertStringEndsWith(' name="duration" type="number">', $html); $this->assertStringStartsWith('assertContains(' data-rule-integer="true" data-msg-integer="The length must be an integer."', $html); $this->assertContains(' min="0" data-msg-min="The length must be at least {0}."', $html); $this->assertContains(' max="18000" data-msg-max="The length may not be greater than {0}."', $html); - $html = $this->form->textarea('description', null, ['rows' => 5]); + $html = $this->form->textarea('description', null, array('rows' => 5)); $this->assertStringEndsWith(' name="description" cols="50">', $html); $this->assertStringStartsWith('