You are here

class UcAddressesEntityCase in Ubercart Addresses 7

Tests for Entity API integration.

Hierarchy

Expanded class hierarchy of UcAddressesEntityCase

File

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

View source
class UcAddressesEntityCase extends UcAddressesTestCase {

  /**
   * Describes this test.
   *
   * @return array
   */
  public static function getInfo() {
    return array(
      'name' => 'Ubercart Addresses entity tests',
      'description' => 'Test the Ubercart Addresses entity integration.',
      'group' => 'Ubercart Addresses',
      'dependencies' => array(
        'ctools',
        'token',
        'uc_store',
        'uc_order',
        'entity',
      ),
    );
  }

  /**
   * Setup.
   */
  public function setUp() {
    parent::setUp();

    // Enable Entity API module.
    module_enable(array(
      'entity',
      'uc_addresses_test',
      'uc_order',
    ));
  }

  /**
   * Test Ubercart Addresses Entity CRUD.
   */
  public function testEntityCrud() {
    $this
      ->drupalLogin($this->adminUser);

    // CREATE TESTS.
    $values = self::getEditAddressValues();
    $address_values = $values['values'];
    $address_values['uid'] = $this->adminUser->uid;
    $entity = entity_create('uc_addresses', $address_values);
    $address = $this
      ->getEntityAddress($entity);

    // Ensure that the address inside the entity contains all set values.
    if ($address instanceof UcAddressesAddress) {
      foreach ($address_values as $field => $value) {
        $this
          ->assertEqual($address
          ->getField($field), $address_values[$field], t('The field %field was set correctly with entity_create().', array(
          '%field' => $field,
        )));
      }
    }

    // Save the entity and ensure it is saved to the database.
    $old_id = $entity
      ->identifier();
    entity_save('uc_addresses', $entity);
    $this
      ->assertEntityHookInvoked('entity_presave', $old_id);
    $this
      ->assertEntityHookInvoked('entity_insert', $entity
      ->identifier());
    $this
      ->assertTrue(self::checkAddressValuesInDatabase($address_values), 'The address was correctly saved using entity_save().');
    if ($address instanceof UcAddressesAddress) {

      // Do tests with other entity API functions.
      $this
        ->doOtherEntityTests($entity, $address);
    }

    // Test the Entity Wrapper.
    $this
      ->doEntityWrapperTests($entity, $address_values);

    // LOAD TESTS.
    $aid = $this
      ->createAddress($this->customer);

    // Load this address through the address book.
    $address = UcAddressesAddressBook::get($this->customer->uid)
      ->getAddressById($aid);

    // Now load through Entity API.
    $entity = entity_load_single('uc_addresses', $aid);
    $this
      ->assertEntityHookInvoked('entity_load', $aid);

    // Ensure these two are equal.
    $this
      ->assertTrue($address === $this
      ->getEntityAddress($entity), 'Address loaded via Address Book API is equal to address loaded via Entity API.');

    // Do tests with other entity API functions.
    $this
      ->doOtherEntityTests($entity, $address);

    // Test the Entity Wrapper.
    $this
      ->doEntityWrapperTests($entity, $address
      ->getRawFieldData());

    // VIEW TESTS.
    // Load addresses and entities first.
    $addressBook = UcAddressesAddressBook::get($this->customer);
    $addresses = $addressBook
      ->getAddresses();
    $addressBook
      ->reset();
    $aids = array();
    foreach ($addresses as $address) {
      $aids[] = $address
        ->getId();
    }
    $entities = entity_load('uc_addresses', $aids);

    // View and render the entities.
    $content = entity_view('uc_addresses', $entities);
    $output = drupal_render($content);
    $this
      ->verbose($output);

    // Test if all addresses are displayed.
    foreach ($addresses as $address) {
      $this
        ->doAddressValuesDisplayedTests($address
        ->getRawFieldData(), 'address_view', $output);
    }

    // UPDATE TESTS.
    // Set some fields directly.
    $values = self::getEditAddressValues();
    $address_update_values = $values['values'];
    foreach ($address_update_values as $field => $value) {
      $entity->{$field} = $value;
    }
    $address = $this
      ->getEntityAddress($entity);
    if ($address instanceof UcAddressesAddress) {
      foreach ($address_update_values as $field => $value) {
        $this
          ->assertEqual($address
          ->getField($field), $address_update_values[$field], t('The field %field was set correctly when setting it directly with $entity->$field.', array(
          '%field' => $field,
        )));
      }

      // Use the 'aid' from the address to ensure later that the address
      // got updated instead of inserted.
      $address_update_values['aid'] = $address
        ->getId();
    }

    // Save the entity and ensure it is updated in the database.
    entity_save('uc_addresses', $entity);
    $this
      ->assertEntityHookInvoked('entity_presave', $entity
      ->identifier());
    $this
      ->assertEntityHookInvoked('entity_update', $entity
      ->identifier());
    $this
      ->assertTrue(self::checkAddressValuesInDatabase($address_update_values), 'The address was correctly updated using entity_save().');
    if ($address instanceof UcAddressesAddress) {

      // Do tests with other entity API functions.
      $this
        ->doOtherEntityTests($entity, $address);
    }

    // Test the Entity Wrapper.
    $this
      ->doEntityWrapperTests($entity, $address_update_values);

    // DELETE TESTS.
    $aid = $this
      ->createAddress($this->customer);
    entity_delete('uc_addresses', $aid);
    $this
      ->assertEntityHookInvoked('entity_delete', $aid);

    // Ensure the address is removed from the database.
    $result = (int) db_select('uc_addresses')
      ->fields('uc_addresses', array(
      'aid',
    ))
      ->condition('aid', $aid)
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertTrue($result === 0, 'The address was deleted using entity_delete().');

    // Ensure the address has been removed from the address book too.
    $deleted_address = UcAddressesAddressBook::get($this->customer->uid)
      ->getAddressById($aid);
    $this
      ->assertFalse($deleted_address, 'The address was deleted from the address book entity_delete().');
  }

