Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
83a63f23
Commit
83a63f23
authored
Apr 23, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed wrong client validation issue in numbervalidator
fixes #3118
parent
4f6e1d30
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
101 additions
and
6 deletions
+101
-6
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
NumberValidator.php
framework/validators/NumberValidator.php
+6
-2
BooleanValidatorTest.php
tests/unit/framework/validators/BooleanValidatorTest.php
+1
-1
CompareValidatorTest.php
tests/unit/framework/validators/CompareValidatorTest.php
+3
-0
DateValidatorTest.php
tests/unit/framework/validators/DateValidatorTest.php
+3
-0
DefaultValueValidatorTest.php
...s/unit/framework/validators/DefaultValueValidatorTest.php
+1
-1
EmailValidatorTest.php
tests/unit/framework/validators/EmailValidatorTest.php
+0
-1
ExistValidatorPostgresTest.php
.../ExistValidatorDriverTests/ExistValidatorPostgresTest.php
+3
-0
ExistValidatorSQliteTest.php
...rs/ExistValidatorDriverTests/ExistValidatorSQliteTest.php
+3
-0
ExistValidatorTest.php
tests/unit/framework/validators/ExistValidatorTest.php
+3
-0
FileValidatorTest.php
tests/unit/framework/validators/FileValidatorTest.php
+3
-0
FilterValidatorTest.php
tests/unit/framework/validators/FilterValidatorTest.php
+3
-0
NumberValidatorTest.php
tests/unit/framework/validators/NumberValidatorTest.php
+46
-0
RangeValidatorTest.php
tests/unit/framework/validators/RangeValidatorTest.php
+3
-0
RegularExpressionValidatorTest.php
...t/framework/validators/RegularExpressionValidatorTest.php
+3
-0
RequiredValidatorTest.php
tests/unit/framework/validators/RequiredValidatorTest.php
+3
-0
StringValidatorTest.php
tests/unit/framework/validators/StringValidatorTest.php
+3
-0
UniqueValidatorPostgresTest.php
...niqueValidatorDriverTests/UniqueValidatorPostgresTest.php
+3
-0
UniqueValidatorSQliteTest.php
.../UniqueValidatorDriverTests/UniqueValidatorSQliteTest.php
+3
-0
UniqueValidatorTest.php
tests/unit/framework/validators/UniqueValidatorTest.php
+3
-0
UrlValidatorTest.php
tests/unit/framework/validators/UrlValidatorTest.php
+1
-1
ValidatorTest.php
tests/unit/framework/validators/ValidatorTest.php
+3
-0
No files found.
framework/CHANGELOG.md
View file @
83a63f23
...
...
@@ -11,6 +11,7 @@ Yii Framework 2 Change Log
-
Bug #3042:
`yii\widgets\Pjax`
should end application right after it finishes responding to a pjax request (qiangxue)
-
Bug #3066:
`yii\db\mssql\Schema::getTableSchema()`
should return null when the table does not exist (qiangxue)
-
Bug #3091: Fixed inconsistent treatment of
`Widget::run()`
when a widget is used as a container and as a self-contained object (qiangxue)
-
Bug #3118: Ensure client validation has the same behavior as server side validation for number validator (cebe)
-
Bug #3121:
`yii\base\Application::bootstrap`
may fail to load some components if they are specified as class names (qiangxue)
-
Bug #3125:
`yii\console\controllers\AssetController`
now respects data URL resources (klimov-paul)
-
Bug #3128: Fixed the bug that
`defaultRoles`
set in RBAC manager was not working as specified (qiangxue)
...
...
framework/validators/NumberValidator.php
View file @
83a63f23
...
...
@@ -128,14 +128,18 @@ class NumberValidator extends Validator
];
if
(
$this
->
min
!==
null
)
{
$options
[
'min'
]
=
$this
->
min
;
// ensure numeric value to make javascript comparison equal to PHP comparison
// https://github.com/yiisoft/yii2/issues/3118
$options
[
'min'
]
=
is_string
(
$this
->
min
)
?
(
float
)
$this
->
min
:
$this
->
min
;
$options
[
'tooSmall'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
tooSmall
,
[
'attribute'
=>
$label
,
'min'
=>
$this
->
min
,
],
Yii
::
$app
->
language
);
}
if
(
$this
->
max
!==
null
)
{
$options
[
'max'
]
=
$this
->
max
;
// ensure numeric value to make javascript comparison equal to PHP comparison
// https://github.com/yiisoft/yii2/issues/3118
$options
[
'max'
]
=
is_string
(
$this
->
max
)
?
(
float
)
$this
->
max
:
$this
->
max
;
$options
[
'tooBig'
]
=
Yii
::
$app
->
getI18n
()
->
format
(
$this
->
tooBig
,
[
'attribute'
=>
$label
,
'max'
=>
$this
->
max
,
...
...
tests/unit/framework/validators/BooleanValidatorTest.php
View file @
83a63f23
...
...
@@ -6,7 +6,7 @@ use yii\validators\BooleanValidator;
use
yiiunit\TestCase
;
/**
*
BooleanValidatorTest
*
@group validators
*/
class
BooleanValidatorTest
extends
TestCase
{
...
...
tests/unit/framework/validators/CompareValidatorTest.php
View file @
83a63f23
...
...
@@ -6,6 +6,9 @@ use yii\validators\CompareValidator;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
CompareValidatorTest
extends
TestCase
{
protected
function
setUp
()
...
...
tests/unit/framework/validators/DateValidatorTest.php
View file @
83a63f23
...
...
@@ -7,6 +7,9 @@ use yii\validators\DateValidator;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
DateValidatorTest
extends
TestCase
{
protected
function
setUp
()
...
...
tests/unit/framework/validators/DefaultValueValidatorTest.php
View file @
83a63f23
...
...
@@ -6,7 +6,7 @@ use yii\validators\DefaultValueValidator;
use
yiiunit\TestCase
;
/**
*
DefaultValueValidatorTest
*
@group validators
*/
class
DefaultValueValidatorTest
extends
TestCase
{
...
...
tests/unit/framework/validators/EmailValidatorTest.php
View file @
83a63f23
...
...
@@ -6,7 +6,6 @@ use yiiunit\data\validators\models\FakedValidationModel;
use
yiiunit\TestCase
;
/**
* EmailValidatorTest
* @group validators
*/
class
EmailValidatorTest
extends
TestCase
...
...
tests/unit/framework/validators/ExistValidatorDriverTests/ExistValidatorPostgresTest.php
View file @
83a63f23
...
...
@@ -3,6 +3,9 @@ namespace yiiunit\framework\validators\ExistValidatorDriverTests;
use
yiiunit\framework\validators\ExistValidatorTest
;
/**
* @group validators
*/
class
ExistValidatorPostgresTest
extends
ExistValidatorTest
{
protected
$driverName
=
'pgsql'
;
...
...
tests/unit/framework/validators/ExistValidatorDriverTests/ExistValidatorSQliteTest.php
View file @
83a63f23
...
...
@@ -3,6 +3,9 @@ namespace yiiunit\framework\validators\ExistValidatorDriverTests;
use
yiiunit\framework\validators\ExistValidatorTest
;
/**
* @group validators
*/
class
ExistValidatorSQliteTest
extends
ExistValidatorTest
{
protected
$driverName
=
'sqlite'
;
...
...
tests/unit/framework/validators/ExistValidatorTest.php
View file @
83a63f23
...
...
@@ -12,6 +12,9 @@ use yiiunit\data\validators\models\ValidatorTestMainModel;
use
yiiunit\data\validators\models\ValidatorTestRefModel
;
use
yiiunit\framework\db\DatabaseTestCase
;
/**
* @group validators
*/
class
ExistValidatorTest
extends
DatabaseTestCase
{
protected
$driverName
=
'mysql'
;
...
...
tests/unit/framework/validators/FileValidatorTest.php
View file @
83a63f23
...
...
@@ -8,6 +8,9 @@ use Yii;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
FileValidatorTest
extends
TestCase
{
public
function
setUp
()
...
...
tests/unit/framework/validators/FilterValidatorTest.php
View file @
83a63f23
...
...
@@ -6,6 +6,9 @@ use yii\validators\FilterValidator;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
FilterValidatorTest
extends
TestCase
{
protected
function
setUp
()
...
...
tests/unit/framework/validators/NumberValidatorTest.php
View file @
83a63f23
...
...
@@ -3,9 +3,13 @@
namespace
yiiunit\framework\validators
;
use
yii\validators\NumberValidator
;
use
yii\web\View
;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
NumberValidatorTest
extends
TestCase
{
protected
function
setUp
()
...
...
@@ -162,4 +166,46 @@ class NumberValidatorTest extends TestCase
$msgs
=
$model
->
getErrors
(
'attr_number'
);
$this
->
assertSame
(
'attr_number is to small.'
,
$msgs
[
0
]);
}
/**
* https://github.com/yiisoft/yii2/issues/3118
*/
public
function
testClientValidateComparison
()
{
$val
=
new
NumberValidator
([
'min'
=>
5
,
'max'
=>
10
,
]);
$model
=
new
FakedValidationModel
();
$js
=
$val
->
clientValidateAttribute
(
$model
,
'attr_number'
,
new
View
([
'assetBundles'
=>
[
'yii\validators\ValidationAsset'
=>
true
]]));
$this
->
assertContains
(
'"min":5'
,
$js
);
$this
->
assertContains
(
'"max":10'
,
$js
);
$val
=
new
NumberValidator
([
'min'
=>
'5'
,
'max'
=>
'10'
,
]);
$model
=
new
FakedValidationModel
();
$js
=
$val
->
clientValidateAttribute
(
$model
,
'attr_number'
,
new
View
([
'assetBundles'
=>
[
'yii\validators\ValidationAsset'
=>
true
]]));
$this
->
assertContains
(
'"min":5'
,
$js
);
$this
->
assertContains
(
'"max":10'
,
$js
);
$val
=
new
NumberValidator
([
'min'
=>
5.65
,
'max'
=>
13.37
,
]);
$model
=
new
FakedValidationModel
();
$js
=
$val
->
clientValidateAttribute
(
$model
,
'attr_number'
,
new
View
([
'assetBundles'
=>
[
'yii\validators\ValidationAsset'
=>
true
]]));
$this
->
assertContains
(
'"min":5.65'
,
$js
);
$this
->
assertContains
(
'"max":13.37'
,
$js
);
$val
=
new
NumberValidator
([
'min'
=>
'5.65'
,
'max'
=>
'13.37'
,
]);
$model
=
new
FakedValidationModel
();
$js
=
$val
->
clientValidateAttribute
(
$model
,
'attr_number'
,
new
View
([
'assetBundles'
=>
[
'yii\validators\ValidationAsset'
=>
true
]]));
$this
->
assertContains
(
'"min":5.65'
,
$js
);
$this
->
assertContains
(
'"max":13.37'
,
$js
);
}
}
tests/unit/framework/validators/RangeValidatorTest.php
View file @
83a63f23
...
...
@@ -6,6 +6,9 @@ use yii\validators\RangeValidator;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
RangeValidatorTest
extends
TestCase
{
protected
function
setUp
()
...
...
tests/unit/framework/validators/RegularExpressionValidatorTest.php
View file @
83a63f23
...
...
@@ -6,6 +6,9 @@ use yii\validators\RegularExpressionValidator;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
RegularExpressionValidatorTest
extends
TestCase
{
protected
function
setUp
()
...
...
tests/unit/framework/validators/RequiredValidatorTest.php
View file @
83a63f23
...
...
@@ -5,6 +5,9 @@ use yii\validators\RequiredValidator;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
RequiredValidatorTest
extends
TestCase
{
protected
function
setUp
()
...
...
tests/unit/framework/validators/StringValidatorTest.php
View file @
83a63f23
...
...
@@ -6,6 +6,9 @@ use yii\validators\StringValidator;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
StringValidatorTest
extends
TestCase
{
public
function
setUp
()
...
...
tests/unit/framework/validators/UniqueValidatorDriverTests/UniqueValidatorPostgresTest.php
View file @
83a63f23
...
...
@@ -4,6 +4,9 @@ namespace yiiunit\framework\validators\UniqueValidatorDriverTests;
use
yiiunit\framework\validators\UniqueValidatorTest
;
/**
* @group validators
*/
class
UniqueValidatorPostgresTest
extends
UniqueValidatorTest
{
protected
$driverName
=
'pgsql'
;
...
...
tests/unit/framework/validators/UniqueValidatorDriverTests/UniqueValidatorSQliteTest.php
View file @
83a63f23
...
...
@@ -4,6 +4,9 @@ namespace yiiunit\framework\validators\UniqueValidatorDriverTests;
use
yiiunit\framework\validators\UniqueValidatorTest
;
/**
* @group validators
*/
class
UniqueValidatorSQliteTest
extends
UniqueValidatorTest
{
protected
$driverName
=
'sqlite'
;
...
...
tests/unit/framework/validators/UniqueValidatorTest.php
View file @
83a63f23
...
...
@@ -12,6 +12,9 @@ use yiiunit\data\validators\models\ValidatorTestMainModel;
use
yiiunit\data\validators\models\ValidatorTestRefModel
;
use
yiiunit\framework\db\DatabaseTestCase
;
/**
* @group validators
*/
class
UniqueValidatorTest
extends
DatabaseTestCase
{
protected
$driverName
=
'mysql'
;
...
...
tests/unit/framework/validators/UrlValidatorTest.php
View file @
83a63f23
...
...
@@ -7,7 +7,7 @@ use yii\validators\UrlValidator;
use
yiiunit\TestCase
;
/**
*
UrlValidatorTest
*
@group validators
*/
class
UrlValidatorTest
extends
TestCase
{
...
...
tests/unit/framework/validators/ValidatorTest.php
View file @
83a63f23
...
...
@@ -9,6 +9,9 @@ use yiiunit\data\validators\models\FakedValidationModel;
use
yiiunit\data\validators\TestValidator
;
use
yiiunit\TestCase
;
/**
* @group validators
*/
class
ValidatorTest
extends
TestCase
{
protected
function
setUp
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment