Commit 25f94a40 by Carsten Brandt

Merge branch 'master' of github.com:yiisoft/yii2

* 'master' of github.com:yiisoft/yii2: added more tests.
parents 074ec7dd 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)) {
......
......@@ -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';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment