You are here

protected function UcAddressesAddressBookTestCase::doOtherUsersAddressTests in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 tests/uc_addresses.addressbook.test \UcAddressesAddressBookTestCase::doOtherUsersAddressTests()

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

Parameters

object $account: The user to do tests for.

boolean $may_view_default: If the user may view all default addresses.

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.

Return value

void

9 calls to UcAddressesAddressBookTestCase::doOtherUsersAddressTests()
UcAddressesAddressBookAdminAllTestCase::testAdminAll in tests/uc_addresses.addressbook.test
Test if a admin with all uc_addresses privileges is able to view, edit and delete addresses.
UcAddressesAddressBookAdminEditTestCase::testAdminEdit in tests/uc_addresses.addressbook.test
Test if a admin who may view and edit all addresses is able to view, edit and delete addresses.
UcAddressesAddressBookAdminViewDefTestCase::testAdminViewDef in tests/uc_addresses.addressbook.test
Test if a admin who may only view default addresses is able to view, edit and delete addresses.
UcAddressesAddressBookAdminViewTestCase::testAdminView in tests/uc_addresses.addressbook.test
Test if a admin who may view all addresses is able to view, edit and delete addresses.
UcAddressesAddressBookCustomerBasicTestCase::testCustomerBasic in tests/uc_addresses.addressbook.test
Test if a customer with no privileges is able to view, edit and delete addresses.

... See full list

File

tests/uc_addresses.addressbook.test, line 98
Test cases for the address book component.

Class

UcAddressesAddressBookTestCase
Base class for test cases for the address book component.

Code

protected function doOtherUsersAddressTests($account, $may_view_default, $may_view_all, $may_edit_all, $may_delete_all) {

  // First make sure that there is an user with three addresses.
  $addressBook = UcAddressesAddressBook::get($this->basicUser->uid);
  $addressBook
    ->setPerformanceHint(UcAddressesAddressBook::PERF_HINT_LOAD_ALL);

  // Setup
  $this
    ->drupalLogin($this->adminUser);
  db_query("DELETE FROM {uc_addresses} WHERE uid = %d", $this->basicUser->uid);

  // Create an address named 'temp_name'.
  $temp_name_aid = $this
    ->createAddress($this->basicUser, TRUE, array(
    'address_name' => 'temp_name',
  ));

  // Create default billing/shipping addresses.
  $default_billing_aid = $this
    ->createAddress($this->basicUser, TRUE, array(
    'default_billing' => TRUE,
  ));
  $default_shipping_aid = $this
    ->createAddress($this->basicUser, TRUE, array(
    'default_shipping' => TRUE,
  ));

  // Make sure nothing is loaded for the address book.
  $addressBook
    ->reset();
  $this
    ->drupalLogin($account);
  $this
    ->viewAddressBook($this->basicUser, $may_view_default);

  // Test the default billing address
  if ($default_billing_address = $addressBook
    ->getAddressById($default_billing_aid)) {
    $this
      ->assertTrue($default_billing_address
      ->isDefault('billing'), t('The address is the default billing address.'));
    $this
      ->doCrudTests($this->basicUser, $default_billing_address
      ->getId(), $may_view_default, $may_edit_all, FALSE);
  }
  else {
    $this
      ->fail(t('There is no default billing address.'));
  }

  // Test the default shipping address
  if ($default_shipping_address = $addressBook
    ->getAddressById($default_shipping_aid)) {

    // Ensure it is the default shipping
    $this
      ->assertTrue($default_shipping_address
      ->isDefault('shipping'), t('The address is the default shipping address.'));
    $this
      ->doCrudTests($this->basicUser, $default_shipping_address
      ->getId(), $may_view_default, $may_edit_all, FALSE);
  }
  else {
    $this
      ->fail(t('There is no default shipping address.'));
  }

  // Test the address named 'temp_name'.
  if ($address = $addressBook
    ->getAddressByName('temp_name')) {
    $this
      ->doCrudTests($this->basicUser, $address
      ->getId(), $may_view_all, $may_edit_all, $may_delete_all, array(
      'address_name' => 'temp_name',
    ));
  }
  else {
    $this
      ->fail(t('There is no address named %name', array(
      '%name' => 'temp_name',
    )));
  }

  // Try to add an address
  $aid = $this
    ->createAddress($this->basicUser, $may_edit_all);
  if ($aid) {
    $this
      ->doCrudTests($this->basicUser, $aid, $may_view_all, $may_edit_all, $may_delete_all);
  }
}