You are here

public function UcAddressesApiTestCase::testMultipleAddressBooks in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 tests/uc_addresses.api.test \UcAddressesApiTestCase::testMultipleAddressBooks()

Tests if address loading works as expected across multiple address books.

File

tests/uc_addresses.api.test, line 211
Test cases for the api component.

Class

UcAddressesApiTestCase
Test cases for the api component.

Code

public function testMultipleAddressBooks() {

  // Get address books from two users.
  $addressBook1 = $this
    ->UcAddressesGetAddressBook($this->adminUser->uid);
  $addressBook2 = $this
    ->UcAddressesGetAddressBook($this->customer->uid);

  // Add an address to the first address book.
  $address1 = $addressBook1
    ->addAddress();
  $values = self::getEditAddressValues();
  $address1
    ->setMultipleFields($values['values'], TRUE);
  $address1
    ->save();

  // Ensure this address can't be get from address book 2.
  $this
    ->assertFalse($addressBook2
    ->getAddressById($address1
    ->getId()), t('Address %aid does not belong to user %uid.', array(
    '%aid' => $address1
      ->getId(),
    '%uid' => $addressBook2
      ->getUserId(),
  )));

  // Reset the first address book.
  $addressBook1
    ->reset();

  // Ensure addresses are equal when either getAddressById() or loadAddress() is used.
  $address1_1 = $addressBook1
    ->getAddressById($address1
    ->getId());
  $address1_2 = UcAddressesAddressBook::loadAddress($address1
    ->getId());
  $this
    ->assertTrue($address1_1 === $address1_2, 'UcAddressesAddressBook::loadAddress() loads exactly the same address as $addressBook->getAddressById().');

  // Try to load a non-existent address using the addressBook's getAddressById() method.
  $this
    ->assertFalse($addressBook1
    ->getAddressById(997), 'Address 997 does not exists.');

  // Try again, but now using the loadAddress() method.
  $this
    ->assertFalse(UcAddressesAddressBook::loadAddress(998), 'Address 998 does not exists.');

  // Set performance hint of address book 1 to load all and ensure that this setting
  // is unchanged in address book 2.
  $addressBook1
    ->setPerformanceHint(UcAddressesAddressBook::PERF_HINT_LOAD_ALL);
  $this
    ->assertEqual($addressBook2
    ->getPerformanceHint(), UcAddressesAddressBook::PERF_HINT_LOAD_ONE, 'Performance hint is set to PERF_HINT_LOAD_ONE.');
}