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/README.md b/README.md
index bdb1977..b00ea80 100644
--- a/README.md
+++ b/README.md
@@ -133,7 +133,7 @@ class UserController extends Controller {
if ($validator->fails())
{
- // actually withErrors is not really neccessary because we already show errors at client side for normal users
+ // actually withErrors is not really necessary because we already show errors at client side for normal users
return Redirect::back()->withErrors($validator);
}
@@ -187,7 +187,7 @@ Form::converter()->route()->extend('someotherrule', function($name, $parameters)
});
```
-Second, you can create your own converter (which extends baseconverter or any current plugin converter) in `Bllim\Laravalid\Converter\` namespace and change plugin configuration in config file with your own plugin name.
+Second, you can create your own converter (which extends `Base\Converter` or any current plugin converter) in `Bllim\Laravalid\Converter\` namespace and change plugin configuration in config file with your own plugin name.
> **Note:** If you are creating a converter for some existed html/js plugin please create it in `converter` folder and send a pull-request.
@@ -244,7 +244,7 @@ To use Jquery Validation, change plugin to `JqueryValidation` in config file and
### Contribution
You can fork and contribute to development of the package. All pull requests is welcome.
-**Convertion Logic**
+**Conversion Logic**
Package converts rules by using converters (in `src/Bllim/Laravalid/converter`). It uses `Converter` class of chosen plugin which extends `Converter/Base/Converter` class.
You can look at existed methods and plugins to understand how it works. Explanation will be ready, soon.
diff --git a/composer.json b/composer.json
index 17dcc64..ac82e0d 100644
--- a/composer.json
+++ b/composer.json
@@ -11,16 +11,15 @@
],
"require": {
"php": ">=5.3.0",
- "illuminate/config": "~4.2",
- "illuminate/html": "~4.2",
- "illuminate/support": "~4.2",
+ "illuminate/config": "~4.0",
+ "illuminate/html": "~4.0",
+ "illuminate/support": "~4.0",
"illuminate/validation": "~4.0",
"illuminate/routing": "~4.0",
"illuminate/translation": "~4.0"
},
"require-dev": {
- "phpunit/phpunit": "~4.0",
- "mockery/mockery": "~0.9"
+ "phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-0": {
diff --git a/phpunit.xml b/phpunit.xml
index 3347b75..fc765ff 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,5 +1,7 @@
-
./tests/
+
+
+
+ ./src/
+
+ ./vendor/
+
+
+
+
+
+
+
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 ff255d2..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
@@ -75,7 +75,7 @@ public function __construct($app)
$config = $app['config'];
$routeUrl = $app['url']->to($config->get('laravalid::route', 'laravalid'));
- $ns = substr(static::class, 0, -9) ?: '\\';
+ $ns = substr($class = get_class($this), 0, strrpos($class, '\\')) . '\\';
($class = $ns . 'Rule') and static::$rule = new $class($routeUrl, $app['encrypter']);
($class = $ns . 'Message') and static::$message = new $class($app['translator']);
($class = $ns . 'Route') and static::$route = new $class($app['validator'], $app['encrypter']);
@@ -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 0ffcef3..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,12 +205,12 @@ 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']);
}
}
- $outputAttributes += $ruleAttributes;
+ $outputAttributes = parent::mergeOutputAttributes($outputAttributes, $ruleAttributes, $inputType);
// remove duplicated rule attributes
if (!empty($inputType) && isset($ruleAttributes[$k = 'data-rule-' . $inputType]) && strcasecmp('true', $ruleAttributes[$k]) == 0)
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 df68a5b..0ac68df 100644
--- a/tests/Bllim/Laravalid/FormBuilderTest.php
+++ b/tests/Bllim/Laravalid/FormBuilderTest.php
@@ -4,9 +4,8 @@
class FormBuilderTest extends \PHPUnit_Framework_TestCase
{
-
/**
- * @var \Mockery\MockInterface|Converter\Base\Converter
+ * @var \PHPUnit_Framework_MockObject_MockObject|Converter\Base\Converter
*/
protected $converter;
@@ -19,16 +18,16 @@ protected function setUp()
{
parent::setUp();
- $app = Converter\ConverterTest::initApplicationMock();
- $this->converter = \Mockery::mock(new Converter\JqueryValidation\Converter($app));
+ $app = Converter\ConverterTest::initApplicationMock($this);
+ $this->converter = ($this->getName(false) == 'testIntegration')
+ ? new Converter\JqueryValidation\Converter($app)
+ : $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);
- }
- protected function tearDown()
- {
- parent::tearDown();
- \Mockery::close();
+ $session = $this->getMock('Illuminate\Session\Store', array('get'), array(), '', false);
+ $this->form->setSessionStore($session);
+ $session->expects($this->any())->method('get')->willReturnArgument(1);
}
/**
@@ -38,9 +37,7 @@ protected function tearDown()
*/
public function testRawAttributeName($paramValue, $expectedValue)
{
- $this->converter->shouldReceive('convert')->once()->andReturnUsing(function ($name) {
- return $name;
- });
+ $this->converter->expects($this->once())->method('convert')->willReturnArgument(0);
$value = Converter\ConverterTest::invokeMethod($this->form, 'getValidationAttributes', $paramValue);
$this->assertEquals($expectedValue, $value);
@@ -52,59 +49,58 @@ 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'),
);
}
public function testSetValidation()
{
- $this->converter->shouldReceive('set')->with(null)->once();
+ $this->converter->expects($this->once())->method('set')->with(null);
$this->form->setValidation(null);
- $this->converter->shouldReceive('reset')->once();
+ $this->converter->expects($this->once())->method('reset');
$this->form->resetValidation();
}
public function testOpen()
{
- $this->converter->shouldReceive('set')->with($rules = ['bar'])->once();
- $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('
', $this->form->close());
}
public function testInput()
{
- $this->converter->shouldReceive('convert')->once()->andReturnUsing(function ($name, $type = null) {
- return [$name => $type];
- });
+ $this->converter->expects($this->exactly(2))->method('convert')
+ ->withConsecutive(array('foo', 'date'), array('bar', 'url'))
+ ->willReturnOnConsecutiveCalls(array('foo' => 'date'), array());
$html = $this->form->input('date', 'foo[]');
$this->assertStringEndsWith('>', $html);
$this->assertStringStartsWith('assertContains(' foo="date"', $html);
- $this->converter->shouldReceive('convert')->with('bar', 'url')->once()->andReturn([]);
$html = $this->form->url('bar[]');
$this->assertStringEndsWith('>', $html);
@@ -115,7 +111,7 @@ public function testInput()
public function testTextArea()
{
- $this->converter->shouldReceive('convert')->with('bar', null)->once()->andReturn([]);
+ $this->converter->expects($this->once())->method('convert')->with('bar', null)->willReturn(array());
$html = $this->form->textarea('bar[]');
$this->assertStringEndsWith('>', $html);
@@ -125,7 +121,7 @@ public function testTextArea()
public function testSelect()
{
- $this->converter->shouldReceive('convert')->with('bar_foo', null)->once()->andReturn([]);
+ $this->converter->expects($this->once())->method('convert')->with('bar_foo', null)->willReturn(array());
$html = $this->form->select('bar_foo');
$this->assertStringEndsWith('>', $html);
@@ -135,7 +131,8 @@ public function testSelect()
public function testCheckbox()
{
- $this->converter->shouldReceive('convert')->with('foo', 'checkbox')->once()->andReturn([]);
+ $this->converter->expects($this->exactly(2))->method('convert')
+ ->withConsecutive(array('foo', 'checkbox'), array('bar', 'radio'))->willReturn(array());
$html = $this->form->checkbox('foo[]');
$this->assertStringEndsWith('>', $html);
@@ -143,7 +140,6 @@ public function testCheckbox()
$this->assertContains(' name="foo[]"', $html);
$this->assertContains(' type="checkbox"', $html);
- $this->converter->shouldReceive('convert')->with('bar', 'radio')->once()->andReturn([]);
$html = $this->form->radio('bar[]');
$this->assertStringEndsWith('>', $html);
@@ -153,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',
@@ -184,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('', $this->form->close());
- $this->assertEquals([], $this->converter->getValidationRules());
+ $this->assertEquals(array(), $this->converter->getValidationRules());
}
-
}
diff --git a/tests/Bllim/Laravalid/ServiceProviderTest.php b/tests/Bllim/Laravalid/ServiceProviderTest.php
new file mode 100644
index 0000000..eee64ee
--- /dev/null
+++ b/tests/Bllim/Laravalid/ServiceProviderTest.php
@@ -0,0 +1,104 @@
+assertAttributeSame(null, 'app', $provider);
+ $this->assertFalse($provider->isDeferred());
+ }
+
+ public function testProvides()
+ {
+ $provider = new LaravalidServiceProvider(null);
+ $this->assertEquals(array('laravalid'), $provider->provides());
+ }
+
+ public function testRegister()
+ {
+ $app = $this->getMock('Illuminate\Container\Container', array('bound', 'bind', 'make'));
+
+ $app->expects($this->once())->method('bound')->with('html')->willReturn(false);
+ $app->expects($this->exactly(2))->method('bind')
+ ->withConsecutive(
+ array('html', $this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_CALLABLE), $this->isTrue()),
+ array('laravalid', $this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_CALLABLE), $this->isTrue())
+ )
+ ->willReturnCallback(function ($abstract, $closure) use ($app, &$html) {
+ $object = $closure($app);
+ if ($abstract == 'html') $html = $object;
+
+ \PHPUnit_Framework_TestCase::assertNotEmpty($object);
+ \PHPUnit_Framework_TestCase::assertContains('\\' . ucfirst($abstract) . '\\', get_class($object));
+ });
+
+ $url = $this->getMock('Illuminate\Routing\UrlGenerator', array('to'), array(), '', false);
+ $config = $this->getMock('Illuminate\Config\Repository', array('get'), array(), '', false);
+ $session = $this->getMock('Illuminate\Session\Store', array('getToken'), array(), '', false);
+
+ $app->expects($this->atLeast(4))->method('make')->withConsecutive(array('url'), array('config'))->willReturnMap(array(
+ array('url', array(), $url),
+ array('config', array(), $config),
+ array('session.store', array(), $session),
+ array('html', array(), &$html),
+ ));
+
+ $config->expects($this->once())->method('get')->with('laravalid::plugin')->willReturn('\MyTestPlugin');
+ $session->expects($this->once())->method('getToken')->willReturn(uniqid());
+
+ if (!class_exists('MyTestPlugin\Converter'))
+ eval('namespace MyTestPlugin { class Converter extends \\' . __NAMESPACE__ . '\Converter\Base\Converter { public function __construct() { echo __CLASS__; } } }');
+
+ $this->expectOutputString('MyTestPlugin\Converter');
+ /** @noinspection PhpParamsInspection */
+ $provider = new LaravalidServiceProvider($app);
+ $provider->register();
+ }
+
+ public function testBoot()
+ {
+ $app = $this->getMock('Illuminate\Container\Container', array('make'));
+
+ $files = $this->getMock('Illuminate\Filesystem\Filesystem', null);
+ $config = $this->getMock('Illuminate\Config\Repository', array('get', 'package'), array(), '', false);
+ $router = $this->getMock('Illuminate\Routing\Router', array('any'), array(), '', false);
+ $route = $this->getMock('Illuminate\Routing\Route', array('where'), array(), '', false);
+
+ $form = $this->getMock(__NAMESPACE__ . '\FormBuilder', array('converter'), array(), '', false);
+ $converter = $this->getMock(__NAMESPACE__ . '\Converter\Base\Converter', array('route'), array(), '', false);
+ $valid = $this->getMock(__NAMESPACE__ . '\Converter\Base\Route', array('convert'), array(), '', false);
+ $request = $this->getMock('Illuminate\Http\Request', array('all'), array(), '', false);
+
+ $app->expects($this->atLeast(5))->method('make')->withConsecutive(array('files'), array('config'))->willReturnMap(array(
+ array('files', array(), $files),
+ array('config', array(), $config),
+ array('router', array(), $router),
+ array('laravalid', array(), $form),
+ array('request', array(), $request),
+ ));
+
+ $path = realpath(__DIR__ . '/../../../src');
+ $config->expects($this->once())->method('package')->with('bllim/laravalid', $path . '/config', 'laravalid');
+ $config->expects($this->once())->method('get')->with('laravalid::route', 'laravalid')->willReturnArgument(1);
+
+ $router->expects($this->once())->method('any')->willReturnCallback(function ($url, $action) use ($route) {
+ \PHPUnit_Framework_TestCase::assertEquals('laravalid/{rule}', $url);
+ \PHPUnit_Framework_TestCase::assertEquals('["exists",[{"params":"~"}]]', $action('exists'));
+ return $route;
+ });
+ $route->expects($this->once())->method('where')->with('rule', '[\w-]+');
+
+ $form->expects($this->once())->method('converter')->willReturn($converter);
+ $converter->expects($this->once())->method('route')->willReturn($valid);
+ $valid->expects($this->once())->method('convert')->willReturnCallback(function () {
+ return json_encode(func_get_args());
+ });
+ $request->expects($this->once())->method('all')->willReturn(array('params' => '~'));
+
+ /** @noinspection PhpParamsInspection */
+ $provider = new LaravalidServiceProvider($app);
+ $provider->boot();
+ }
+}
diff --git a/tests/Bllim/Laravalid/converter/ConverterTest.php b/tests/Bllim/Laravalid/converter/ConverterTest.php
index 2ca7db2..3549638 100644
--- a/tests/Bllim/Laravalid/converter/ConverterTest.php
+++ b/tests/Bllim/Laravalid/converter/ConverterTest.php
@@ -1,18 +1,11 @@
shouldReceive('get')->zeroOrMoreTimes()->andReturnUsing(function ($key, $default = null) {
+ $config = $test->getMock('Illuminate\Config\Repository', array('get'), array(), '', false);
+ $config->expects($test->any())->method('get')->willReturnCallback(function ($key, $default = null) {
return isset($default) ? $default : ($key == 'laravalid::plugin' ? 'JqueryValidation' : null);
});
- $url = \Mockery::mock(UrlGenerator::class);
- $url->shouldReceive('to')->andReturnUsing(function ($path) {
+ $url = $test->getMock('Illuminate\Routing\UrlGenerator', array('to'), array(), '', false);
+ $url->expects($test->any())->method('to')->willReturnCallback(function ($path) {
return '/' . ltrim($path, '/');
});
- /* @var $encrypter \Mockery\MockInterface|Encrypter */
- $encrypter = \Mockery::mock(Encrypter::class);
- $encrypter->shouldReceive('encrypt')->andReturnUsing(function ($data) {
- return str_replace(['/', '+', '='], ['_', '-', ''], base64_encode($data));
+ $encrypter = $test->getMock('Illuminate\Encryption\Encrypter', array('encrypt'), array(), '', false);
+ $encrypter->expects($test->any())->method('encrypt')->willReturnCallback(function ($data) {
+ return str_replace(array('/', '+', '='), array('_', '-', ''), base64_encode($data));
});
- /* @var $loader \Mockery\MockInterface|LoaderInterface */
- $loader = \Mockery::mock(LoaderInterface::class);
- $loader->shouldReceive('load')->with('en', 'validation', '*')->andReturn(static::$messages);
+ $loader = $test->getMock('Illuminate\Translation\LoaderInterface');
+ $loader->expects($test->any())->method('load')->with('en', 'validation', '*')->willReturn(static::$messages);
//
- $translator = \Mockery::mock(new Translator($loader, 'en'));
- $translator->shouldReceive('has')->zeroOrMoreTimes()->andReturn(false);
+ $translator = $test->getMock('Illuminate\Translation\Translator', !$trans ? array('has') : array('has', 'get'), array($loader, 'en'));
+ $translator->expects($test->any())->method('has')->willReturn(false);
- $mocks = compact('config', 'url', 'encrypter', 'translator');
- /* @var $app \Mockery\MockInterface|Container */
- $app = \Mockery::mock(Container::class);// Illuminate\Foundation\Application
-
- $app->shouldReceive('make')->andReturnUsing($func = function ($key) use ($mocks) {
- return isset($mocks[$key]) ? $mocks[$key] : null;
- });
- $app->shouldReceive('offsetGet')->zeroOrMoreTimes()->andReturnUsing($func);
+ $app = $test->getMock('Illuminate\Container\Container', array('make'));// Illuminate\Foundation\Application
+ $app->expects($test->any())->method('make')->willReturnMap(array(
+ array('config', array(), $config),
+ array('url', array(), $url),
+ array('encrypter', array(), $encrypter),
+ array('translator', array(), $translator),
+ ));
return $app;
}
@@ -62,16 +57,10 @@ protected function setUp()
{
parent::setUp();
- $this->app = $this->initApplicationMock();
+ $this->app = $this->initApplicationMock($this, $this->getName(false) == 'testDefaultErrorMessage');
$this->converter = new JqueryValidation\Converter($this->app);
}
- protected function tearDown()
- {
- parent::tearDown();
- \Mockery::close();
- }
-
static function invokeMethod($object, $methodName, $parameters = array())
{
$method = new \ReflectionMethod(get_class($object), $methodName);
@@ -82,9 +71,9 @@ static function invokeMethod($object, $methodName, $parameters = array())
public function testConstructor()
{
- $this->assertEquals(JqueryValidation\Rule::class, get_class($this->converter->rule()));
- $this->assertEquals(JqueryValidation\Message::class, get_class($this->converter->message()));
- $this->assertEquals(JqueryValidation\Route::class, get_class($this->converter->route()));
+ $this->assertInstanceOf(__NAMESPACE__ . '\JqueryValidation\Rule', $this->converter->rule());
+ $this->assertInstanceOf(__NAMESPACE__ . '\JqueryValidation\Message', $this->converter->message());
+ $this->assertInstanceOf(__NAMESPACE__ . '\JqueryValidation\Route', $this->converter->route());
$this->assertAttributeEquals($this->converter->rule(), 'rule', $this->converter);
$this->assertAttributeEquals($this->converter->message(), 'message', $this->converter);
@@ -94,19 +83,19 @@ public function testConstructor()
public function testSetRules()
{
$this->converter->reset();
- $this->assertEquals([], $this->converter->getValidationRules());
+ $this->assertEquals(array(), $this->converter->getValidationRules());
- $this->converter->set($rules = ['foo_bar' => 'required|email']);
+ $this->converter->set($rules = array('foo_bar' => 'required|email'));
$this->assertEquals($rules, $this->converter->getValidationRules());
$this->converter->set(null);
$this->assertEquals($rules, $this->converter->getValidationRules());
$value = $this->invokeMethod($this->converter, 'getValidationRule', 'foo_bar');
- $this->assertEquals(['required', 'email'], $value);
+ $this->assertEquals(array('required', 'email'), $value);
$this->converter->set('foo_bar');
- $this->assertEquals(['foo_bar'], $this->converter->getValidationRules());
+ $this->assertEquals(array('foo_bar'), $this->converter->getValidationRules());
$this->assertTrue($this->invokeMethod($this->converter, 'checkValidationRule', 0));
$this->assertFalse($this->invokeMethod($this->converter, 'checkValidationRule', 'foo'));
@@ -117,7 +106,7 @@ public function testSetRules()
* @param array $expected
* @dataProvider dataForParseValidationRule
*/
- public function testParseValidationRule($rule = '', $expected = [])
+ public function testParseValidationRule($rule = '', $expected = array())
{
$value = $this->invokeMethod($this->converter, 'parseValidationRule', $rule);
$this->assertEquals($expected, $value);
@@ -126,24 +115,24 @@ public function testParseValidationRule($rule = '', $expected = [])
public function dataForParseValidationRule()
{
return array(
- ['', ['name' => '', 'parameters' => []]],
- ['required', ['name' => 'required', 'parameters' => []]],
- ['min:3', ['name' => 'min', 'parameters' => ['3']]],
- ['exists:users,uid', ['name' => 'exists', 'parameters' => ['users', 'uid']]],
- ['max:255', ['name' => 'max', 'parameters' => ['255']]],
- ['unique:users,email', ['name' => 'unique', 'parameters' => ['users', 'email']]],
- ['regex:/^\d+,$/', ['name' => 'regex', 'parameters' => ['/^\d+,$/']]],
- ['same:pwd,1', ['name' => 'same', 'parameters' => ['pwd,1']]],
- ['required_without:first_name', ['name' => 'required_without', 'parameters' => ['first_name']]],
- ['required_with:name|max', ['name' => 'required_with', 'parameters' => ['name|max']]],
- ['different:name', ['name' => 'different', 'parameters' => ['name']]],
- ['active_url:anon', ['name' => 'active_url', 'parameters' => ['anon']]],
- ['between:20,30', ['name' => 'between', 'parameters' => ['20', '30']]],
- ['in:US,VN', ['name' => 'in', 'parameters' => ['US', 'VN']]],
- ['after:1900-01-01|before', ['name' => 'after', 'parameters' => ['1900-01-01|before']]],
- ['before:2018-01-01', ['name' => 'before', 'parameters' => ['2018-01-01']]],
- ['array', ['name' => 'array', 'parameters' => []]],
- ['mimes:csv,txt', ['name' => 'mimes', 'parameters' => ['csv', 'txt']]],
+ array('', array('name' => '', 'parameters' => array())),
+ array('required', array('name' => 'required', 'parameters' => array())),
+ array('min:3', array('name' => 'min', 'parameters' => array('3'))),
+ array('exists:users,uid', array('name' => 'exists', 'parameters' => array('users', 'uid'))),
+ array('max:255', array('name' => 'max', 'parameters' => array('255'))),
+ array('unique:users,email', array('name' => 'unique', 'parameters' => array('users', 'email'))),
+ array('regex:/^\d+,$/', array('name' => 'regex', 'parameters' => array('/^\d+,$/'))),
+ array('same:pwd,1', array('name' => 'same', 'parameters' => array('pwd,1'))),
+ array('required_without:first_name', array('name' => 'required_without', 'parameters' => array('first_name'))),
+ array('required_with:name|max', array('name' => 'required_with', 'parameters' => array('name|max'))),
+ array('different:name', array('name' => 'different', 'parameters' => array('name'))),
+ array('active_url:anon', array('name' => 'active_url', 'parameters' => array('anon'))),
+ array('between:20,30', array('name' => 'between', 'parameters' => array('20', '30'))),
+ array('in:US,VN', array('name' => 'in', 'parameters' => array('US', 'VN'))),
+ array('after:1900-01-01|before', array('name' => 'after', 'parameters' => array('1900-01-01|before'))),
+ array('before:2018-01-01', array('name' => 'before', 'parameters' => array('2018-01-01'))),
+ array('array', array('name' => 'array', 'parameters' => array())),
+ array('mimes:csv,txt', array('name' => 'mimes', 'parameters' => array('csv', 'txt'))),
);
}
@@ -152,22 +141,22 @@ public function dataForParseValidationRule()
* @param string $expected
* @dataProvider dataForGetTypeOfInput
*/
- public function testGetTypeOfInput($rules = [], $expected = '')
+ public function testGetTypeOfInput($rules = array(), $expected = '')
{
- $value = $this->invokeMethod($this->converter, 'getTypeOfInput', [$rules]);
+ $value = $this->invokeMethod($this->converter, 'getTypeOfInput', array($rules));
$this->assertEquals($expected, $value);
}
public function dataForGetTypeOfInput()
{
return array(
- [[], 'string'],
- [['required_with:name', 'numeric'], 'numeric'],
- [['min:0', 'integer'], 'numeric'],
- [['between:0,5', 'array'], 'array'],
- [['before:2018-01-01', 'image'], 'file'],
- [['max:100', 'mimes'], 'file'],
- [['required', 'unique', 'after:1900-01-01'], 'string'],
+ array(array(), 'string'),
+ array(array('required_with:name', 'numeric'), 'numeric'),
+ array(array('min:0', 'integer'), 'numeric'),
+ array(array('between:0,5', 'array'), 'array'),
+ array(array('before:2018-01-01', 'image'), 'file'),
+ array(array('max:100', 'mimes'), 'file'),
+ array(array('required', 'unique', 'after:1900-01-01'), 'string'),
);
}
@@ -176,9 +165,9 @@ public function dataForGetTypeOfInput()
* @param array $expected
* @dataProvider dataForDefaultErrorMessage
*/
- public function testDefaultErrorMessage($params = [], $expected = [])
+ public function testDefaultErrorMessage($params = array(), $expected = array())
{
- $this->app['translator']->shouldReceive('get')->times(2)->andReturnUsing(function ($key, $data = []) {
+ $this->app['translator']->expects($this->exactly(2))->method('get')->willReturnCallback(function ($key, $data = array()) {
return $key . (empty($data) ? '' : json_encode($data));
});
@@ -189,9 +178,9 @@ public function testDefaultErrorMessage($params = [], $expected = [])
public function dataForDefaultErrorMessage()
{
return array(
- [['url', 'barFoo'], ['data-msg-url' => 'validation.url{"attribute":"bar foo"}']],
- [['date', 'bar_Foo'], ['data-msg-date' => 'validation.date{"attribute":"bar foo"}']],
- [['email', 'Foo'], ['data-msg-email' => 'validation.email{"attribute":"foo"}']],
+ array(array('url', 'barFoo'), array('data-msg-url' => 'validation.url{"attribute":"bar foo"}')),
+ array(array('date', 'bar_Foo'), array('data-msg-date' => 'validation.date{"attribute":"bar foo"}')),
+ array(array('email', 'Foo'), array('data-msg-email' => 'validation.email{"attribute":"foo"}')),
);
}
@@ -201,7 +190,7 @@ public function dataForDefaultErrorMessage()
* @param array $expected
* @dataProvider dataForTestConvert
*/
- public function testConvert($inputName = '', $inputType = null, $expected = [])
+ public function testConvert($inputName = '', $inputType = null, $expected = array())
{
$this->converter->set(FormBuilderTest::$validationRules);
@@ -265,109 +254,108 @@ public function testConvert($inputName = '', $inputType = null, $expected = [])
public function dataForTestConvert()
{
return array(
- ['', null, []],
- ['not_exists', null, []],
+ array('', null, array()),
+ array('not_exists', null, array()),
//
- ['uid', 'text', [
+ array('uid', 'text', array(
'required' => 'required', 'data-msg-required' => 'The UID field is required.',
'minlength' => '3', 'data-msg-minlength' => 'The UID must be at least {0} characters.',
'maxlength' => '30', 'data-msg-maxlength' => 'The UID may not be greater than {0} characters.',
'pattern' => '^[A-Za-z0-9_.-]+$', 'data-msg-pattern' => 'The UID may only contain letters and numbers.',
'data-rule-remote' => '/laravalid/exists?params=dXNlcnMsdWlk', 'data-msg-remote' => 'The UID did not exist.',
- ]],
- ['email', 'email', [
+ )),
+ array('email', 'email', array(
'required' => 'required', 'data-msg-required' => 'The email field is required.',
'maxlength' => '255', 'data-msg-maxlength' => 'The email may not be greater than {0} characters.',
'data-msg-email' => 'The email must be a valid email address.',
'data-rule-remote' => '/laravalid/unique?params=dXNlcnMsZW1haWw', 'data-msg-remote' => 'The email has already been taken.',
- ]],
- ['url', 'url', [
+ )),
+ array('url', 'url', array(
'required' => 'required', 'data-msg-required' => 'The URL field is required.',
'maxlength' => '255', 'data-msg-maxlength' => 'The URL may not be greater than {0} characters.',
'data-msg-url' => 'The URL format is invalid.',
'data-rule-remote' => '/laravalid/unique-active_url?params[]=dXNlcnMsdXJs¶ms[]=',
- ]],
- ['name', 'text', [
+ )),
+ array('name', 'text', array(
'maxlength' => '255', 'data-msg-maxlength' => 'The name may not be greater than {0} characters.',
'pattern' => '^[A-Za-z_.-]+$', 'data-msg-pattern' => 'The name may only contain letters.',
- ]],
+ )),
//
- ['pwd', 'password', [
+ array('pwd', 'password', array(
'minlength' => '6', 'data-msg-minlength' => 'The password must be at least {0} characters.',
'maxlength' => '15', 'data-msg-maxlength' => 'The password may not be greater than {0} characters.',
'pattern' => '^[0-9]+[xX][0-9]+$', 'data-msg-pattern' => 'The password format is invalid.',
- ]],
- ['confirm_pwd', 'password', [
+ )),
+ array('confirm_pwd', 'password', array(
'minlength' => '6', 'data-msg-minlength' => 'The confirmation must be at least {0} characters.',
'maxlength' => '15', 'data-msg-maxlength' => 'The confirmation may not be greater than {0} characters.',
'data-rule-equalto' => ':input[name=\'pwd\']', 'data-msg-equalto' => 'The confirmation and password must match.',
- ]],
+ )),
//
- ['first_name', 'text', [
+ array('first_name', 'text', array(
'data-rule-required' => ':input:enabled[name=\'name\']:not(:checkbox):not(:radio):filled,input:enabled[name=\'name\']:checked',
'data-msg-required' => 'The first name field is required when name is present.',
'maxlength' => '100', 'data-msg-maxlength' => 'The first name may not be greater than {0} characters.',
'data-rule-notequalto' => ':input[name=\'name\']', 'data-msg-notequalto' => 'The first name and name must be different.',
- ]],
- ['last_name', 'text', [
+ )),
+ array('last_name', 'text', array(
'data-rule-required' => ':input:enabled[name=\'first_name\']:not(:checkbox):not(:radio):blank,input:enabled[name=\'first_name\']:unchecked',
'data-msg-required' => 'The last name field is required when first name is not present.',
'maxlength' => '100', 'data-msg-maxlength' => 'The last name may not be greater than {0} characters.',
- ]],
+ )),
//
- ['photo', 'url', [
+ array('photo', 'url', array(
'maxlength' => '1000', 'data-msg-maxlength' => 'The photo may not be greater than {0} characters.',
'data-msg-url' => 'The photo format is invalid.',
'data-rule-remote' => '/laravalid/active_url?params=YW5vbg', 'data-msg-remote' => 'The photo is not a valid URL.',
- ]],
- ['gender', null, []],// unsupported: boolean
- ['birthdate', 'date', [
+ )),
+ array('gender', null, array()),// unsupported: boolean
+ array('birthdate', 'date', array(
'data-msg-date' => 'The birthdate is not a valid date.',
'min' => '1900-01-01', 'data-msg-min' => 'The birthdate must be a date after {0}.',
'max' => '2018-01-01', 'data-msg-max' => 'The birthdate must be a date before {0}.',
- ]],
- ['phone', 'text', [
+ )),
+ array('phone', 'text', array(
'data-rule-rangelength' => '20,30', 'data-msg-rangelength' => 'The phone must be between {0} and {1} characters.',
'maxlength' => '30',
- ]],
- ['country', null, []],// unsupported: in
+ )),
+ array('country', null, array()),// unsupported: in
//
- ['rating', 'number', [
+ array('rating', 'number', array(
'data-msg-number' => 'The rating must be a number.',
'data-rule-range' => '0,100', 'data-msg-range' => 'The rating must be between {0} and {1}.',
- ]],
- ['duration', 'number', [
+ )),
+ array('duration', 'number', array(
'data-rule-integer' => 'true', 'data-msg-integer' => 'The length must be an integer.',
'min' => '0', 'data-msg-min' => 'The length must be at least {0}.',
'max' => '18000', 'data-msg-max' => 'The length may not be greater than {0}.',
- ]],
+ )),
//
- ['description', null, [
+ array('description', null, array(
'maxlength' => '2000', 'data-msg-maxlength' => 'The description may not be greater than {0} characters.',
- ]],
- ['roles', 'checkbox', [
+ )),
+ array('roles', 'checkbox', array(
'minlength' => '1', 'data-msg-minlength' => 'The roles must have at least {0} items.',
'maxlength' => '3', 'data-msg-maxlength' => 'The roles may not have more than {0} items.',
- ]],
+ )),
//
- ['avatar', 'file', [
+ array('avatar', 'file', array(
'accept' => 'image/*', 'data-msg-accept' => 'The avatar must be an image.',
'minlength' => '30', 'data-msg-minlength' => 'The avatar must be at least {0} kilobytes.',
'maxlength' => '300', 'data-msg-maxlength' => 'The avatar may not be greater than {0} kilobytes.',
- ]],
- ['settings', null, [
+ )),
+ array('settings', null, array(
'data-rule-rangelength' => '0,5', 'data-msg-rangelength' => 'The settings must have between {0} and {1} items.',
'maxlength' => '5',
- ]],
- ['client_ip', 'text', [
+ )),
+ array('client_ip', 'text', array(
'data-rule-ipv4' => 'true', 'data-msg-ipv4' => 'The client ip must be a valid IP address.',
- ]],
- ['upload', 'file', [
+ )),
+ array('upload', 'file', array(
'accept' => '.csv,.txt', 'data-msg-accept' => 'The upload must be a file of type: csv, txt.',
'data-rule-rangelength' => '100,500', 'data-msg-rangelength' => 'The upload must be between {0} and {1} kilobytes.',
'maxlength' => '500',
- ]],
+ )),
);
}
-
}
diff --git a/tests/Bllim/Laravalid/converter/MessageTest.php b/tests/Bllim/Laravalid/converter/MessageTest.php
index f8d5f23..0760197 100644
--- a/tests/Bllim/Laravalid/converter/MessageTest.php
+++ b/tests/Bllim/Laravalid/converter/MessageTest.php
@@ -1,12 +1,9 @@
translator = \Mockery::mock(Translator::class);
+ $this->translator = $this->getMock('Illuminate\Translation\Translator', array('has', 'get'), array(), '', false);
$this->message = new JqueryValidation\Message($this->translator);
}
- protected function tearDown()
- {
- parent::tearDown();
- \Mockery::close();
- }
-
public function testExtend()
{
$this->assertNull($this->message->convert('foo'));
@@ -36,47 +27,37 @@ public function testExtend()
$this->message->extend('foo', $func = function () {
return func_get_args();
});
- $this->assertEquals($params = ['Bar', ['zoo' => 'foo']], $this->message->convert('Foo', $params));
+ $this->assertEquals($params = array('Bar', array('zoo' => 'foo')), $this->message->convert('Foo', $params));
$this->message->extend('ip', $func);
- $this->assertEquals($params = [['name' => 'Ip'], 'barFoo'], $this->message->convert('IP', $params));
+ $this->assertEquals($params = array(array('name' => 'Ip'), 'barFoo'), $this->message->convert('IP', $params));
}
public function testGetValidationMessage()
{
- $this->translator->shouldReceive('has')->once()->andReturn(false);
- $this->translator->shouldReceive('get')->with('validation.attributes.first_name')->once()->andReturnUsing(function ($key) {
- return $key;
- });
- $this->translator->shouldReceive('get')
- ->with('validation.active_url', ['other' => 'old_name', 'attribute' => 'first name'])->once()
- ->andReturnUsing(function ($key, $data) {
- return ($key == 'validation.active_url') ? $data['attribute'] . ' === ' . $data['other'] : $key;
- });
-
- $value = $this->message->getValidationMessage('first_name', 'activeUrl', ['other' => 'old_name']);
- $this->assertEquals('first name === old_name', $value);
-
+ $this->translator->expects($this->exactly(3))->method('has')
+ ->withConsecutive(array($this->anything()), array('validation.custom.lastName.email'), array($this->anything()))
+ ->willReturnOnConsecutiveCalls(false, true, false);
//
- $this->translator->shouldReceive('has')->with('validation.custom.lastName.email')->once()->andReturn(true);
- $this->translator->shouldReceive('get')->with('validation.attributes.lastName')->once()->andReturn('Last name');
- $this->translator->shouldReceive('get')
- ->with('validation.custom.lastName.email', ['max' => '100', 'attribute' => 'Last name'])->once()
- ->andReturnUsing(function ($key, $data) {
- return ($key == 'validation.custom.lastName.email') ? $data['attribute'] . ' <= ' . $data['max'] : $key;
- });
+ $this->translator->expects($this->exactly(6))->method('get')
+ ->withConsecutive(
+ array('validation.attributes.first_name'), array('validation.active_url', array('other' => 'old_name', 'attribute' => 'first name')),
+ array('validation.attributes.lastName'), array('validation.custom.lastName.email', array('max' => '100', 'attribute' => 'Last name')),
+ array('validation.attributes.foo'), array('validation.max.numeric', array('attribute' => 'Bar'))
+ )
+ ->willReturnOnConsecutiveCalls(
+ 'validation.attributes.first_name', 'first name === old_name',
+ 'Last name', 'Last name <= 100',
+ 'Bar', 'validation.max.numeric'
+ );
+
+ $value = $this->message->getValidationMessage('first_name', 'activeUrl', array('other' => 'old_name'));
+ $this->assertEquals('first name === old_name', $value);
- $value = $this->message->getValidationMessage('lastName', 'email', ['max' => '100']);
+ $value = $this->message->getValidationMessage('lastName', 'email', array('max' => '100'));
$this->assertEquals('Last name <= 100', $value);
- //
- $this->translator->shouldReceive('has')->once()->andReturn(false);
- $this->translator->shouldReceive('get')->with('validation.attributes.foo')->once()->andReturn('Bar');
- $this->translator->shouldReceive('get')->with('validation.max.numeric', ['attribute' => 'Bar'])->once()->andReturnUsing(function ($key) {
- return $key;
- });
-
- $value = $this->message->getValidationMessage('foo', 'max', [], 'numeric');
+ $value = $this->message->getValidationMessage('foo', 'max', array(), 'numeric');
$this->assertEquals('validation.max.numeric', $value);
}
@@ -86,14 +67,14 @@ public function testGetValidationMessage()
* @param array $expected
* @dataProvider dataForTestAllRules
*/
- public function testAllRules($name = '', $params = [], $expected = [])
+ public function testAllRules($name = '', $params = array(), $expected = array())
{
- $this->translator->shouldReceive('has')->times(2)->andReturn(preg_match('/^[A-Z]/', $name));
- $this->translator->shouldReceive('get')->atLeast()->times(4)->andReturnUsing(function ($key, $data = null) {
+ $this->translator->expects($this->exactly(2))->method('has')->willReturn(preg_match('/^[A-Z]/', $name));
+ $this->translator->expects($this->atLeast(4))->method('get')->willReturnCallback(function ($key, $data = null) {
return $key . (empty($data) ? '' : json_encode($data));
});
- $value = call_user_func_array([$this->message, strtolower($name)], $params);
+ $value = call_user_func_array(array($this->message, strtolower($name)), $params);
$this->assertEquals($expected, $value);
$this->assertEquals($expected, $this->message->convert($name, $params));
@@ -102,50 +83,49 @@ public function testAllRules($name = '', $params = [], $expected = [])
public function dataForTestAllRules()
{
return array(
- ['IP', [['name' => 'Ip'], 'barFoo', 'string'], ['data-msg-ipv4' => 'validation.custom.barFoo.ip{"attribute":"bar foo"}']],
- ['same', [['name' => 'Same', 'parameters' => ['X']], 'barFoo'], ['data-msg-equalto' => 'validation.same{"other":"x","attribute":"bar foo"}']],
- ['different', [['name' => 'different', 'parameters' => ['foo']], 'bar'], ['data-msg-notequalto' => 'validation.different{"other":"foo","attribute":"bar"}']],
- ['Alpha', [['name' => 'alpha'], 'barFoo'], ['data-msg-pattern' => 'validation.custom.barFoo.alpha{"attribute":"bar foo"}']],
- ['alpha_Num', [['name' => 'AlphaNum'], 'barFoo', 'numeric'], ['data-msg-pattern' => 'validation.alpha_num{"attribute":"bar foo"}']],
- ['Regex', [['name' => 'Regex'], 'barFoo'], ['data-msg-pattern' => 'validation.custom.barFoo.regex{"attribute":"bar foo"}']],
+ array('IP', array(array('name' => 'Ip'), 'barFoo', 'string'), array('data-msg-ipv4' => 'validation.custom.barFoo.ip{"attribute":"bar foo"}')),
+ array('same', array(array('name' => 'Same', 'parameters' => array('X')), 'barFoo'), array('data-msg-equalto' => 'validation.same{"other":"x","attribute":"bar foo"}')),
+ array('different', array(array('name' => 'different', 'parameters' => array('foo')), 'bar'), array('data-msg-notequalto' => 'validation.different{"other":"foo","attribute":"bar"}')),
+ array('Alpha', array(array('name' => 'alpha'), 'barFoo'), array('data-msg-pattern' => 'validation.custom.barFoo.alpha{"attribute":"bar foo"}')),
+ array('alpha_Num', array(array('name' => 'AlphaNum'), 'barFoo', 'numeric'), array('data-msg-pattern' => 'validation.alpha_num{"attribute":"bar foo"}')),
+ array('Regex', array(array('name' => 'Regex'), 'barFoo'), array('data-msg-pattern' => 'validation.custom.barFoo.regex{"attribute":"bar foo"}')),
//
- ['image', [['name' => 'Image'], 'barFoo', 'file'], ['data-msg-accept' => 'validation.image{"attribute":"bar foo"}']],
- ['before', [['name' => 'Before'], 'Bar', 'date'], ['data-msg-max' => 'validation.before{"date":"{0}","attribute":"bar"}']],
- ['after', [['name' => 'after', 'parameters' => ['1900-01-01']], 'bar', 'date'], ['data-msg-min' => 'validation.after{"date":"{0}","attribute":"bar"}']],
- ['Numeric', [['name' => 'Numeric'], 'barFoo', 'numeric'], ['data-msg-number' => 'validation.custom.barFoo.numeric{"attribute":"bar foo"}']],
+ array('image', array(array('name' => 'Image'), 'barFoo', 'file'), array('data-msg-accept' => 'validation.image{"attribute":"bar foo"}')),
+ array('before', array(array('name' => 'Before'), 'Bar', 'date'), array('data-msg-max' => 'validation.before{"date":"{0}","attribute":"bar"}')),
+ array('after', array(array('name' => 'after', 'parameters' => array('1900-01-01')), 'bar', 'date'), array('data-msg-min' => 'validation.after{"date":"{0}","attribute":"bar"}')),
+ array('Numeric', array(array('name' => 'Numeric'), 'barFoo', 'numeric'), array('data-msg-number' => 'validation.custom.barFoo.numeric{"attribute":"bar foo"}')),
//
- ['Max', [['name' => 'Max'], 'Foo', 'numeric'], ['data-msg-max' => 'validation.custom.Foo.max.numeric{"max":"{0}","attribute":"foo"}']],
- ['max', [['name' => 'Max', 'parameters' => ['10']], 'foo', 'file'], ['data-msg-maxlength' => 'validation.max.file{"max":"{0}","attribute":"foo"}']],
- ['Min', [['name' => 'Min'], 'Bar', 'numeric'], ['data-msg-min' => 'validation.custom.Bar.min.numeric{"min":"{0}","attribute":"bar"}']],
- ['min', [['name' => 'Min', 'parameters' => ['10']], 'bar', 'string'], ['data-msg-minlength' => 'validation.min.string{"min":"{0}","attribute":"bar"}']],
+ array('Max', array(array('name' => 'Max'), 'Foo', 'numeric'), array('data-msg-max' => 'validation.custom.Foo.max.numeric{"max":"{0}","attribute":"foo"}')),
+ array('max', array(array('name' => 'Max', 'parameters' => array('10')), 'foo', 'file'), array('data-msg-maxlength' => 'validation.max.file{"max":"{0}","attribute":"foo"}')),
+ array('Min', array(array('name' => 'Min'), 'Bar', 'numeric'), array('data-msg-min' => 'validation.custom.Bar.min.numeric{"min":"{0}","attribute":"bar"}')),
+ array('min', array(array('name' => 'Min', 'parameters' => array('10')), 'bar', 'string'), array('data-msg-minlength' => 'validation.min.string{"min":"{0}","attribute":"bar"}')),
//
- ['between', [['name' => 'between'], 'barFoo', 'numeric'], ['data-msg-range' => 'validation.between.numeric{"min":"{0}","max":"{1}","attribute":"bar foo"}']],
- [
+ array('between', array(array('name' => 'between'), 'barFoo', 'numeric'), array('data-msg-range' => 'validation.between.numeric{"min":"{0}","max":"{1}","attribute":"bar foo"}')),
+ array(
'Between',
- [['name' => 'Between', 'parameters' => ['1', '10']], 'barFoo', 'array'],
- ['data-msg-rangelength' => 'validation.custom.barFoo.between.array{"min":"{0}","max":"{1}","attribute":"bar foo"}']
- ],
+ array(array('name' => 'Between', 'parameters' => array('1', '10')), 'barFoo', 'array'),
+ array('data-msg-rangelength' => 'validation.custom.barFoo.between.array{"min":"{0}","max":"{1}","attribute":"bar foo"}')
+ ),
//
- [
+ array(
'required_With',
- [['name' => 'requiredWith', 'parameters' => ['bar', 'foo2']], 'Foo', 'string'],
- ['data-msg-required' => 'validation.required_with{"values":"bar, foo2","attribute":"foo"}']
- ],
- [
+ array(array('name' => 'requiredWith', 'parameters' => array('bar', 'foo2')), 'Foo', 'string'),
+ array('data-msg-required' => 'validation.required_with{"values":"bar, foo2","attribute":"foo"}')
+ ),
+ array(
'Required_withOut',
- [['name' => 'RequiredWithout', 'parameters' => ['foo2']], 'foo', 'array'],
- ['data-msg-required' => 'validation.custom.foo.required_without{"values":"foo2","attribute":"foo"}']
- ],
- [
+ array(array('name' => 'RequiredWithout', 'parameters' => array('foo2')), 'foo', 'array'),
+ array('data-msg-required' => 'validation.custom.foo.required_without{"values":"foo2","attribute":"foo"}')
+ ),
+ array(
'Mimes',
- [['name' => 'Mimes', 'parameters' => ['csv', 'pdf']], 'barFoo', 'file'],
- ['data-msg-accept' => 'validation.custom.barFoo.mimes{"values":"csv, pdf","attribute":"bar foo"}']
- ],
+ array(array('name' => 'Mimes', 'parameters' => array('csv', 'pdf')), 'barFoo', 'file'),
+ array('data-msg-accept' => 'validation.custom.barFoo.mimes{"values":"csv, pdf","attribute":"bar foo"}')
+ ),
//
- ['Unique', [['name' => 'unique'], 'Bar', 'string'], ['data-msg-remote' => 'validation.custom.Bar.unique{"attribute":"bar"}']],
- ['exists', [['name' => 'exists', 'parameters' => ['Tbl,f']], 'BarFoo'], ['data-msg-remote' => 'validation.exists{"attribute":"bar foo"}']],
- ['active_Url', [['name' => 'ActiveUrl', 'parameters' => ['anon']], 'barFoo'], ['data-msg-remote' => 'validation.active_url{"attribute":"bar foo"}']],
+ array('Unique', array(array('name' => 'unique'), 'Bar', 'string'), array('data-msg-remote' => 'validation.custom.Bar.unique{"attribute":"bar"}')),
+ array('exists', array(array('name' => 'exists', 'parameters' => array('Tbl,f')), 'BarFoo'), array('data-msg-remote' => 'validation.exists{"attribute":"bar foo"}')),
+ array('active_Url', array(array('name' => 'ActiveUrl', 'parameters' => array('anon')), 'barFoo'), array('data-msg-remote' => 'validation.active_url{"attribute":"bar foo"}')),
);
}
-
}
diff --git a/tests/Bllim/Laravalid/converter/RouteTest.php b/tests/Bllim/Laravalid/converter/RouteTest.php
index 7be3da3..e261bd6 100644
--- a/tests/Bllim/Laravalid/converter/RouteTest.php
+++ b/tests/Bllim/Laravalid/converter/RouteTest.php
@@ -1,21 +1,16 @@
validator = \Mockery::mock(Factory::class);
- $this->encrypter = \Mockery::mock(Encrypter::class);
+ $this->validator = $this->getMock('Illuminate\Validation\Factory', array('make'), array(), '', false);
+ $this->encrypter = $this->getMock('Illuminate\Encryption\Encrypter', array('decrypt'), array(), '', false);
$this->route = new JqueryValidation\Route($this->validator, $this->encrypter);
}
- protected function tearDown()
- {
- parent::tearDown();
- \Mockery::close();
- }
-
public function testActiveUrl()
{
- $this->validator->shouldReceive('make')->with(['Bar' => 'foo'], ['Bar' => ['active_url']])->once()
- ->andReturn($validator = \Mockery::mock(Validator::class));
- $validator->shouldReceive('fails')->once()->andReturn(true);
- $validator->shouldReceive('messages')->once()->andReturn(new MessageBag(['Bar' => $msg = 'Inactive URL']));
-
- $response = $this->route->convert('active_url', [['Bar' => 'foo', '_' => time()]]);
- $this->assertEquals(JsonResponse::class, get_class($response));
- $this->assertEquals($msg, $response->getData());
+ $validator = $this->getMock('Illuminate\Validation\Validator', array('fails', 'messages'), array(), '', false);
+ $this->validator->expects($this->once())->method('make')
+ ->with(array('Bar' => 'foo'), array('Bar' => array('active_url')))->willReturn($validator);
+ $validator->expects($this->once())->method('fails')->willReturn(true);
+ $validator->expects($this->once())->method('messages')->willReturn(new MessageBag(array('Bar' => $msg = 'Inactive URL')));
+
+ $response = $this->route->convert('active_url', array(array('Bar' => 'foo', '_' => time())));
+ $this->assertInstanceOf('Illuminate\Http\JsonResponse', $response);
+ $this->assertAttributeEquals('"' . $msg . '"', 'data', $response);
}
public function testExists()
{
- $this->encrypter->shouldReceive('decrypt')->once()->andReturnUsing(function ($data) {
+ $this->encrypter->expects($this->once())->method('decrypt')->willReturnCallback(function ($data) {
return substr($data, 1);
});
- $this->validator->shouldReceive('make')->with(['foo' => 'Bar'], ['foo' => ['exists:Tbl,field,ID']])->once()
- ->andReturn($validator = \Mockery::mock(Validator::class));
- $validator->shouldReceive('fails')->once()->andReturn(false);
+ $validator = $this->getMock('Illuminate\Validation\Validator', array('fails'), array(), '', false);
+ $this->validator->expects($this->once())->method('make')
+ ->with(array('foo' => 'Bar'), array('foo' => array('exists:Tbl,field,ID')))->willReturn($validator);
+ $validator->expects($this->once())->method('fails')->willReturn(false);
- $response = $this->route->convert('exists', [['foo' => 'Bar', 'params' => '~Tbl,field,ID', '_' => time()]]);
- $this->assertEquals(JsonResponse::class, get_class($response));
- $this->assertTrue($response->getData());
+ $response = $this->route->convert('exists', array(array('foo' => 'Bar', 'params' => '~Tbl,field,ID', '_' => time())));
+ $this->assertInstanceOf('Illuminate\Http\JsonResponse', $response);
+ $this->assertAttributeEquals('true', 'data', $response);
}
public function testUnique()
{
- $this->encrypter->shouldReceive('decrypt')->times(2)->andReturnUsing(function ($data) {
+ $this->encrypter->expects($this->exactly(2))->method('decrypt')->willReturnCallback(function ($data) {
return empty($data) ? $data : substr($data, 1);
});
- $this->validator->shouldReceive('make')->with(['Foo' => 'Bar'], ['Foo' => ['unique:Tbl,field,Id,#Bar', 'active_url:anon']])->once()
- ->andReturn($validator = \Mockery::mock(Validator::class));
- $validator->shouldReceive('fails')->once()->andReturn(false);
+ $validator = $this->getMock('Illuminate\Validation\Validator', array('fails'), array(), '', false);
+ $this->validator->expects($this->once())->method('make')
+ ->with(array('Foo' => 'Bar'), array('Foo' => array('unique:Tbl,field,Id,#Bar', 'active_url:anon')))->willReturn($validator);
+ $validator->expects($this->once())->method('fails')->willReturn(false);
- $response = $this->route->convert('unique-active_url', [['Foo' => 'Bar', 'params' => ['~Tbl,field,Id,#Bar', '+anon'], '_' => time()]]);
- $this->assertEquals(JsonResponse::class, get_class($response));
- $this->assertTrue($response->getData());
+ $response = $this->route->convert('unique-active_url', array(array('Foo' => 'Bar', 'params' => array('~Tbl,field,Id,#Bar', '+anon'), '_' => time())));
+ $this->assertInstanceOf('Illuminate\Http\JsonResponse', $response);
+ $this->assertAttributeEquals('true', 'data', $response);
}
public function testExtend()
{
- $this->route->extend('unique', function ($parameters = []) {
+ $this->route->extend('unique', function ($parameters = array()) {
return $parameters;
});
- $this->assertEquals($params = ['foo' => '?', 'params' => '~'], $this->route->convert('Unique', [$params]));
+ $this->assertEquals($params = array('foo' => '?', 'params' => '~'), $this->route->convert('Unique', array($params)));
}
-
}
diff --git a/tests/Bllim/Laravalid/converter/RuleTest.php b/tests/Bllim/Laravalid/converter/RuleTest.php
index b551e96..f026149 100644
--- a/tests/Bllim/Laravalid/converter/RuleTest.php
+++ b/tests/Bllim/Laravalid/converter/RuleTest.php
@@ -1,12 +1,9 @@
encrypter = \Mockery::mock(Encrypter::class);
+ $this->encrypter = $this->getMock('Illuminate\Encryption\Encrypter', array('encrypt'), array(), '', false);
$this->rule = new JqueryValidation\Rule(static::routeUrl(), $this->encrypter);
}
- protected function tearDown()
- {
- parent::tearDown();
- \Mockery::close();
- }
-
protected static function routeUrl()
{
static $url;
if (!isset($url))
- $url = ['http://localhost:8000/laravalid', '/laravalid'][mt_rand(0, 1)];
+ $url = array_rand(array_flip(array('http://localhost:8000/laravalid', '/laravalid')));
return $url;
}
@@ -44,10 +35,10 @@ public function testExtend()
$this->rule->extend('foo', $func = function () {
return func_get_args();
});
- $this->assertEquals($params = ['Bar', ['zoo' => 'foo']], $this->rule->convert('Foo', $params));
+ $this->assertEquals($params = array('Bar', array('zoo' => 'foo')), $this->rule->convert('Foo', $params));
$this->rule->extend('ip', $func);
- $this->assertEquals($params = [['name' => 'Ip'], 'barFoo', 'string'], $this->rule->convert('IP', $params));
+ $this->assertEquals($params = array(array('name' => 'Ip'), 'barFoo', 'string'), $this->rule->convert('IP', $params));
}
/**
@@ -56,9 +47,9 @@ public function testExtend()
* @param array $expected
* @dataProvider dataForTestGenericRules
*/
- public function testGenericRules($name = '', $params = [], $expected = [])
+ public function testGenericRules($name = '', $params = array(), $expected = array())
{
- $value = call_user_func_array([$this->rule, strtolower($name)], $params);
+ $value = call_user_func_array(array($this->rule, strtolower($name)), $params);
$this->assertEquals($expected, $value);
$this->assertEquals($expected, $this->rule->convert($name, $params));
@@ -67,45 +58,45 @@ public function testGenericRules($name = '', $params = [], $expected = [])
public function dataForTestGenericRules()
{
return array(
- ['Email', [[], 'foo', 'string'], ['data-rule-email' => 'true']],
- ['required', [[], 'bar'], ['required' => 'required']],
- ['Url', [[], 'barFoo'], ['data-rule-url' => 'true']],
- ['integer', [[], 'bar_foo', 'numeric'], ['data-rule-integer' => 'true']],
- ['Numeric', [[], 'bar', 'numeric'], ['data-rule-number' => 'true']],
- ['Ip', [[], 'barFoo', 'string'], ['data-rule-ipv4' => 'true']],
- ['Same', [['parameters' => ['foo2']], 'bar'], ['data-rule-equalto' => ':input[name=\'foo2\']']],
- ['different', [['parameters' => ['foo2']], 'bar'], ['data-rule-notequalto' => ':input[name=\'foo2\']']],
+ array('Email', array(array(), 'foo', 'string'), array('data-rule-email' => 'true')),
+ array('required', array(array(), 'bar'), array('required' => 'required')),
+ array('Url', array(array(), 'barFoo'), array('data-rule-url' => 'true')),
+ array('integer', array(array(), 'bar_foo', 'numeric'), array('data-rule-integer' => 'true')),
+ array('Numeric', array(array(), 'bar', 'numeric'), array('data-rule-number' => 'true')),
+ array('Ip', array(array(), 'barFoo', 'string'), array('data-rule-ipv4' => 'true')),
+ array('Same', array(array('parameters' => array('foo2')), 'bar'), array('data-rule-equalto' => ':input[name=\'foo2\']')),
+ array('different', array(array('parameters' => array('foo2')), 'bar'), array('data-rule-notequalto' => ':input[name=\'foo2\']')),
//
- ['Regex', [['parameters' => ['/^\d+$/']], 'bar', 'string'], ['pattern' => '^\d+$']],
- ['regex', [['parameters' => ['^\w+$']], 'bar', 'string'], ['pattern' => '^\w+$']],
- ['Alpha', [[], 'foo', 'string'], ['pattern' => '^[A-Za-z_.-]+$']],
- ['alpha_Num', [[], 'foo', 'string'], ['pattern' => '^[A-Za-z0-9_.-]+$']],
+ array('Regex', array(array('parameters' => array('/^\d+$/')), 'bar', 'string'), array('pattern' => '^\d+$')),
+ array('regex', array(array('parameters' => array('^\w+$')), 'bar', 'string'), array('pattern' => '^\w+$')),
+ array('Alpha', array(array(), 'foo', 'string'), array('pattern' => '^[A-Za-z_.-]+$')),
+ array('alpha_Num', array(array(), 'foo', 'string'), array('pattern' => '^[A-Za-z0-9_.-]+$')),
//
- ['Image', [[], 'img', 'file'], ['accept' => 'image/*']],
- ['Date', [[], 'bar'], ['data-rule-date' => 'true']],
- ['before', [['parameters' => ['1900-01-01']], 'dt'], ['max' => '1900-01-01']],
- ['After', [['parameters' => ['2018-01-01']], 'dt'], ['min' => '2018-01-01']],
+ array('Image', array(array(), 'img', 'file'), array('accept' => 'image/*')),
+ array('Date', array(array(), 'bar'), array('data-rule-date' => 'true')),
+ array('before', array(array('parameters' => array('1900-01-01')), 'dt'), array('max' => '1900-01-01')),
+ array('After', array(array('parameters' => array('2018-01-01')), 'dt'), array('min' => '2018-01-01')),
//
- ['min', [['parameters' => ['1']], 'x', 'numeric'], ['min' => '1']],
- ['Min', [['parameters' => ['3']], 'x', 'string'], ['minlength' => '3']],
- ['min', [['parameters' => ['100']], 'x', 'file'], ['minlength' => '100']],// KB
- ['max', [['parameters' => ['10']], 'x', 'numeric'], ['max' => '10']],
- ['Max', [['parameters' => ['255']], 'x', 'string'], ['maxlength' => '255']],
- ['max', [['parameters' => ['200']], 'x', 'file'], ['maxlength' => '200']],// KB
- ['Between', [['parameters' => ['1', '10']], 'x', 'numeric'], ['data-rule-range' => '1,10']],
- ['between', [['parameters' => ['1', '100']], 'x', 'string'], ['data-rule-rangelength' => '1,100', 'maxlength' => '100']],
+ array('min', array(array('parameters' => array('1')), 'x', 'numeric'), array('min' => '1')),
+ array('Min', array(array('parameters' => array('3')), 'x', 'string'), array('minlength' => '3')),
+ array('min', array(array('parameters' => array('100')), 'x', 'file'), array('minlength' => '100')),// KB
+ array('max', array(array('parameters' => array('10')), 'x', 'numeric'), array('max' => '10')),
+ array('Max', array(array('parameters' => array('255')), 'x', 'string'), array('maxlength' => '255')),
+ array('max', array(array('parameters' => array('200')), 'x', 'file'), array('maxlength' => '200')),// KB
+ array('Between', array(array('parameters' => array('1', '10')), 'x', 'numeric'), array('data-rule-range' => '1,10')),
+ array('between', array(array('parameters' => array('1', '100')), 'x', 'string'), array('data-rule-rangelength' => '1,100', 'maxlength' => '100')),
//
- [
+ array(
'required_With',
- [['parameters' => ['f1', 'f2']], 'foo'],
- ['data-rule-required' => ':input:enabled[name=\'f1\']:not(:checkbox):not(:radio):filled,:input:enabled[name=\'f2\']:not(:checkbox):not(:radio):filled,input:enabled[name=\'f1\']:checked,input:enabled[name=\'f2\']:checked']
- ],
- [
+ array(array('parameters' => array('f1', 'f2')), 'foo'),
+ array('data-rule-required' => ':input:enabled[name=\'f1\']:not(:checkbox):not(:radio):filled,:input:enabled[name=\'f2\']:not(:checkbox):not(:radio):filled,input:enabled[name=\'f1\']:checked,input:enabled[name=\'f2\']:checked')
+ ),
+ array(
'Required_withOut',
- [['parameters' => ['f2']], 'foo'],
- ['data-rule-required' => ':input:enabled[name=\'f2\']:not(:checkbox):not(:radio):blank,input:enabled[name=\'f2\']:unchecked']
- ],
- ['Mimes', [['parameters' => ['csv', 'xls']], 'x', 'file'], ['accept' => '.csv,.xls']],
+ array(array('parameters' => array('f2')), 'foo'),
+ array('data-rule-required' => ':input:enabled[name=\'f2\']:not(:checkbox):not(:radio):blank,input:enabled[name=\'f2\']:unchecked')
+ ),
+ array('Mimes', array(array('parameters' => array('csv', 'xls')), 'x', 'file'), array('accept' => '.csv,.xls')),
);
}
@@ -115,12 +106,12 @@ public function dataForTestGenericRules()
* @param array $expected
* @dataProvider dataForTestRemoteRules
*/
- public function testRemoteRules($name = '', $params = [], $expected = [])
+ public function testRemoteRules($name = '', $params = array(), $expected = array())
{
- $this->encrypter->shouldReceive('encrypt')->andReturnUsing(function ($data) {
+ $this->encrypter->expects($this->any())->method('encrypt')->willReturnCallback(function ($data) {
return '~' . $data;
});
- $value = call_user_func_array([$this->rule, strtolower($name)], $params);
+ $value = call_user_func_array(array($this->rule, strtolower($name)), $params);
$this->assertEquals($expected, $value);
$this->assertEquals($expected, $this->rule->convert($name, $params));
@@ -129,10 +120,10 @@ public function testRemoteRules($name = '', $params = [], $expected = [])
public function dataForTestRemoteRules()
{
return array(
- ['Unique', [['parameters' => ['Tbl,f,Id,NULL']], 'foo'], ['data-rule-remote' => static::routeUrl() . '/unique?params=~Tbl,f,Id,NULL']],
- ['exists', [['parameters' => ['Tbl,f']], 'foo'], ['data-rule-remote' => static::routeUrl() . '/exists?params=~Tbl,f']],
- ['active_Url', [['parameters' => ['anon']], 'bar'], ['data-rule-remote' => static::routeUrl() . '/active_url?params=~anon']],
- ['Active_url', [['parameters' => []], 'bar'], ['data-rule-remote' => static::routeUrl() . '/active_url?params=']],
+ array('Unique', array(array('parameters' => array('Tbl,f,Id,NULL')), 'foo'), array('data-rule-remote' => static::routeUrl() . '/unique?params=~Tbl,f,Id,NULL')),
+ array('exists', array(array('parameters' => array('Tbl,f')), 'foo'), array('data-rule-remote' => static::routeUrl() . '/exists?params=~Tbl,f')),
+ array('active_Url', array(array('parameters' => array('anon')), 'bar'), array('data-rule-remote' => static::routeUrl() . '/active_url?params=~anon')),
+ array('Active_url', array(array('parameters' => array()), 'bar'), array('data-rule-remote' => static::routeUrl() . '/active_url?params=')),
);
}
@@ -144,7 +135,7 @@ public function dataForTestRemoteRules()
* @param array $expectedRule
* @dataProvider dataForMergeOutputAttributes
*/
- public function testMergeOutputAttributes($outputAttributes = [], $ruleAttributes = [], $inputType = null, $expectedOutput = [], $expectedRule = [])
+ public function testMergeOutputAttributes($outputAttributes = array(), $ruleAttributes = array(), $inputType = null, $expectedOutput = array(), $expectedRule = array())
{
$outputAttributes = $this->rule->mergeOutputAttributes($outputAttributes, $ruleAttributes, $inputType);
@@ -155,57 +146,56 @@ public function testMergeOutputAttributes($outputAttributes = [], $ruleAttribute
public function dataForMergeOutputAttributes()
{
return array(
- [[], [], null, [], []],
- [[], ['required'], 'text', ['required'], ['required']],
- [['pattern' => '*'], ['required'], '', ['pattern' => '*', 'required'], ['required']],
- [['pattern' => '*'], ['pattern' => '?'], '', ['pattern' => '*'], ['pattern' => '?']],
- [[], ['data-rule-number' => 'true'], 'number', [], ['data-rule-number' => 'true']],
- [['pattern' => '*'], ['data-rule-remote' => '/'], 'email', ['pattern' => '*', 'data-rule-remote' => '/'], ['data-rule-remote' => '/']],
- [
- ['data-rule-remote' => 'laravalid/active_url'],
- ['data-rule-remote' => '/'],
+ array(array(), array(), null, array(), array()),
+ array(array(), array('required'), 'text', array('required'), array('required')),
+ array(array('pattern' => '*'), array('required'), '', array('pattern' => '*', 'required'), array('required')),
+ array(array('pattern' => '*'), array('pattern' => '?'), '', array('pattern' => '*'), array('pattern' => '?')),
+ array(array(), array('data-rule-number' => 'true'), 'number', array(), array('data-rule-number' => 'true')),
+ array(array('pattern' => '*'), array('data-rule-remote' => '/'), 'email', array('pattern' => '*', 'data-rule-remote' => '/'), array('data-rule-remote' => '/')),
+ array(
+ array('data-rule-remote' => 'laravalid/active_url'),
+ array('data-rule-remote' => '/'),
'tel',
- ['data-rule-remote' => 'laravalid/active_url'],
- ['data-rule-remote' => '/']
- ],
+ array('data-rule-remote' => 'laravalid/active_url'),
+ array('data-rule-remote' => '/')
+ ),
//
- [
- ['data-rule-remote' => static::routeUrl() . '/exists?params=pE'],
- ['data-rule-remote' => static::routeUrl() . '/active_url?params='],
+ array(
+ array('data-rule-remote' => static::routeUrl() . '/exists?params=pE'),
+ array('data-rule-remote' => static::routeUrl() . '/active_url?params='),
'',
- ['data-rule-remote' => static::routeUrl() . '/exists-active_url?params[]=pE¶ms[]='],
- []
- ],
- [
- ['data-rule-remote' => static::routeUrl() . '/unique?params=pU', 'data-msg-remote' => '?'],
- ['data-rule-remote' => static::routeUrl() . '/active_url?params=anon'],
+ array('data-rule-remote' => static::routeUrl() . '/exists-active_url?params[]=pE¶ms[]='),
+ array()
+ ),
+ array(
+ array('data-rule-remote' => static::routeUrl() . '/unique?params=pU', 'data-msg-remote' => '?'),
+ array('data-rule-remote' => static::routeUrl() . '/active_url?params=anon'),
'text',
- ['data-rule-remote' => static::routeUrl() . '/unique-active_url?params[]=pU¶ms[]=anon'],
- []
- ],
- [
- ['data-rule-remote' => static::routeUrl() . '/unique?params=pU', 'data-msg-remote' => '?'],
- ['data-rule-remote' => static::routeUrl() . '/active_url?params=anon', 'data-rule-url' => 'true'],
+ array('data-rule-remote' => static::routeUrl() . '/unique-active_url?params[]=pU¶ms[]=anon'),
+ array()
+ ),
+ array(
+ array('data-rule-remote' => static::routeUrl() . '/unique?params=pU', 'data-msg-remote' => '?'),
+ array('data-rule-remote' => static::routeUrl() . '/active_url?params=anon', 'data-rule-url' => 'true'),
'url',
- ['data-rule-remote' => static::routeUrl() . '/unique-active_url?params[]=pU¶ms[]=anon'],
- ['data-rule-url' => 'true']
- ],
+ array('data-rule-remote' => static::routeUrl() . '/unique-active_url?params[]=pU¶ms[]=anon'),
+ array('data-rule-url' => 'true')
+ ),
//
- [
- ['data-rule-remote' => '{"url":"' . static::routeUrl() . '/exists?params=pE","data":{"bar":"foo"}}'],
- ['data-rule-remote' => static::routeUrl() . '/active_url?params='],
+ array(
+ array('data-rule-remote' => '{"url":"' . static::routeUrl() . '/exists?params=pE","data":{"bar":"foo"}}'),
+ array('data-rule-remote' => static::routeUrl() . '/active_url?params='),
'',
- ['data-rule-remote' => '{"url":"' . static::routeUrl() . '/exists-active_url?params[]=pE¶ms[]=","data":{"bar":"foo"}}'],
- []
- ],
- [
- ['data-rule-remote' => '{"url":"' . static::routeUrl() . '/exists?params=pE","data":{"bar":"foo"}}'],
- ['data-rule-remote' => '{"url":"' . static::routeUrl() . '/active_url?params=","data":{"foo":"X"}}'],
+ array('data-rule-remote' => '{"url":"' . static::routeUrl() . '/exists-active_url?params[]=pE¶ms[]=","data":{"bar":"foo"}}'),
+ array()
+ ),
+ array(
+ array('data-rule-remote' => '{"url":"' . static::routeUrl() . '/exists?params=pE","data":{"bar":"foo"}}'),
+ array('data-rule-remote' => '{"url":"' . static::routeUrl() . '/active_url?params=","data":{"foo":"X"}}'),
'',
- ['data-rule-remote' => '{"url":"' . static::routeUrl() . '/exists-active_url?params[]=pE¶ms[]=","data":{"bar":"foo","foo":"X"}}'],
- []
- ],
+ array('data-rule-remote' => '{"url":"' . static::routeUrl() . '/exists-active_url?params[]=pE¶ms[]=","data":{"bar":"foo","foo":"X"}}'),
+ array()
+ ),
);
}
-
}