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
cde97847
Commit
cde97847
authored
Jul 29, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BooleanValidatorTest
parent
376bddbe
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
0 deletions
+106
-0
BooleanValidatorTest.php
tests/unit/framework/validators/BooleanValidatorTest.php
+53
-0
DefaultValueValidatorTest.php
...s/unit/framework/validators/DefaultValueValidatorTest.php
+32
-0
FakedValidationModel.php
tests/unit/framework/validators/FakedValidationModel.php
+21
-0
No files found.
tests/unit/framework/validators/BooleanValidatorTest.php
0 → 100644
View file @
cde97847
<?php
namespace
yiiunit\framework\validators
;
use
yiiunit\framework\validators\FakedValidationModel
;
use
yii\validators\BooleanValidator
;
use
yiiunit\TestCase
;
require_once
__DIR__
.
'/FakedValidationModel.php'
;
/**
* BooleanValidatorTest
*/
class
BooleanValidatorTest
extends
TestCase
{
public
function
testValidateValue
()
{
$val
=
new
BooleanValidator
;
$this
->
assertTrue
(
$val
->
validateValue
(
true
));
$this
->
assertTrue
(
$val
->
validateValue
(
false
));
$this
->
assertTrue
(
$val
->
validateValue
(
'0'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'1'
));
$this
->
assertTrue
(
$val
->
validateValue
(
null
));
$this
->
assertTrue
(
$val
->
validateValue
(
array
()));
$val
->
strict
=
true
;
$this
->
assertTrue
(
$val
->
validateValue
(
'0'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'1'
));
$this
->
assertFalse
(
$val
->
validateValue
(
true
));
$this
->
assertFalse
(
$val
->
validateValue
(
false
));
$val
->
trueValue
=
true
;
$val
->
falseValue
=
false
;
$this
->
assertFalse
(
$val
->
validateValue
(
'0'
));
$this
->
assertFalse
(
$val
->
validateValue
(
array
()));
$this
->
assertTrue
(
$val
->
validateValue
(
true
));
$this
->
assertTrue
(
$val
->
validateValue
(
false
));
}
public
function
testValidateAttributeAndError
()
{
$obj
=
new
FakedValidationModel
;
$obj
->
attrA
=
true
;
$obj
->
attrB
=
'1'
;
$obj
->
attrC
=
'0'
;
$obj
->
attrD
=
array
();
$val
=
new
BooleanValidator
;
$val
->
validateAttribute
(
$obj
,
'attrA'
);
$this
->
assertFalse
(
isset
(
$obj
->
errors
[
'attrA'
]));
$val
->
validateAttribute
(
$obj
,
'attrC'
);
$this
->
assertFalse
(
isset
(
$obj
->
errors
[
'attrC'
]));
$val
->
strict
=
true
;
$val
->
validateAttribute
(
$obj
,
'attrB'
);
$this
->
assertFalse
(
isset
(
$obj
->
errors
[
'attrB'
]));
$val
->
validateAttribute
(
$obj
,
'attrD'
);
$this
->
assertTrue
(
isset
(
$obj
->
errors
[
'attrD'
]));
}
}
tests/unit/framework/validators/DefaultValueValidatorTest.php
0 → 100644
View file @
cde97847
<?php
namespace
yiiunit\framework\validators
;
use
yii\validators\DefaultValueValidator
;
use
yiiunit\TestCase
;
/**
* DefaultValueValidatorTest
*/
class
DefaultValueValidatorTest
extends
TestCase
{
public
function
testValidateAttribute
()
{
$val
=
new
DefaultValueValidator
;
$val
->
value
=
'test_value'
;
$obj
=
new
\stdclass
;
$obj
->
attrA
=
'attrA'
;
$obj
->
attrB
=
null
;
$obj
->
attrC
=
''
;
// original values to chek which attritubes where modified
$objB
=
clone
$obj
;
$val
->
validateAttribute
(
$obj
,
'attrB'
);
$this
->
assertEquals
(
$val
->
value
,
$obj
->
attrB
);
$this
->
assertEquals
(
$objB
->
attrA
,
$obj
->
attrA
);
$val
->
value
=
'new_test_value'
;
$obj
=
clone
$objB
;
// get clean object
$val
->
validateAttribute
(
$obj
,
'attrC'
);
$this
->
assertEquals
(
'new_test_value'
,
$obj
->
attrC
);
$this
->
assertEquals
(
$objB
->
attrA
,
$obj
->
attrA
);
$val
->
validateAttribute
(
$obj
,
'attrA'
);
$this
->
assertEquals
(
$objB
->
attrA
,
$obj
->
attrA
);
}
}
tests/unit/framework/validators/FakedValidationModel.php
0 → 100644
View file @
cde97847
<?php
namespace
yiiunit\framework\validators
;
/**
* @codeCoverageIgnore
*/
class
FakedValidationModel
{
public
$errors
=
array
();
public
function
getAttributeLabel
(
$attr
)
{
return
'Attr-Label: '
.
$attr
;
}
public
function
addError
(
$attribute
,
$message
)
{
$this
->
errors
[
$attribute
]
=
$message
;
}
}
\ 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