Commit 99238886 by Alexander Makarov

More Model tests

parent 7b73fdff
<?php
namespace yiiunit\data\base;
use yii\base\Model;
/**
* InvalidRulesModel
*/
class InvalidRulesModel extends Model
{
public function rules()
{
return array(
array('test'),
);
}
}
<?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
<?php
namespace yiiunit\data\base;
use yii\base\Model;
/**
* Speaker
*/
use yii\base\Model;
class Speaker extends Model
{
public $firstName;
......
<?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();
}
}
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