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
7d5bb082
Commit
7d5bb082
authored
Aug 23, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FilterValidator test
parent
3b07e4af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
FilterValidatorTest.php
tests/unit/framework/validators/FilterValidatorTest.php
+47
-0
No files found.
tests/unit/framework/validators/FilterValidatorTest.php
0 → 100644
View file @
7d5bb082
<?php
namespace
yiiunit\framework\validators
;
use
yii\validators\FilterValidator
;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
class
FilterValidatorTest
extends
TestCase
{
public
function
testAssureExceptionOnInit
()
{
$this
->
setExpectedException
(
'yii\base\InvalidConfigException'
);
$val
=
new
FilterValidator
();
}
public
function
testValidateAttribute
()
{
$m
=
FakedValidationModel
::
createWithAttributes
(
array
(
'attr_one'
=>
' to be trimmed '
,
'attr_two'
=>
'set this to null'
,
'attr_empty1'
=>
''
,
'attr_empty2'
=>
null
));
$val
=
new
FilterValidator
(
array
(
'filter'
=>
'trim'
));
$val
->
validateAttribute
(
$m
,
'attr_one'
);
$this
->
assertSame
(
'to be trimmed'
,
$m
->
attr_one
);
$val
->
filter
=
function
(
$value
)
{
return
null
;
};
$val
->
validateAttribute
(
$m
,
'attr_two'
);
$this
->
assertNull
(
$m
->
attr_two
);
$val
->
filter
=
array
(
$this
,
'notToBeNull'
);
$val
->
validateAttribute
(
$m
,
'attr_empty1'
);
$this
->
assertSame
(
$this
->
notToBeNull
(
''
),
$m
->
attr_empty1
);
$val
->
skipOnEmpty
=
true
;
$val
->
validateAttribute
(
$m
,
'attr_empty2'
);
$this
->
assertNotNull
(
$m
->
attr_empty2
);
}
public
function
notToBeNull
(
$value
)
{
return
'not null'
;
}
}
\ No newline at end of file
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