I’m on page 199 of the Agile Web Dev book (which is great, must say) but now I’ve gotten stuck when I run my test i get this error:
I (think) have followed everything exactly as per the instructions. (all unit tests previously have passed).
First part of ProjectTest.php:
class ProjectTest extends CDbTestCase {
public $fixtures = array(
'projects'=>'Project',
'users'=>'User',
'projUsrAssign'=>':tbl_project_user_assignment',
'projUserRole'=>':tbl_project_user_role',
);
public function testUserRoleAssignment() {
$project = $this->projects('project1');
$user = $this->users('user1');
$this->assertEquals(1, $project->associateUserToRole('owner', $user->id));
$this->assertEquals(1, $project->removeUserFromRole('owner', $user->id));
}
public function testIsInRole() {
$row1 = $this->projUserRole['row1'];
Yii::app()->user->setId($row1['user_id']);
$project = Project::model()->findByPk($row1['project_id']);
$this->assertTrue($project->isUserInRole('member'));
}
public function testUserAccessBasedOnProjectRole() {
$row1 = $this->projUserRole['row1'];
Yii::app()->user->setId($row1['user_id']);
$project = Project::model()->findByPk($row1['project_id']);
//Assign php snippet bizRule
$auth = Yii::app()->authManager;
$bizRule = 'return isset($params["project"]) && $params["project"]->isUserInRole("member");';
$auth->assign('member', $row1['user_id'], $bizRule); //line 44
$params = array('project'=>$project);
$this->assertTrue(Yii::app()->user->checkAccess('updateIssue', $params));
$this->assertTrue(Yii::app()->user->checkAccess('readIssue', $params));
$this->assertFalse(Yii::app()->user->checkAccess('updateProject', $params));
}
My tbl_project_user_role.php file:
<?php
return array(
'row1' => array(
'project_id' => 2,
'user_id' => 2,
'role' => 'member',
),
);
?>
Looking at the error, it seems that it’s trying to insert a record but that primary key is already been duplicated.
I’ve tried a couple of things:
- Have the fixtures file return an empty array:
This STILL causes same issue
- Deleted the (only) record from the tbl_project_user_role table
Still get same issue
I am not quite sure what I am missing here?
Any help much appreciated,
gvanto