Commit df6176ed by Carsten Brandt

added unit test for Model::load()

parent 128ee07b
...@@ -17,6 +17,13 @@ class Speaker extends Model ...@@ -17,6 +17,13 @@ class Speaker extends Model
protected $protectedProperty; protected $protectedProperty;
private $_privateProperty; private $_privateProperty;
public static $formName = 'Speaker';
public function formName()
{
return static::$formName;
}
public function attributeLabels() public function attributeLabels()
{ {
return array( return array(
......
...@@ -75,6 +75,32 @@ class ModelTest extends TestCase ...@@ -75,6 +75,32 @@ class ModelTest extends TestCase
$this->assertEquals('Qiang', $speaker->firstName); $this->assertEquals('Qiang', $speaker->firstName);
} }
public function testLoad()
{
$singer = new Singer();
$this->assertEquals('Singer', $singer->formName());
$post = array('firstName' => 'Qiang');
Speaker::$formName = '';
$model = new Speaker();
$model->setScenario('test');
$this->assertTrue($model->load($post));
$this->assertEquals('Qiang', $model->firstName);
Speaker::$formName = 'Speaker';
$model = new Speaker();
$model->setScenario('test');
$this->assertTrue($model->load(array('Speaker' => $post)));
$this->assertEquals('Qiang', $model->firstName);
Speaker::$formName = 'Speaker';
$model = new Speaker();
$model->setScenario('test');
$this->assertFalse($model->load(array('Example' => array())));
$this->assertEquals('', $model->firstName);
}
public function testActiveAttributes() public function testActiveAttributes()
{ {
// by default mass assignment doesn't work at all // by default mass assignment doesn't work at all
......
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