You are here

protected function UcAddressesEntityCase::doOwnAddressTestsUsingEntityAccess in Ubercart Addresses 7

Does basic tests for viewing, editing and deleting own addresses.

Parameters

object $account: The user to do tests for.

boolean $may_view_own_default: If the user may view it's own default addresses.

boolean $may_view_own: If the user may view it's own addresses.

boolean $may_edit_own: If the user may edit it's own addresses.

boolean $may_delete_own: If the user may delete it's own addresses.

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

Return value

void

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

File

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

Class

UcAddressesEntityCase
Tests for Entity API integration.

Code

protected function doOwnAddressTestsUsingEntityAccess($account, $may_view_own, $may_edit_own, $may_delete_own, $usertype) {

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

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