public function PmpermissionTestCase::testpmpermissionChangeParent in Drupal PM (Project Management) 7.2
Same name and namespace in other branches
- 8 pm.permission.test \PmPermissionTestCase::testpmpermissionChangeParent()
- 7.3 pm.permission.test \PmPermissionTestCase::testpmpermissionChangeParent()
Tests permissions after parent change.
File
- pmpermission/
pmpermission.test, line 125 - Test definitions for PM Permission.
Class
- PmpermissionTestCase
- Define a test case for PM Permission.
Code
public function testpmpermissionChangeParent() {
// Allow PM Permission to override project permissions.
variable_set('node_permissions_pmproject', 0);
// Setup users.
$users = array();
// Create two users for testing view permissions (A & B).
$user_permissions = array(
'PM permission pmproject: view own Organization',
);
$this
->checkPermissions($user_permissions, TRUE);
$users['a'] = $this
->drupalCreateUser($user_permissions);
$users['b'] = $this
->drupalCreateUser($user_permissions);
$this
->assertTrue(is_object($users['a']), 'User A successfully created.');
$this
->assertTrue(is_object($users['b']), 'User B successfully created.');
// Create two organization nodes (A & B) with respective users as members.
$organization_a_settings = array(
'type' => 'pmorganization',
'uid' => 1,
);
$organization_a_settings['pmorganization_members'][LANGUAGE_NONE][]['target_id'] = $users['a']->uid;
$organization_a = $this
->drupalCreateNode($organization_a_settings);
$organization_b_settings = array(
'type' => 'pmorganization',
'uid' => 1,
);
$organization_b_settings['pmorganization_members'][LANGUAGE_NONE][]['target_id'] = $users['b']->uid;
$organization_b = $this
->drupalCreateNode($organization_b_settings);
// Create one project node, attached to organization A.
$project_settings = array(
'type' => 'pmproject',
'uid' => 1,
);
$project_settings['pmproject_parent'][LANGUAGE_NONE][]['target_id'] = $organization_a->nid;
$project = $this
->drupalCreateNode($project_settings);
// Test that user A can view the project.
$this
->drupalLogin($users['a']);
$this
->drupalGet('node/' . $project->nid);
$this
->assertResponse(200, 'Access granted to user A when project is attached to organization A.');
// Test that user B can not view the project.
$this
->drupalLogin($users['b']);
$this
->drupalGet('node/' . $project->nid);
$this
->assertResponse(403, 'Access is denied to user B when project is attached to organization A.');
// Attach the project to organization B.
$project->pmproject_parent[LANGUAGE_NONE][0]['target_id'] = $organization_b->nid;
node_save($project);
// Test that user A can not view the project.
$this
->drupalLogin($users['a']);
$this
->drupalGet('node/' . $project->nid);
$this
->assertResponse(403, 'Access is denied to user A when project is attached to organization B.');
// Test that user B can view the project.
$this
->drupalLogin($users['b']);
$this
->drupalGet('node/' . $project->nid);
$this
->assertResponse(200, 'Access granted to user B when project is attached to organization B.');
}