  /**
   * Test if entity_access() behaves as expected.
   *
   * @todo UcAddressesPermissions have to be adjusted in
   * order to let entity_access() behave as expected.
   */
  public function testEntityAccess() {

    // Create some users.
    $users = array();
    $customerBasic = $this
      ->drupalCreateUser();
    $customerView = $this
      ->drupalCreateUser(array(
      'view own addresses',
    ));
    $customerEdit = $this
      ->drupalCreateUser(array(
      'add/edit own addresses',
    ));
    $customerDelete = $this
      ->drupalCreateUser(array(
      'add/edit own addresses',
      'delete own addresses',
    ));
    $adminView = $this
      ->drupalCreateUser(array(
      'view all addresses',
    ));
    $adminEdit = $this
      ->drupalCreateUser(array(
      'add/edit all addresses',
    ));
    $adminAll = $this->adminUser;

    // Test access for each user.
    // Basic customer: no permissions at all.
    $this
      ->doOwnAddressTestsUsingEntityAccess($customerBasic, FALSE, FALSE, FALSE, 'customerBasic');
    $this
      ->doOtherUsersAddressTestsUsingEntityAccess($customerBasic, FALSE, FALSE, FALSE, 'customerBasic');

    // customerView: may only view addresses it owns.
    $this
      ->doOwnAddressTestsUsingEntityAccess($customerView, TRUE, FALSE, FALSE, 'customerView');
    $this
      ->doOtherUsersAddressTestsUsingEntityAccess($customerView, FALSE, FALSE, FALSE, 'customerView');

    // customerEdit: may only view and edit addresses it owns.
    $this
      ->doOwnAddressTestsUsingEntityAccess($customerEdit, TRUE, TRUE, FALSE, 'customerEdit');
    $this
      ->doOtherUsersAddressTestsUsingEntityAccess($customerEdit, FALSE, FALSE, FALSE, 'customerEdit');

    // customerDelete: may only view, edit and delete addresses it owns.
    $this
      ->doOwnAddressTestsUsingEntityAccess($customerDelete, TRUE, TRUE, TRUE, 'customerDelete');
    $this
      ->doOtherUsersAddressTestsUsingEntityAccess($customerDelete, FALSE, FALSE, FALSE, 'customerDelete');

    // adminView: may view addresses from all users.
    $this
      ->doOwnAddressTestsUsingEntityAccess($adminView, TRUE, FALSE, FALSE, 'adminView');
    $this
      ->doOtherUsersAddressTestsUsingEntityAccess($adminView, TRUE, FALSE, FALSE, 'adminView');

    // adminEdit: may view and edit addresses from all users.
    $this
      ->doOwnAddressTestsUsingEntityAccess($adminEdit, TRUE, TRUE, FALSE, 'adminEdit');
    $this
      ->doOtherUsersAddressTestsUsingEntityAccess($adminEdit, TRUE, TRUE, FALSE, 'adminEdit');

    // adminAll: may view, edit and delete addresses from all users.
    $this
      ->doOwnAddressTestsUsingEntityAccess($adminAll, TRUE, TRUE, TRUE, 'adminAll');
    $this
      ->doOtherUsersAddressTestsUsingEntityAccess($adminAll, TRUE, TRUE, TRUE, 'adminAll');
  }

