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
7910cc11
Commit
7910cc11
authored
Mar 16, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2767 from ZhandosKz/filter_validator_skip_on_array
Fixed typo in FilterValidator for skipping array values.
parents
76a7beb6
202e3ae0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
FilterValidator.php
framework/validators/FilterValidator.php
+1
-1
FilterValidatorTest.php
tests/unit/framework/validators/FilterValidatorTest.php
+13
-1
No files found.
framework/validators/FilterValidator.php
View file @
7910cc11
...
...
@@ -67,7 +67,7 @@ class FilterValidator extends Validator
public
function
validateAttribute
(
$object
,
$attribute
)
{
$value
=
$object
->
$attribute
;
if
(
$this
->
skipOnArray
||
!
is_array
(
$value
))
{
if
(
!
$this
->
skipOnArray
||
!
is_array
(
$value
))
{
$object
->
$attribute
=
call_user_func
(
$this
->
filter
,
$value
);
}
}
...
...
tests/unit/framework/validators/FilterValidatorTest.php
View file @
7910cc11
...
...
@@ -26,7 +26,9 @@ class FilterValidatorTest extends TestCase
'attr_one'
=>
' to be trimmed '
,
'attr_two'
=>
'set this to null'
,
'attr_empty1'
=>
''
,
'attr_empty2'
=>
null
'attr_empty2'
=>
null
,
'attr_array'
=>
[
'Maria'
,
'Anna'
,
'Elizabeth'
],
'attr_array_skipped'
=>
[
'John'
,
'Bill'
]
]);
$val
=
new
FilterValidator
([
'filter'
=>
'trim'
]);
$val
->
validateAttribute
(
$m
,
'attr_one'
);
...
...
@@ -42,6 +44,16 @@ class FilterValidatorTest extends TestCase
$val
->
skipOnEmpty
=
true
;
$val
->
validateAttribute
(
$m
,
'attr_empty2'
);
$this
->
assertNotNull
(
$m
->
attr_empty2
);
$val
->
filter
=
function
(
$value
)
{
return
implode
(
','
,
$value
);
};
$val
->
skipOnArray
=
false
;
$val
->
validateAttribute
(
$m
,
'attr_array'
);
$this
->
assertSame
(
'Maria,Anna,Elizabeth'
,
$m
->
attr_array
);
$val
->
skipOnArray
=
true
;
$val
->
validateAttribute
(
$m
,
'attr_array_skipped'
);
$this
->
assertSame
([
'John'
,
'Bill'
],
$m
->
attr_array_skipped
);
}
public
function
notToBeNull
(
$value
)
...
...
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