Browse Source

More Model tests

tags/2.0.0-beta
Alexander Makarov 12 years ago
parent
commit
9923888637
  1. 17
      tests/unit/data/base/InvalidRulesModel.php
  2. 21
      tests/unit/data/base/Singer.php
  3. 3
      tests/unit/data/base/Speaker.php
  4. 31
      tests/unit/framework/base/ModelTest.php

17
tests/unit/data/base/InvalidRulesModel.php

@ -0,0 +1,17 @@
<?php
namespace yiiunit\data\base;
use yii\base\Model;
/**
* InvalidRulesModel
*/
class InvalidRulesModel extends Model
{
public function rules()
{
return array(
array('test'),
);
}
}

21
tests/unit/data/base/Singer.php

@ -0,0 +1,21 @@
<?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'),
);
}
}

3
tests/unit/data/base/Speaker.php

@ -1,11 +1,10 @@
<?php
namespace yiiunit\data\base;
use yii\base\Model;
/**
* Speaker
*/
use yii\base\Model;
class Speaker extends Model
{
public $firstName;

31
tests/unit/framework/base/ModelTest.php

@ -1,8 +1,11 @@
<?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();
}
}

Loading…
Cancel
Save