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
202e3ae0
Commit
202e3ae0
authored
Mar 16, 2014
by
Zhandos Nuftiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed typo in FilterValidator for skipping array values.
parent
76a7beb6
Show 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 @
202e3ae0
...
@@ -67,7 +67,7 @@ class FilterValidator extends Validator
...
@@ -67,7 +67,7 @@ class FilterValidator extends Validator
public
function
validateAttribute
(
$object
,
$attribute
)
public
function
validateAttribute
(
$object
,
$attribute
)
{
{
$value
=
$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
);
$object
->
$attribute
=
call_user_func
(
$this
->
filter
,
$value
);
}
}
}
}
...
...
tests/unit/framework/validators/FilterValidatorTest.php
View file @
202e3ae0
...
@@ -26,7 +26,9 @@ class FilterValidatorTest extends TestCase
...
@@ -26,7 +26,9 @@ class FilterValidatorTest extends TestCase
'attr_one'
=>
' to be trimmed '
,
'attr_one'
=>
' to be trimmed '
,
'attr_two'
=>
'set this to null'
,
'attr_two'
=>
'set this to null'
,
'attr_empty1'
=>
''
,
'attr_empty1'
=>
''
,
'attr_empty2'
=>
null
'attr_empty2'
=>
null
,
'attr_array'
=>
[
'Maria'
,
'Anna'
,
'Elizabeth'
],
'attr_array_skipped'
=>
[
'John'
,
'Bill'
]
]);
]);
$val
=
new
FilterValidator
([
'filter'
=>
'trim'
]);
$val
=
new
FilterValidator
([
'filter'
=>
'trim'
]);
$val
->
validateAttribute
(
$m
,
'attr_one'
);
$val
->
validateAttribute
(
$m
,
'attr_one'
);
...
@@ -42,6 +44,16 @@ class FilterValidatorTest extends TestCase
...
@@ -42,6 +44,16 @@ class FilterValidatorTest extends TestCase
$val
->
skipOnEmpty
=
true
;
$val
->
skipOnEmpty
=
true
;
$val
->
validateAttribute
(
$m
,
'attr_empty2'
);
$val
->
validateAttribute
(
$m
,
'attr_empty2'
);
$this
->
assertNotNull
(
$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
)
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