You are here

protected function UcAddressesAddressBookTestCase::doOwnAddressTests in Ubercart Addresses 6.2

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

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.

Return value

void

9 calls to UcAddressesAddressBookTestCase::doOwnAddressTests()
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 35
Test cases for the address book component.

Class

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

Code

protected function doOwnAddressTests($account, $may_view_own_default, $may_view_own, $may_edit_own, $may_delete_own) {

  // Tell the address book we want to load multiple addresses.
  UcAddressesAddressBook::get($account->uid)
    ->setPerformanceHint(UcAddressesAddressBook::PERF_HINT_LOAD_ALL);

  // Check if this user has any addresses, if not create one.
  $query = "SELECT COUNT(aid) FROM {uc_addresses} WHERE uid=%d";
  $number_of_addresses = db_result(db_query($query, $account->uid));
  if ($number_of_addresses < 1) {
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->viewAddressBook($this->adminUser, TRUE);

    // Ensure there are no addresses displayed.
    $this
      ->assertText(t('No addresses have been saved.'));

    // Create one address.
    $aid = $this
      ->createAddress($account);
    $this
      ->verbose(t('Address with ID %aid created', array(
      '%aid' => $aid,
    )));
  }

  // Make sure nothing is loaded for the address book.
  UcAddressesAddressBook::get($account->uid)
    ->reset();
  $this
    ->drupalLogin($account);
  $this
    ->viewAddressBook($account, $may_view_own_default);

  // Check if this user has a default billing address.
  if ($default_address = UcAddressesAddressBook::get($account->uid)
    ->getDefaultAddress('billing')) {

    // Address is the default billing.
  }
  elseif ($default_address = UcAddressesAddressBook::get($account->uid)
    ->getDefaultAddress('shipping')) {

    // Address is the default shipping.
  }
  if ($default_address) {

    // Test if the default address may viewed, edited or deleted.
    // Default addresses may never be deleted!
    $this
      ->doCrudTests($account, $default_address
      ->getId(), $may_view_own_default, $may_edit_own, FALSE);
  }

  // Try to add an address.
  $aid = $this
    ->createAddress($account, $may_edit_own);
  if ($aid) {
    $this
      ->doCrudTests($account, $aid, $may_view_own, $may_edit_own, $may_delete_own);
  }
}