You are here

public function PartyAccessTestCase::testPartyDataSetCRUDAccess in Party 7

Same name and namespace in other branches
  1. 8.2 tests/party_access.test \PartyAccessTestCase::testPartyDataSetCRUDAccess()

Test Data Set CRUD Access.

File

tests/party_access.test, line 81
Access Tests for the Party module.

Class

PartyAccessTestCase
Test Core Party functionality

Code

public function testPartyDataSetCRUDAccess() {

  // Create a user with no permissions.
  $user_no_access = $this
    ->drupalCreateUser();

  // Create a user with permission to view a given data set
  $user = $this
    ->drupalCreateUser(array(
    'view party attached ' . $this->data_set_name,
  ));

  // Assert that the user has access to view the data set.
  $this
    ->assertTrue(party_access('view', $this->party, $this->data_set_name, $user), 'A user with permission to view a given data set can view it.');

  // Assert that a user with no permission cannot view the data set.
  $this
    ->assertFalse(party_access('view', $this->party, $this->data_set_name, $user_no_access), 'A user without permission to view a given data set cannot view it.');

  // Create a user with permission to edit a given data set
  $user = $this
    ->drupalCreateUser(array(
    'edit party attached ' . $this->data_set_name,
  ));

  // Assert that the user has access to edit the data set.
  $this
    ->assertTrue(party_access('edit', $this->party, $this->data_set_name, $user), 'A user with permission to edit a given data set can edit it.');

  // Assert that a user with no permission cannot edit the data set.
  $this
    ->assertFalse(party_access('edit', $this->party, $this->data_set_name, $user_no_access), 'A user without permission to edit a given data set cannot edit it.');

  // Create a user with permission to detach a given data set
  $user = $this
    ->drupalCreateUser(array(
    'detach party attached ' . $this->data_set_name,
  ));

  // Assert that the user has access to detach the data set.
  $this
    ->assertTrue(party_access('detach', $this->party, $this->data_set_name, $user), 'A user with permission to detach a given data set can detach it.');

  // Assert that a user with no permission cannot detach the data set.
  $this
    ->assertFalse(party_access('detach', $this->party, $this->data_set_name, $user_no_access), 'A user without permission to detach a given data set cannot detach it.');

  /**
  * @todo: Add a permission to 'add' a data set.
  *
      // Create a user with permission to add a given data set
      $user = $this->drupalCreateUser( array(
   'add party ' . $this->data_set_name,
      ));
      // Assert that the user has access to add the data set.
      $this->assertTrue(party_access('add', $this->party, $this->data_set_name, $user), t('A user with permission to add a given data set can add it.'));
      // Assert that a user with no permission cannot add the data set.
      $this->assertFalse(party_access('add', $this->party, $this->data_set_name, $user_no_access), t('A user without permission to add a given data set cannot add it.'));
  */

  // Create a user with permission to attach a given data set
  $user = $this
    ->drupalCreateUser(array(
    'attach party user',
  ));

  // Assert that the user has access to attach the data set.
  $this
    ->assertTrue(party_access('attach', $this->party, 'user', $user), 'A user with permission to attach a given data set can attach it.');

  // Assert that a user with no permission cannot attach the data set.
  $this
    ->assertFalse(party_access('attach', $this->party, 'user', $user_no_access), 'A user without permission to attach a given data set cannot attach it.');
}