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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
c829dd6b
Commit
c829dd6b
authored
Jan 27, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more tests.
parent
4e966832
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletion
+29
-1
DynamicModel.php
framework/base/DynamicModel.php
+1
-1
DynamicModelTest.php
tests/unit/framework/base/DynamicModelTest.php
+28
-0
No files found.
framework/base/DynamicModel.php
View file @
c829dd6b
...
...
@@ -62,7 +62,7 @@ class DynamicModel extends Model
* @param array $attributes the dynamic attributes (name-value pairs, or names) being defined
* @param array $config the configuration array to be applied to this object.
*/
public
function
__construct
(
array
$attributes
,
$config
=
[])
public
function
__construct
(
array
$attributes
=
[]
,
$config
=
[])
{
foreach
(
$attributes
as
$name
=>
$value
)
{
if
(
is_integer
(
$name
))
{
...
...
tests/unit/framework/base/DynamicModelTest.php
View file @
c829dd6b
...
...
@@ -39,6 +39,34 @@ class DynamicModelTest extends TestCase
$this
->
assertTrue
(
$model
->
hasErrors
(
'age'
));
}
public
function
testAddRule
()
{
$model
=
new
DynamicModel
();
$this
->
assertEquals
(
0
,
$model
->
getValidators
()
->
count
());
$model
->
addRule
(
'name'
,
'string'
,
[
'min'
=>
12
]);
$this
->
assertEquals
(
1
,
$model
->
getValidators
()
->
count
());
$model
->
addRule
(
'email'
,
'email'
);
$this
->
assertEquals
(
2
,
$model
->
getValidators
()
->
count
());
$model
->
addRule
([
'name'
,
'email'
],
'required'
);
$this
->
assertEquals
(
3
,
$model
->
getValidators
()
->
count
());
}
public
function
testValidateWithAddRule
()
{
$email
=
'invalid'
;
$name
=
'long name'
;
$age
=
''
;
$model
=
new
DynamicModel
(
compact
(
'name'
,
'email'
,
'age'
));
$model
->
addRule
([
'email'
,
'name'
,
'age'
],
'required'
)
->
addRule
(
'email'
,
'email'
)
->
addRule
(
'name'
,
'string'
,
[
'max'
=>
3
])
->
validate
();
$this
->
assertTrue
(
$model
->
hasErrors
());
$this
->
assertTrue
(
$model
->
hasErrors
(
'email'
));
$this
->
assertTrue
(
$model
->
hasErrors
(
'name'
));
$this
->
assertTrue
(
$model
->
hasErrors
(
'age'
));
}
public
function
testDynamicProperty
()
{
$email
=
'invalid'
;
...
...
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