You are here

public function UcAddressesEntityCase::testEntityAccess in Ubercart Addresses 7

Test if entity_access() behaves as expected.

@todo UcAddressesPermissions have to be adjusted in order to let entity_access() behave as expected.

File

tests/uc_addresses.entity.test, line 150
Test cases address entity.

Class

UcAddressesEntityCase
Tests for Entity API integration.

Code

public function testEntityAccess() {

  // Create some users.
  $users = array();
  $customerBasic = $this
    ->drupalCreateUser();
  $customerView = $this
    ->drupalCreateUser(array(
    'view own addresses',
  ));
  $customerEdit = $this
    ->drupalCreateUser(array(
    'add/edit own addresses',
  ));
  $customerDelete = $this
    ->drupalCreateUser(array(
    'add/edit own addresses',
    'delete own addresses',
  ));
  $adminView = $this
    ->drupalCreateUser(array(
    'view all addresses',
  ));
  $adminEdit = $this
    ->drupalCreateUser(array(
    'add/edit all addresses',
  ));
  $adminAll = $this->adminUser;

  // Test access for each user.
  // Basic customer: no permissions at all.
  $this
    ->doOwnAddressTestsUsingEntityAccess($customerBasic, FALSE, FALSE, FALSE, 'customerBasic');
  $this
    ->doOtherUsersAddressTestsUsingEntityAccess($customerBasic, FALSE, FALSE, FALSE, 'customerBasic');

  // customerView: may only view addresses it owns.
  $this
    ->doOwnAddressTestsUsingEntityAccess($customerView, TRUE, FALSE, FALSE, 'customerView');
  $this
    ->doOtherUsersAddressTestsUsingEntityAccess($customerView, FALSE, FALSE, FALSE, 'customerView');

  // customerEdit: may only view and edit addresses it owns.
  $this
    ->doOwnAddressTestsUsingEntityAccess($customerEdit, TRUE, TRUE, FALSE, 'customerEdit');
  $this
    ->doOtherUsersAddressTestsUsingEntityAccess($customerEdit, FALSE, FALSE, FALSE, 'customerEdit');

  // customerDelete: may only view, edit and delete addresses it owns.
  $this
    ->doOwnAddressTestsUsingEntityAccess($customerDelete, TRUE, TRUE, TRUE, 'customerDelete');
  $this
    ->doOtherUsersAddressTestsUsingEntityAccess($customerDelete, FALSE, FALSE, FALSE, 'customerDelete');

  // adminView: may view addresses from all users.
  $this
    ->doOwnAddressTestsUsingEntityAccess($adminView, TRUE, FALSE, FALSE, 'adminView');
  $this
    ->doOtherUsersAddressTestsUsingEntityAccess($adminView, TRUE, FALSE, FALSE, 'adminView');

  // adminEdit: may view and edit addresses from all users.
  $this
    ->doOwnAddressTestsUsingEntityAccess($adminEdit, TRUE, TRUE, FALSE, 'adminEdit');
  $this
    ->doOtherUsersAddressTestsUsingEntityAccess($adminEdit, TRUE, TRUE, FALSE, 'adminEdit');

  // adminAll: may view, edit and delete addresses from all users.
  $this
    ->doOwnAddressTestsUsingEntityAccess($adminAll, TRUE, TRUE, TRUE, 'adminAll');
  $this
    ->doOtherUsersAddressTestsUsingEntityAccess($adminAll, TRUE, TRUE, TRUE, 'adminAll');
}