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
777ff792
Commit
777ff792
authored
Jul 31, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DateValidatorTest
parent
1c6b64e7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
DateValidatorTest.php
tests/unit/framework/validators/DateValidatorTest.php
+62
-0
No files found.
tests/unit/framework/validators/DateValidatorTest.php
0 → 100644
View file @
777ff792
<?php
namespace
yiiunit\framework\validators
;
use
DateTime
;
use
yii\validators\DateValidator
;
use
yiiunit\TestCase
;
require_once
__DIR__
.
'/FakedValidationModel.php'
;
class
DateValidatorTest
extends
TestCase
{
public
function
testEnsureMessageIsSet
()
{
$val
=
new
DateValidator
;
$this
->
assertTrue
(
$val
->
message
!==
null
&&
strlen
(
$val
->
message
)
>
1
);
}
public
function
testValidateValue
()
{
$val
=
new
DateValidator
;
$this
->
assertTrue
(
$val
->
validateValue
(
'2013-09-13'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'31.7.2013'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'31-7-2013'
));
$this
->
assertFalse
(
$val
->
validateValue
(
time
()));
$val
->
format
=
'U'
;
$this
->
assertTrue
(
$val
->
validateValue
(
time
()));
$val
->
format
=
'd.m.Y'
;
$this
->
assertTrue
(
$val
->
validateValue
(
'31.7.2013'
));
$val
->
format
=
'Y-m-!d H:i:s'
;
$this
->
assertTrue
(
$val
->
validateValue
(
'2009-02-15 15:16:17'
));
}
public
function
testValidateAttribute
()
{
// error-array-add
$val
=
new
DateValidator
;
$model
=
new
FakedValidationModel
;
$model
->
attr_date
=
'2013-09-13'
;
$val
->
validateAttribute
(
$model
,
'attr_date'
);
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_date'
));
$model
=
new
FakedValidationModel
;
$model
->
attr_date
=
'1375293913'
;
$val
->
validateAttribute
(
$model
,
'attr_date'
);
$this
->
assertTrue
(
$model
->
hasErrors
(
'attr_date'
));
//// timestamp attribute
$val
=
new
DateValidator
(
array
(
'timestampAttribute'
=>
'attr_timestamp'
));
$model
=
new
FakedValidationModel
;
$model
->
attr_date
=
'2013-09-13'
;
$model
->
attr_timestamp
=
true
;
$val
->
validateAttribute
(
$model
,
'attr_date'
);
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_date'
));
$this
->
assertFalse
(
$model
->
hasErrors
(
'attr_timestamp'
));
$this
->
assertEquals
(
DateTime
::
createFromFormat
(
$val
->
format
,
'2013-09-13'
)
->
getTimestamp
(),
$model
->
attr_timestamp
);
}
}
\ 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