public function PmPermissionTestCase::testpmpermissionBelonged in Drupal PM (Project Management) 8
Same name and namespace in other branches
- 7.3 pm.permission.test \PmPermissionTestCase::testpmpermissionBelonged()
- 7.2 pmpermission/pmpermission.test \PmpermissionTestCase::testpmpermissionBelonged()
Tests "belonged" permission.
File
- ./
pm.permission.test, line 77 - Test definitions for PM Permission.
Class
- PmPermissionTestCase
- Define a test case for PM Permission.
Code
public function testpmpermissionBelonged() {
// Allow PM Permission to override organization permissions.
variable_set('node_permissions_pmorganization', 0);
// Setup users.
$users = array();
// Create two users for testing view permissions (A & B).
$user_permissions = array(
'PM permission pmorganization: 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.');
$this
->assertTrue(is_numeric($users['b']->uid), 'User B uid is numeric.');
$this
->assertTrue(!is_null($users['b']->uid), 'User B uid is not null.');
// Create a node to test against.
$organization_settings = array(
'type' => 'pmorganization',
'uid' => 1,
);
$organization_settings['pmorganization_members'][LANGUAGE_NONE][]['target_id'] = $users['b']->uid;
$organization = $this
->drupalCreateNode($organization_settings);
$this
->assertTrue(isset($organization->nid), 'Node successfully created.');
// Test that anonymous users can not view the node.
$this
->drupalLogout();
$this
->drupalGet('node/' . $organization->nid);
$this
->assertResponse(403, 'Access is denied to anonymous user.');
// Test that user A can not view the node.
$this
->drupalLogin($users['a']);
$this
->drupalGet('node/' . $organization->nid);
$this
->assertResponse(403, 'Access is denied to user A.');
// Test that user B can view the node.
$this
->drupalLogin($users['b']);
$this
->drupalGet('node/' . $organization->nid);
$this
->assertResponse(200, 'Access granted to user B.');
}