You are here

public function PmpermissionTestCase::testpmpermissionViewAll in Drupal PM (Project Management) 7.2

Same name and namespace in other branches
  1. 8 pm.permission.test \PmPermissionTestCase::testpmpermissionViewAll()
  2. 7.3 pm.permission.test \PmPermissionTestCase::testpmpermissionViewAll()

Tests "view all" permission.

File

pmpermission/pmpermission.test, line 34
Test definitions for PM Permission.

Class

PmpermissionTestCase
Define a test case for PM Permission.

Code

public function testpmpermissionViewAll() {

  // Allow PM Permission to override organization permissions.
  variable_set('node_permissions_pmorganization', 0);

  // Setup users.
  $users = array();

  // Create a node to test against.
  $organization_settings = array(
    'type' => 'pmorganization',
  );
  $organization = $this
    ->drupalCreateNode($organization_settings);
  $this
    ->assertTrue(isset($organization->nid), 'Node successfully created.');

  // Test that anonymous users can not view the node.
  $this
    ->drupalGet('node/' . $organization->nid);
  $this
    ->assertResponse(403, 'Access is denied to anonymous user.');

  // Create basic user and test that user cannot view the node.
  $users['basic'] = $this
    ->drupalCreateUser(array());
  $this
    ->assertTrue(is_object($users['basic']), 'Basic user successfully created.');
  $this
    ->drupalLogin($users['basic']);
  $this
    ->drupalGet('node/' . $organization->nid);
  $this
    ->assertResponse(403, 'Access is denied to basic user.');

  // Create privileged user and test that user can view the node.
  $user_permissions = array(
    'PM permission pmorganization: view all',
  );
  $this
    ->checkPermissions($user_permissions, TRUE);
  $users['privileged'] = $this
    ->drupalCreateUser($user_permissions);
  $this
    ->assertTrue(is_object($users['privileged']), 'Privileged user successfully created.');
  $this
    ->drupalLogin($users['privileged']);
  $this
    ->drupalGet('node/' . $organization->nid);
  $this
    ->assertResponse(200, 'Access granted to privileged user.');
}