  /**
   * Test if entity hooks are invoked when using the address book API.
   */
  public function testHooks() {

    // Get the address book of the admin user.
    $addressBook = UcAddressesAddressBook::get($this->adminUser->uid);

    // Test presave and insert hook.
    $address = $addressBook
      ->addAddress();
    $address
      ->setField('last_name', self::randomName());
    $old_id = $address
      ->getId();
    $address
      ->save();
    $aid = $address
      ->getId();
    $this
      ->assertEntityHookInvoked('entity_presave', $old_id);
    $this
      ->assertEntityHookInvoked('entity_insert', $aid);

    // Ensure the load is NOT invoked, because the address
    // should be cached in memory.
    $addressBook
      ->getAddressById($aid);
    $this
      ->assertEntityHookNotInvoked('entity_load', $aid);

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

    // Test load hook.
    $address = $addressBook
      ->getAddressById($aid);
    $this
      ->assertEntityHookInvoked('entity_load', $aid);

    // Ensure the update is NOT invoked, because the address
    // didn't change.
    $address
      ->save();
    $this
      ->assertEntityHookNotInvoked('entity_update', $aid);

    // Now, change something on the address and save again.
    // This time the update hook should be invoked.
    $address
      ->setField('first_name', self::randomName());
    $address
      ->save();
    $this
      ->assertEntityHookInvoked('entity_update', $aid);

    // Test if the delete hook is invoked.
    // This address is not marked as a default address, so deleting
    // should go fine.
    $address
      ->delete();
    $this
      ->assertEntityHookInvoked('entity_delete', $aid);
  }

  /**
   * Tests getting uc_addresses property on an address.
   *
   * @covers uc_addresses_field_get()
   */
  public function testUcAddressesPropertyGet() {
    $city = self::randomName();

    // Create a new address.
    $address = UcAddressesAddressBook::newAddress();
    $address
      ->setField('city', $city);

    // Assert that properties can be get using the Entity API's metadata wrapper.
    $address_wrapper = entity_metadata_wrapper('uc_addresses', $address);
    $this
      ->assertEqual($city, $address_wrapper->city
      ->raw());
  }

