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
25f94a40
Commit
25f94a40
authored
Jan 28, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2
* 'master' of github.com:yiisoft/yii2: added more tests.
parents
074ec7dd
c829dd6b
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 @
25f94a40
...
...
@@ -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 @
25f94a40
...
...
@@ -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