You are here

public function UcAddressesAddressBookAdminAllTestCase::testDoubleAddresses in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 tests/uc_addresses.addressbook.test \UcAddressesAddressBookAdminAllTestCase::testDoubleAddresses()

Test if double addresses are not saved.

File

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

Class

UcAddressesAddressBookAdminAllTestCase
Test cases for the address book component.

Code

public function testDoubleAddresses() {
  $adminAll = $this
    ->drupalCreateUser(array(
    'add/edit all addresses',
    'delete all addresses',
  ));
  $values = self::getEditAddressValues(array(
    'address',
  ), array(), 'address_form');
  $this
    ->drupalLogin($adminAll);

  // Create first address.
  $this
    ->createAddress($adminAll, TRUE, $values['values']);

  // Now try to create an address with the same values.
  // A (form) error should be displayed about that the address already exists.
  $this
    ->drupalPost($this
    ->constructAddressUrl($adminAll) . 'add', $values['form_values'], t('Save address'));
  $this
    ->assertText(t('This address already appears in your address book. A new address was not added.'), t('The address already appeared in the address book.'));

  // Create an other address.
  $aid = $this
    ->createAddress($adminAll, TRUE);

  // Now try to edit this same address, but with the values from the first address.
  // This should also result into a (form) error, though with a different message
  // than the first.
  $this
    ->drupalPost($this
    ->constructAddressUrl($adminAll, $aid) . 'edit', $values['form_values'], t('Save address'));
  $this
    ->assertText(t('The revised address is already in your address book. Your change was not made.'), t('The revised address already appeared in the address book.'));
}