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
0ed6355e
Commit
0ed6355e
authored
Aug 01, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test and docs to be clear about #4558
parent
2ffd6d8e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
6 deletions
+16
-6
Model.php
framework/base/Model.php
+6
-5
Singer.php
tests/unit/data/base/Singer.php
+2
-0
ModelTest.php
tests/unit/framework/base/ModelTest.php
+8
-1
No files found.
framework/base/Model.php
View file @
0ed6355e
...
...
@@ -385,7 +385,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
if
(
$this
->
_validators
===
null
)
{
$this
->
_validators
=
$this
->
createValidators
();
}
return
$this
->
_validators
;
}
...
...
@@ -404,7 +403,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
$validators
[]
=
$validator
;
}
}
return
$validators
;
}
...
...
@@ -427,7 +425,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
throw
new
InvalidConfigException
(
'Invalid validation rule: a rule must specify both attribute names and validator type.'
);
}
}
return
$validators
;
}
...
...
@@ -436,6 +433,12 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
* This is determined by checking if the attribute is associated with a
* [[\yii\validators\RequiredValidator|required]] validation rule in the
* current [[scenario]].
*
* Note that when the validator has a conditional validation applied using
* [[\yii\validators\RequiredValidator::$when|$when]] this method will return
* `false` regardless of the `when` condition because it may be called be
* before the model is loaded with data.
*
* @param string $attribute attribute name
* @return boolean whether the attribute is required
*/
...
...
@@ -446,7 +449,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
return
true
;
}
}
return
false
;
}
...
...
@@ -482,7 +484,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
public
function
getAttributeLabel
(
$attribute
)
{
$labels
=
$this
->
attributeLabels
();
return
isset
(
$labels
[
$attribute
])
?
$labels
[
$attribute
]
:
$this
->
generateAttributeLabel
(
$attribute
);
}
...
...
tests/unit/data/base/Singer.php
View file @
0ed6355e
...
...
@@ -10,6 +10,7 @@ class Singer extends Model
{
public
$firstName
;
public
$lastName
;
public
$test
;
public
function
rules
()
{
...
...
@@ -17,6 +18,7 @@ class Singer extends Model
[[
'lastName'
],
'default'
,
'value'
=>
'Lennon'
],
[[
'lastName'
],
'required'
],
[[
'underscore_style'
],
'yii\captcha\CaptchaValidator'
],
[[
'test'
],
'required'
,
'when'
=>
function
(
$model
)
{
return
$model
->
firstName
===
'cebe'
;
}],
];
}
}
tests/unit/framework/base/ModelTest.php
View file @
0ed6355e
...
...
@@ -216,7 +216,7 @@ class ModelTest extends TestCase
public
function
testDefaultScenarios
()
{
$singer
=
new
Singer
();
$this
->
assertEquals
([
'default'
=>
[
'lastName'
,
'underscore_style'
]],
$singer
->
scenarios
());
$this
->
assertEquals
([
'default'
=>
[
'lastName'
,
'underscore_style'
,
'test'
]],
$singer
->
scenarios
());
$scenarios
=
[
'default'
=>
[
'id'
,
'name'
,
'description'
],
...
...
@@ -238,6 +238,13 @@ class ModelTest extends TestCase
$singer
=
new
Singer
();
$this
->
assertFalse
(
$singer
->
isAttributeRequired
(
'firstName'
));
$this
->
assertTrue
(
$singer
->
isAttributeRequired
(
'lastName'
));
// attribute is not marked as required when a conditional validation is applied using `$when`.
// the condition should not be applied because this info may be retrieved before model is loaded with data
$singer
->
firstName
=
'qiang'
;
$this
->
assertFalse
(
$singer
->
isAttributeRequired
(
'test'
));
$singer
->
firstName
=
'cebe'
;
$this
->
assertFalse
(
$singer
->
isAttributeRequired
(
'test'
));
}
public
function
testCreateValidators
()
...
...
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