You are here

protected function UcAddressesEntityCase::doOtherUsersAddressTestsUsingEntityAccess in Ubercart Addresses 7

Does basic tests for viewing, editing and deleting other ones addresses.

Parameters

object $account: The user to do tests for.

boolean $may_view_all: If the user may view all addresses.

boolean $may_edit_all: If the user may edit all addresses.

boolean $may_delete_all: If the user may delete all addresses.

string $usertype: Indicates in short which permissions this user should have.

Return value

void

1 call to UcAddressesEntityCase::doOtherUsersAddressTestsUsingEntityAccess()
UcAddressesEntityCase::testEntityAccess in tests/uc_addresses.entity.test
Test if entity_access() behaves as expected.

File

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

Class

UcAddressesEntityCase
Tests for Entity API integration.

Code

protected function doOtherUsersAddressTestsUsingEntityAccess($account, $may_view_all, $may_edit_all, $may_delete_all, $usertype) {
  static $entity;
  if (!isset($entity)) {

    // Create an address for an other user.
    $values = self::getEditAddressValues();
    $address_values = $values['values'];
    $address_values['uid'] = 1;
    $entity = entity_create('uc_addresses', $address_values);
    entity_save('uc_addresses', $entity);
  }
  $msgvars = array(
    '@user' => check_plain($usertype),
  );

  // Test access.
  if ($may_view_all) {
    $this
      ->assertTrue(entity_access('view', 'uc_addresses', $entity, $account), strtr('User @user may view all addresses.', $msgvars));
  }
  else {
    $this
      ->assertFalse(entity_access('view', 'uc_addresses', $entity, $account), strtr('User @user may NOT view all addresses.', $msgvars));
  }
  if ($may_edit_all) {
    $this
      ->assertTrue(entity_access('update', 'uc_addresses', $entity, $account), strtr('User @user may edit all addresses.', $msgvars));
  }
  else {
    $this
      ->assertFalse(entity_access('update', 'uc_addresses', $entity, $account), strtr('User @user may NOT edit all addresses.', $msgvars));
  }
  if ($may_delete_all) {
    $this
      ->assertTrue(entity_access('delete', 'uc_addresses', $entity, $account), strtr('User @user may delete all addresses.', $msgvars));
  }
  else {
    $this
      ->assertFalse(entity_access('delete', 'uc_addresses', $entity, $account), strtr('User @user may NOT delete all addresses.', $msgvars));
  }
}