  /**
   * Tests setting uc_addresses property on an address.
   *
   * @covers uc_addresses_field_set()
   */
  public function testUcAddressesPropertySet() {
    $city = self::randomName();

    // Create a new address.
    $address = UcAddressesAddressBook::newAddress();

    // Set a property using the Entity API's metadata wrapper.
    $address_wrapper = entity_metadata_wrapper('uc_addresses', $address);
    $address_wrapper->city
      ->set($city);

    // Assert that the property was set.
    $this
      ->assertEqual($city, $address
      ->getField('city'));
  }

  /**
   * Tests getting uc_addresses properties on an user.
   *
   * @covers uc_addresses_user_address_property_get()
   */
  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);
  }

  /**
   * Tests getting uc_addreses properties on a new uc_order.
   *
   * @covers uc_addresses_uc_order_address_property_get()
   */
  public function testNewUcOrderPropertyGet() {
    $delivery_city = self::randomName();
    $billing_city = self::randomName();

    // Create a new order without saving.
    $order = new UcOrder();
    $order->delivery_city = $delivery_city;
    $order->billing_city = $billing_city;

    // Assert that properties can be get using the Entity API's metadata wrapper.
    $order_wrapper = entity_metadata_wrapper('uc_order', $order);
    $this
      ->assertEqual($delivery_city, $order_wrapper->uc_addresses_delivery_address->city
      ->raw());
    $this
      ->assertEqual($billing_city, $order_wrapper->uc_addresses_billing_address->city
      ->raw());
    $this
      ->assertTrue($order_wrapper->uc_addresses_delivery_address
      ->raw() instanceof UcAddressesAddress);
    $this
      ->assertTrue($order_wrapper->uc_addresses_billing_address
      ->raw() instanceof UcAddressesAddress);
  }

  /**
   * Tests getting uc_addreses properties on an existing uc_order.
   *
   * @covers uc_addresses_uc_order_address_property_get()
   */
  public function testExistingUcOrderPropertyGet() {
    $delivery_city = self::randomName();
    $billing_city = self::randomName();

    // Create a new order manually and save into the database.
    $order_new = new UcOrder();
    $order_new->delivery_city = $delivery_city;
    $order_new->billing_city = $billing_city;
    drupal_write_record('uc_orders', $order_new);

    // Load this order.
    $order = uc_order_load($order_new->order_id);

    // Assert that properties can be get using the Entity API's metadata wrapper.
    $order_wrapper = entity_metadata_wrapper('uc_order', $order);
    $this
      ->assertEqual($delivery_city, $order_wrapper->uc_addresses_delivery_address->city
      ->raw());
    $this
      ->assertEqual($billing_city, $order_wrapper->uc_addresses_billing_address->city
      ->raw());
    $this
      ->assertTrue($order_wrapper->uc_addresses_delivery_address
      ->raw() instanceof UcAddressesAddress);
    $this
      ->assertTrue($order_wrapper->uc_addresses_billing_address
      ->raw() instanceof UcAddressesAddress);
  }

  /**
   * Does basic tests for viewing, editing and deleting own addresses.
   *
   * @param object $account
   *   The user to do tests for.
   * @param boolean $may_view_own_default
   *   If the user may view it's own default addresses.
   * @param boolean $may_view_own
   *   If the user may view it's own addresses.
   * @param boolean $may_edit_own
   *   If the user may edit it's own addresses.
   * @param boolean $may_delete_own
   *   If the user may delete it's own addresses.
   * @param string $usertype
   *   Indicates in short which permissions this user should have.
   *
   * @return void
   */
  protected function doOwnAddressTestsUsingEntityAccess($account, $may_view_own, $may_edit_own, $may_delete_own, $usertype) {

    // Create an address for this user.
    $values = self::getEditAddressValues();
    $address_values = $values['values'];
    $address_values['uid'] = $account->uid;
    $entity = entity_create('uc_addresses', $address_values);
    entity_save('uc_addresses', $entity);
    $msgvars = array(
      '@user' => check_plain($usertype),
    );

    // Test access.
    if ($may_view_own) {
      $this
        ->assertTrue(entity_access('view', 'uc_addresses', $entity, $account), strtr('User @user may view own addresses.', $msgvars));
    }
    else {
      $this
        ->assertFalse(entity_access('view', 'uc_addresses', $entity, $account), strtr('User @user may NOT view own addresses.', $msgvars));
    }
    if ($may_edit_own) {
      $this
        ->assertTrue(entity_access('update', 'uc_addresses', $entity, $account), strtr('User @user may edit own addresses.', $msgvars));
    }
    else {
      $this
        ->assertFalse(entity_access('update', 'uc_addresses', $entity, $account), strtr('User @user may NOT edit own addresses.', $msgvars));
    }
    if ($may_delete_own) {
      $this
        ->assertTrue(entity_access('delete', 'uc_addresses', $entity, $account), strtr('User @user may delete own addresses.', $msgvars));
    }
    else {
      $this
        ->assertFalse(entity_access('delete', 'uc_addresses', $entity, $account), strtr('User @user may NOT delete own addresses.', $msgvars));
    }
  }

  /**
   * Does basic tests for viewing, editing and deleting other ones addresses.
   *
   * @param object $account
   *   The user to do tests for.
   * @param boolean $may_view_all
   *   If the user may view all addresses.
   * @param boolean $may_edit_all
   *   If the user may edit all addresses.
   * @param boolean $may_delete_all
   *   If the user may delete all addresses.
   * @param string $usertype
   *   Indicates in short which permissions this user should have.
   *
   * @return void
   */
  protected function doOtherUsersAddressTestsUsingEntityAccess($account, $may_view_all, $may_edit_all, $may_delete_all, $usertype) {
    static $entity;
    if (!isset($entity)) {

      // Create an address for an other user.
      $values = self::getEditAddressValues();
      $address_values = $values['values'];
      $address_values['uid'] = 1;
      $entity = entity_create('uc_addresses', $address_values);
      entity_save('uc_addresses', $entity);
    }
    $msgvars = array(
      '@user' => check_plain($usertype),
    );

    // Test access.
    if ($may_view_all) {
      $this
        ->assertTrue(entity_access('view', 'uc_addresses', $entity, $account), strtr('User @user may view all addresses.', $msgvars));
    }
    else {
      $this
        ->assertFalse(entity_access('view', 'uc_addresses', $entity, $account), strtr('User @user may NOT view all addresses.', $msgvars));
    }
    if ($may_edit_all) {
      $this
        ->assertTrue(entity_access('update', 'uc_addresses', $entity, $account), strtr('User @user may edit all addresses.', $msgvars));
    }
    else {
      $this
        ->assertFalse(entity_access('update', 'uc_addresses', $entity, $account), strtr('User @user may NOT edit all addresses.', $msgvars));
    }
    if ($may_delete_all) {
      $this
        ->assertTrue(entity_access('delete', 'uc_addresses', $entity, $account), strtr('User @user may delete all addresses.', $msgvars));
    }
    else {
      $this
        ->assertFalse(entity_access('delete', 'uc_addresses', $entity, $account), strtr('User @user may NOT delete all addresses.', $msgvars));
    }
  }

  /**
   * This a helper function for getting an UcAddressesAddress instance
   * from an address entity.
   *
   * Should the method for getting an address entity's UcAddressesAddress
   * instance ever change, then this would be only place to change it in
   * the automated tests.
   *
   * @param object $entity
   *   The address entity.
   *
   * @return UcAddressesAddress
   *   An instance of UcAddressesAddress, if it exists.
   *   Something unexpected otherwise!
   */
  public function getEntityAddress($entity) {
    $address = $entity;

    // Ensure an address is attached.
    $this
      ->assertTrue($address instanceof UcAddressesAddress, 'The address entity correctly contains an UcAddressesAddress instance.');
    return $address;
  }

  /**
   * Test if non-crud entity API functions behave as expected.
   *
   * @param object $entity
   *   The entity to pass to entity API functions.
   * @param UcAddressesAddress $address
   *   An instance of UcAddressesAddress.
   *   This will be used to perform known address book API
   *   methods on.
   *
   * @return void
   */
  protected function doOtherEntityTests($entity, UcAddressesAddress $address) {

    // Ensure the address ID can be get via entity_id().
    $this
      ->assertEqual(entity_id('uc_addresses', $entity), $address
      ->getId(), 'The address ID can be get via entity_id().');

    // Test if entity_label() returns the name of the address (if the address has one).
    if ($name = $address
      ->getName()) {
      $this
        ->assertEqual(entity_label('uc_addresses', $entity), $name, 'entity_label() correctly returns the address name.');
    }

    // Test for correct uri.
    $uri['path'] = 'user/' . $address
      ->getUserId() . '/addresses/' . $address
      ->getId();
    $entity_uri = entity_uri('uc_addresses', $entity);
    $msgvars = array(
      '@uri' => check_plain($uri['path']),
      '@entity_uri' => check_plain($entity_uri['path']),
    );
    $this
      ->assertEqual($entity_uri['path'], $uri['path'], strtr('entity_uri() returns the expected uri: @uri (actual: @entity_uri).', $msgvars));
  }

  /**
   * Test if Entity API Wrapper behaves as expected on address entity's.
   *
   * @param object $entity
   *   The entity to pass to entity API functions.
   * @param array $values
   *   The expected values for each field.
   *
   * @return void
   */
  protected function doEntityWrapperTests($entity, $values) {
    $wrapper = entity_metadata_wrapper('uc_addresses', $entity);
    foreach ($values as $field => $value) {
      switch ($field) {
        case 'uid':

          // The entity property for the 'uid' field is called 'user'.
          $property = 'user';
          break;
        default:

          // All other entity property names are equal to the field name.
          $property = $field;
          break;
      }
      $msgvars = array(
        '@field' => check_plain($field),
      );
      $this
        ->assertEqual($wrapper->{$property}
        ->raw(), $value, strtr('Entity wrapper returns expected value for @field.', $msgvars));
    }
  }

  /**
   * Asserts if a certain hook is invoked.
   *
   * @param string $hook
   *   The hook that was invoked.
   * @param object $entity
   *   The entity that was passed with the hook.
   *
   * @return void
   */
  protected function assertEntityHookInvoked($hook, $entity_id, $message = NULL) {
    if (is_null($message)) {
      $message = t('The hook %hook was invoked upon an uc_addresses entity with id %id', array(
        '%hook' => $hook . '()',
        '%id' => $entity_id,
      ));
    }

    // We can not use variable_get() here, because that returns the
    // on runtime cached variables.
    $serialized_value = db_select('variable')
      ->fields('variable', array(
      'value',
    ))
      ->condition('name', 'uc_addresses_' . $hook)
      ->execute()
      ->fetchField();
    if (!$serialized_value) {
      $this
        ->fail($message);
      return;
    }
    $value = unserialize($serialized_value);
    $this
      ->verbose($value);
    $this
      ->assertEqual($value, $entity_id, $message);
  }

  /**
   * Asserts if a certain hook is NOT invoked.
   *
   * @param string $hook
   *   The hook that was invoked.
   * @param object $entity
   *   The entity that was passed with the hook.
   *
   * @return void
   */
  protected function assertEntityHookNotInvoked($hook, $entity_id, $message = NULL) {
    if (is_null($message)) {
      $message = t('The hook %hook was not invoked upon an uc_addresses entity with id %id', array(
        '%hook' => $hook . '()',
        '%id' => $entity_id,
      ));
    }

    // We can not use variable_get() here, because that returns the
    // on runtime cached variables.
    $serialized_value = db_select('variable')
      ->fields('variable', array(
      'value',
    ))
      ->condition('name', 'uc_addresses_' . $hook)
      ->execute()
      ->fetchField();
    if (!$serialized_value) {
      $this
        ->pass($message);
      return;
    }
    $value = unserialize($serialized_value);
    $this
      ->verbose($value);
    $this
      ->assertNotEqual($value, $entity_id, $message);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
UcAddressesEntityCase::assertEntityHookInvoked protected function Asserts if a certain hook is invoked.
UcAddressesEntityCase::assertEntityHookNotInvoked protected function Asserts if a certain hook is NOT invoked.
UcAddressesEntityCase::doEntityWrapperTests protected function Test if Entity API Wrapper behaves as expected on address entity's.
UcAddressesEntityCase::doOtherEntityTests protected function Test if non-crud entity API functions behave as expected.
UcAddressesEntityCase::doOtherUsersAddressTestsUsingEntityAccess protected function Does basic tests for viewing, editing and deleting other ones addresses.
UcAddressesEntityCase::doOwnAddressTestsUsingEntityAccess protected function Does basic tests for viewing, editing and deleting own addresses.
UcAddressesEntityCase::getEntityAddress public function This a helper function for getting an UcAddressesAddress instance from an address entity.
UcAddressesEntityCase::getInfo public static function Describes this test.
UcAddressesEntityCase::setUp public function Setup. Overrides UcAddressesTestCase::setUp
UcAddressesEntityCase::testEntityAccess public function Test if entity_access() behaves as expected.
UcAddressesEntityCase::testEntityCrud public function Test Ubercart Addresses Entity CRUD.
UcAddressesEntityCase::testExistingUcOrderPropertyGet public function Tests getting uc_addreses properties on an existing uc_order.
UcAddressesEntityCase::testHooks public function Test if entity hooks are invoked when using the address book API.
UcAddressesEntityCase::testNewUcOrderPropertyGet public function Tests getting uc_addreses properties on a new uc_order.
UcAddressesEntityCase::testUcAddressesPropertyGet public function Tests getting uc_addresses property on an address.
UcAddressesEntityCase::testUcAddressesPropertySet public function Tests setting uc_addresses property on an address.
UcAddressesEntityCase::testUserPropertyGet public function Tests getting uc_addresses properties on an user.
UcAddressesTestCase::$adminUser protected property Admin user that has all the privileges of uc_addresses.
UcAddressesTestCase::$basicUser protected property An account with no privileges, will be used to create addresses for by other users.
UcAddressesTestCase::$customer protected property Customer who may view, edit and delete own addresses.
UcAddressesTestCase::assertAddressLabel protected function Pass if an address label is found on the page.
UcAddressesTestCase::assertNoAddressLabel protected function Pass if an address label is NOT found on the page.
UcAddressesTestCase::checkAddressValuesInDatabase public static function Test if these address values appear in the database.
UcAddressesTestCase::constructAddressUrl protected function Constructs the url for the address book.
UcAddressesTestCase::createAddress protected function Create a new address for an user.
UcAddressesTestCase::deleteAddress protected function Delete an address of an user.
UcAddressesTestCase::doAddressValuesDisplayedTests protected function Test if these address values are displayed on the page.
UcAddressesTestCase::doCrudTests protected function Test if user can view, edit or delete the address.
UcAddressesTestCase::editAddress protected function Edit an address of an user.
UcAddressesTestCase::generateAddressFieldValue public static function Generates a value for an address field.
UcAddressesTestCase::getEditAddressValues public static function Generates an array of values to post into an address form
UcAddressesTestCase::UcAddressesCreateAddresses protected function Create 2 addresses for each passed user:
UcAddressesTestCase::UcAddressesCreateUser protected function Creates a single user and registers which permissions this user should get.
UcAddressesTestCase::UcAddressesGetAddressBook protected function Returns an empty address book to be used in tests.
UcAddressesTestCase::viewAddress protected function View a single address of an user.
UcAddressesTestCase::viewAddressBook protected function View the address book of an user.