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
99238886
Commit
99238886
authored
Mar 29, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More Model tests
parent
7b73fdff
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
2 deletions
+71
-2
InvalidRulesModel.php
tests/unit/data/base/InvalidRulesModel.php
+17
-0
Singer.php
tests/unit/data/base/Singer.php
+22
-0
Speaker.php
tests/unit/data/base/Speaker.php
+1
-2
ModelTest.php
tests/unit/framework/base/ModelTest.php
+31
-0
No files found.
tests/unit/data/base/InvalidRulesModel.php
0 → 100644
View file @
99238886
<?php
namespace
yiiunit\data\base
;
use
yii\base\Model
;
/**
* InvalidRulesModel
*/
class
InvalidRulesModel
extends
Model
{
public
function
rules
()
{
return
array
(
array
(
'test'
),
);
}
}
tests/unit/data/base/Singer.php
0 → 100644
View file @
99238886
<?php
namespace
yiiunit\data\base
;
use
yii\base\Model
;
/**
* Singer
*/
class
Singer
extends
Model
{
public
$fistName
;
public
$lastName
;
public
function
rules
()
{
return
array
(
array
(
'lastName'
,
'default'
,
'value'
=>
'Lennon'
),
array
(
'lastName'
,
'required'
),
array
(
'underscore_style'
,
'yii\validators\CaptchaValidator'
),
);
}
}
\ No newline at end of file
tests/unit/data/base/Speaker.php
View file @
99238886
<?php
namespace
yiiunit\data\base
;
use
yii\base\Model
;
/**
* Speaker
*/
use
yii\base\Model
;
class
Speaker
extends
Model
{
public
$firstName
;
...
...
tests/unit/framework/base/ModelTest.php
View file @
99238886
<?php
namespace
yiiunit\framework\base
;
use
yii\base\Model
;
use
yiiunit\TestCase
;
use
yiiunit\data\base\Speaker
;
use
yiiunit\data\base\Singer
;
use
yiiunit\data\base\InvalidRulesModel
;
/**
* ModelTest
...
...
@@ -169,4 +172,32 @@ class ModelTest extends TestCase
$this
->
assertNull
(
$speaker
[
'firstName'
]);
$this
->
assertFalse
(
isset
(
$speaker
[
'firstName'
]));
}
public
function
testDefaults
()
{
$singer
=
new
Model
();
$this
->
assertEquals
(
array
(),
$singer
->
rules
());
$this
->
assertEquals
(
array
(),
$singer
->
attributeLabels
());
}
public
function
testDefaultScenarios
()
{
$singer
=
new
Singer
();
$this
->
assertEquals
(
array
(
'default'
=>
array
(
'lastName'
,
'underscore_style'
)),
$singer
->
scenarios
());
}
public
function
testIsAttributeRequired
()
{
$singer
=
new
Singer
();
$this
->
assertFalse
(
$singer
->
isAttributeRequired
(
'firstName'
));
$this
->
assertTrue
(
$singer
->
isAttributeRequired
(
'lastName'
));
}
public
function
testCreateValidators
()
{
$this
->
setExpectedException
(
'yii\base\InvalidConfigException'
,
'Invalid validation rule: a rule must be an array specifying both attribute names and validator type.'
);
$invalid
=
new
InvalidRulesModel
();
$invalid
->
createValidators
();
}
}
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