Browse Source

added unit test for Model::load()

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
df6176edb6
  1. 7
      tests/unit/data/base/Speaker.php
  2. 26
      tests/unit/framework/base/ModelTest.php

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

@ -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(

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

@ -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

Loading…
Cancel
Save