Hello,
I’m writing some unit tests with Yii 1.1 alpha and i don’t succeed to use the access feature to fixture data. Here is my code :
File test/fixtures/AccountStatus.php :
return array(
'unknown'=>array(
'id' => 1,
'code' => 'unknown',
'name' => 'Unknown',
),
'active'=>array(
'id' => 2,
'code' => 'active',
'name' => 'Active',
),
'inactive'=>array(
'id' => 3,
'code' => 'inactive',
'name' => 'Inactive',
),
);
File test/unit/AccountTest.php :
class AccountTest extends CDbTestCase
{
public $fixtures=array(
'status' => 'AccountStatus',
'accounts' => 'Account',
);
public function testCreate()
{
$account=new Account;
$account->setAttributes(array(
'login' => 'new login',
'name' => 'new name',
'password' => 'new password',
'email' => 'new@email.test',
'accountstatus_id' => 2,
),false);
$this->assertTrue($account->save(false));
}
}
With this code, my test pass as it should. But if i change one line in AccountTest.php :
'accountstatus_id' => 1,
to
'accountstatus_id' => $this->status['active']['id'],
the test fails. It seems that $this->status[‘active’][‘id’] doesn’t have any value. As far as i can understand, $this->status[‘active’][‘id’] should return 2. Am i doing something wrong ??
Thanks for your help.
Regards,
Stéphane.