You are here

protected function UcAddressesTestCase::createAddress in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 tests/UcAddressesTestCase.test \UcAddressesTestCase::createAddress()

Create a new address for an user.

Parameters

object $account: The user to create an address for.

boolean $may_edit: If expected if the user may edit the address. Defaults to TRUE.

array $values: (optional) The values for the address to set. If not given, default values will be used for the address.

Return value

int The address ID for the created address if creating was succesful. NULL Otherwise.

5 calls to UcAddressesTestCase::createAddress()
UcAddressesAddressBookAdminAllTestCase::testDoubleAddresses in tests/uc_addresses.addressbook.test
Test if double addresses are not saved.
UcAddressesAddressBookTestCase::doOtherUsersAddressTests in tests/uc_addresses.addressbook.test
Does basic tests for viewing, editing and deleting other ones addresses.
UcAddressesAddressBookTestCase::doOwnAddressTests in tests/uc_addresses.addressbook.test
Does basic tests for viewing, editing and deleting own addresses.
UcAddressesApiTestCase::testAddressFormatWithoutDefaultCountry in tests/uc_addresses.api.test
Tests if a proper address format is generated when there is no default country set.
UcAddressesEntityCase::testEntityCrud in tests/uc_addresses.entity.test
Test Ubercart Addresses Entity CRUD.

File

tests/UcAddressesTestCase.test, line 125
Contains base class for Ubercart Addresses tests.

Class

UcAddressesTestCase
Base class for Ubercart Addresses tests.

Code

protected function createAddress($account, $may_edit = TRUE, $values = array()) {
  if ($may_edit) {
    $values = self::getEditAddressValues(array(
      'address',
    ), $values, 'address_form');
    $this
      ->drupalPost($this
      ->constructAddressUrl($account) . 'add', $values['form_values'], t('Save address'));
    $this
      ->assertText(t('The address is saved.'), t('The address was saved.'));

    // Lookup address to find out ID.
    $aid = db_query("SELECT aid FROM {uc_addresses}\n      WHERE uid = :uid\n      ORDER BY aid DESC\n      ", array(
      ':uid' => $account->uid,
    ))
      ->fetchField();

    // Ensure any given values exists based on whether they should be displayed.
    $this
      ->viewAddress($account, $aid);
    $values['values']['aid'] = $aid;
    $this
      ->doAddressValuesDisplayedTests($values['values'], 'address_view');
    $this
      ->assertTrue(self::checkAddressValuesInDatabase($values['values']), t('The address %aid is correctly saved to the database.', array(
      '%aid' => $aid,
    )));
    return $aid;
  }
  else {
    $this
      ->drupalGet($this
      ->constructAddressUrl($account) . 'add');
    $this
      ->assertResponse(403);
  }
  return NULL;
}