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
8e48f01c
Commit
8e48f01c
authored
Aug 14, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RegularExpressionValidatorTest
parent
02c92fea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
RegularExpressionValidatorTest.php
...t/framework/validators/RegularExpressionValidatorTest.php
+49
-0
No files found.
tests/unit/framework/validators/RegularExpressionValidatorTest.php
0 → 100644
View file @
8e48f01c
<?php
namespace
yiiunit\framework\validators
;
use
yii\validators\RegularExpressionValidator
;
use
yiiunit\data\validators\models\FakedValidationModel
;
use
yiiunit\TestCase
;
class
RegularExpressionValidatorTest
extends
TestCase
{
public
function
testValidateValue
()
{
$val
=
new
RegularExpressionValidator
(
array
(
'pattern'
=>
'/^[a-zA-Z0-9](\.)?([^\/]*)$/m'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'b.4'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'b./'
));
$this
->
assertFalse
(
$val
->
validateValue
(
array
(
'a'
,
'b'
)));
$val
->
not
=
true
;
$this
->
assertFalse
(
$val
->
validateValue
(
'b.4'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'b./'
));
$this
->
assertFalse
(
$val
->
validateValue
(
array
(
'a'
,
'b'
)));
}
public
function
testValidateAttribute
()
{
$val
=
new
RegularExpressionValidator
(
array
(
'pattern'
=>
'/^[a-zA-Z0-9](\.)?([^\/]*)$/m'
));
$m
=
FakedValidationModel
::
createWithAttributes
(
array
(
'attr_reg1'
=>
'b.4'
));
$val
->
validateAttribute
(
$m
,
'attr_reg1'
);
$this
->
assertFalse
(
$m
->
hasErrors
(
'attr_reg1'
));
$m
->
attr_reg1
=
'b./'
;
$val
->
validateAttribute
(
$m
,
'attr_reg1'
);
$this
->
assertTrue
(
$m
->
hasErrors
(
'attr_reg1'
));
}
public
function
testMessageSetOnInit
()
{
$val
=
new
RegularExpressionValidator
(
array
(
'pattern'
=>
'/^[a-zA-Z0-9](\.)?([^\/]*)$/m'
));
$this
->
assertTrue
(
is_string
(
$val
->
message
));
}
public
function
testInitException
()
{
$this
->
setExpectedException
(
'yii\base\InvalidConfigException'
);
$val
=
new
RegularExpressionValidator
();
$val
->
validateValue
(
'abc'
);
}
}
\ 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