You are here

public function UcAddressesEntityCase::testUserPropertyGet in Ubercart Addresses 7

Tests getting uc_addresses properties on an user.

@covers uc_addresses_user_address_property_get()

File

tests/uc_addresses.entity.test, line 271
Test cases address entity.

Class

UcAddressesEntityCase
Tests for Entity API integration.

Code

public function testUserPropertyGet() {
  $shipping_city = self::randomName();
  $billing_city = self::randomName();
  $account = $this
    ->drupalCreateUser();

  // Create default addresses for this user.
  $addressBook = $this
    ->UcAddressesGetAddressBook($account->uid);

  // Create default shipping address.
  $shipping_address = $addressBook
    ->addAddress();
  $shipping_address
    ->setField('city', $shipping_city);
  $addressBook
    ->setAddressAsDefault($shipping_address, 'shipping');
  $shipping_address
    ->save();

  // Create default billing address.
  $billing_address = $addressBook
    ->addAddress();
  $billing_address
    ->setField('city', $billing_city);
  $addressBook
    ->setAddressAsDefault($billing_address, 'billing');
  $billing_address
    ->save();

  // Reset the address book so no addresses are loaded in memory.
  $addressBook
    ->reset();

  // Assert that properties can be get using the Entity API's metadata wrapper.
  $user_wrapper = entity_metadata_wrapper('user', $account);
  $this
    ->assertEqual($shipping_city, $user_wrapper->uc_addresses_default_shipping_address->city
    ->raw());
  $this
    ->assertEqual($billing_city, $user_wrapper->uc_addresses_default_billing_address->city
    ->raw());
  $this
    ->assertTrue($user_wrapper->uc_addresses_default_shipping_address
    ->raw() instanceof UcAddressesAddress);
  $this
    ->assertTrue($user_wrapper->uc_addresses_default_billing_address
    ->raw() instanceof UcAddressesAddress);
}