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
3469b2cb
Commit
3469b2cb
authored
Aug 22, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RangeValidator tests.
parent
0c45765e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
RangeValidatorTest.php
tests/unit/framework/validators/RangeValidatorTest.php
+71
-0
No files found.
tests/unit/framework/validators/RangeValidatorTest.php
0 → 100644
View file @
3469b2cb
<?php
namespace
yiiunit\framework\validators
;
use
yii\validators\RangeValidator
;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
class
RangeValidatorTest
extends
TestCase
{
public
function
testInitException
()
{
$this
->
setExpectedException
(
'yii\base\InvalidConfigException'
,
'The "range" property must be set.'
);
$val
=
new
RangeValidator
(
array
(
'range'
=>
'not an array'
));
}
public
function
testAssureMessageSetOnInit
()
{
$val
=
new
RangeValidator
(
array
(
'range'
=>
array
()));
$this
->
assertTrue
(
is_string
(
$val
->
message
));
}
public
function
testValidateValue
()
{
$val
=
new
RangeValidator
(
array
(
'range'
=>
range
(
1
,
10
,
1
)));
$this
->
assertTrue
(
$val
->
validateValue
(
1
));
$this
->
assertFalse
(
$val
->
validateValue
(
0
));
$this
->
assertFalse
(
$val
->
validateValue
(
11
));
$this
->
assertFalse
(
$val
->
validateValue
(
5.5
));
$this
->
assertTrue
(
$val
->
validateValue
(
10
));
$this
->
assertTrue
(
$val
->
validateValue
(
"10"
));
$this
->
assertTrue
(
$val
->
validateValue
(
"5"
));
}
public
function
testValidateValueStrict
()
{
$val
=
new
RangeValidator
(
array
(
'range'
=>
range
(
1
,
10
,
1
),
'strict'
=>
true
));
$this
->
assertTrue
(
$val
->
validateValue
(
1
));
$this
->
assertTrue
(
$val
->
validateValue
(
5
));
$this
->
assertTrue
(
$val
->
validateValue
(
10
));
$this
->
assertFalse
(
$val
->
validateValue
(
"1"
));
$this
->
assertFalse
(
$val
->
validateValue
(
"10"
));
$this
->
assertFalse
(
$val
->
validateValue
(
"5.5"
));
}
public
function
testValidateValueNot
()
{
$val
=
new
RangeValidator
(
array
(
'range'
=>
range
(
1
,
10
,
1
),
'not'
=>
true
));
$this
->
assertFalse
(
$val
->
validateValue
(
1
));
$this
->
assertTrue
(
$val
->
validateValue
(
0
));
$this
->
assertTrue
(
$val
->
validateValue
(
11
));
$this
->
assertTrue
(
$val
->
validateValue
(
5.5
));
$this
->
assertFalse
(
$val
->
validateValue
(
10
));
$this
->
assertFalse
(
$val
->
validateValue
(
"10"
));
$this
->
assertFalse
(
$val
->
validateValue
(
"5"
));
}
public
function
testValidateAttribute
()
{
$val
=
new
RangeValidator
(
array
(
'range'
=>
range
(
1
,
10
,
1
)));
$m
=
FakedValidationModel
::
createWithAttributes
(
array
(
'attr_r1'
=>
5
,
'attr_r2'
=>
999
));
$val
->
validateAttribute
(
$m
,
'attr_r1'
);
$this
->
assertFalse
(
$m
->
hasErrors
());
$val
->
validateAttribute
(
$m
,
'attr_r2'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'attr_r2'
));
$err
=
$m
->
getErrors
(
'attr_r2'
);
$this
->
assertTrue
(
stripos
(
$err
[
0
],
'attr_r2'
)
!==
false
);
}
}
\ 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