You are here

class UcAddressesViewsTestCase in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 tests/uc_addresses.views.test \UcAddressesViewsTestCase

Test cases for Views integration.

Hierarchy

Expanded class hierarchy of UcAddressesViewsTestCase

File

tests/uc_addresses.views.test, line 14
Test cases for Views integration.

View source
class UcAddressesViewsTestCase extends UcAddressesTestCase {

  /**
   * Array of accounts.
   *
   * @var array
   * @access protected
   */
  protected $accounts = array();

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

  /**
   * Setup.
   */
  public function setUp() {
    parent::setUp();
    drupal_install_modules(array(
      'views',
    ));
    drupal_get_schema(NULL, TRUE);
    $this
      ->checkPermissions(array(), TRUE);

    // Create a number of users with two addresses each.
    $this
      ->UcAddressesCreateUsers();
    foreach ($this->accounts as $account) {
      $this
        ->UcAddressesCreateAddresses($account);
    }

    // Create addresses for the basic user too.
    $this
      ->UcAddressesCreateAddresses($this->basicUser);
  }

  /**
   * Create users, each with different uc_addresses permissions.
   */
  protected function UcAddressesCreateUsers() {
    $this->accounts = array();
    $this->accounts['customerBasic'] = $this
      ->UcAddressesCreateUser('customerBasic');
    $this->accounts['customerViewDef'] = $this
      ->UcAddressesCreateUser('customerViewDef', array(
      'view own default addresses',
    ), TRUE);
    $this->accounts['customerView'] = $this
      ->UcAddressesCreateUser('customerView', array(
      'view own addresses',
    ), TRUE, TRUE);
    $this->accounts['customerEdit'] = $this
      ->UcAddressesCreateUser('customerEdit', array(
      'add/edit own addresses',
    ), TRUE, TRUE, TRUE);
    $this->accounts['customerDelete'] = $this
      ->UcAddressesCreateUser('customerDelete', array(
      'add/edit own addresses',
      'delete own addresses',
    ), TRUE, TRUE, TRUE, TRUE);
    $this->accounts['adminViewDef'] = $this
      ->UcAddressesCreateUser('adminViewDef', array(
      'view all default addresses',
    ), TRUE, FALSE, FALSE, FALSE, TRUE);
    $this->accounts['adminView'] = $this
      ->UcAddressesCreateUser('adminView', array(
      'view all addresses',
    ), TRUE, TRUE, FALSE, FALSE, TRUE, TRUE);
    $this->accounts['adminEdit'] = $this
      ->UcAddressesCreateUser('adminEdit', array(
      'add/edit all addresses',
    ), TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE);
    $this->accounts['adminAll'] = $this
      ->UcAddressesCreateUser('adminAll', array(
      'add/edit all addresses',
      'delete all addresses',
    ), TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
  }

  /**
   * Saves a View and clears caches.
   *
   * @param view $view
   *   The View to save.
   *
   * @return void
   */
  protected function UcAddressesSaveView($view) {
    $view
      ->save();

    // Rebuild menus and clear caches.
    views_get_all_views(TRUE);
    cache_clear_all('*', 'cache_views', TRUE);
    cache_clear_all('*', 'cache_views_data', TRUE);
    cache_clear_all();
    menu_rebuild();
  }

  /**
   * Tests if the address access filters work as expected.
   */
  public function testAccessFilters() {

    // Setup View.
    $this
      ->createAccessFiltersView();
    $this
      ->doAccessFilterTests($this->accounts['customerBasic']);
    $this
      ->doAccessFilterTests($this->accounts['customerViewDef']);
    $this
      ->doAccessFilterTests($this->accounts['customerView']);
    $this
      ->doAccessFilterTests($this->accounts['customerEdit']);
    $this
      ->doAccessFilterTests($this->accounts['customerDelete']);
    $this
      ->doAccessFilterTests($this->accounts['adminViewDef']);
    $this
      ->doAccessFilterTests($this->accounts['adminView']);
    $this
      ->doAccessFilterTests($this->accounts['adminEdit']);
    $this
      ->doAccessFilterTests($this->accounts['adminAll']);
  }

  /**
   * Tests if the address access filters work for one particular
   * account.
   *
   * @param object $account
   *   The account to check access for.
   *
   * @return void
   */
  protected function doAccessFilterTests($account) {
    $this
      ->drupalLogin($account);

    // Test view access.
    $this
      ->drupalGet('uc_addresses/view');

    // View own default addresses.
    $text = $account->uid . '_default';
    if ($account->uc_addresses_permissions['view_own_def']) {
      $this
        ->assertText($text, 'User sees own default address.');
    }
    else {
      $this
        ->assertNoText($text);
    }

    // View own addresses.
    $text = $account->uid . '_other';
    if ($account->uc_addresses_permissions['view_own']) {
      $this
        ->assertText($text);
    }
    else {
      $this
        ->assertNoText($text);
    }

    // View all default addresses.
    $text = $this->basicUser->uid . '_default';
    if ($account->uc_addresses_permissions['view_all_def']) {
      $this
        ->assertText($text);
    }
    else {
      $this
        ->assertNoText($text);
    }

    // View all addresses.
    $text = $this->basicUser->uid . '_other';
    if ($account->uc_addresses_permissions['view_all']) {
      $this
        ->assertText($text);
    }
    else {
      $this
        ->assertNoText($text);
    }

    // Test edit access.
    $this
      ->drupalGet('uc_addresses/edit');

    // Edit own address.
    $text = $account->uid . '_other';
    if ($account->uc_addresses_permissions['edit_own']) {
      $this
        ->assertText($text);
    }
    else {
      $this
        ->assertNoText($text);
    }

    // Edit all addresses.
    $text = $this->basicUser->uid . '_other';
    if ($account->uc_addresses_permissions['edit_all']) {
      $this
        ->assertText($text);
    }
    else {
      $this
        ->assertNoText($text);
    }

    // Test delete access.
    $this
      ->drupalGet('uc_addresses/delete');

    // Delete own address.
    $text = $account->uid . '_other';
    if ($account->uc_addresses_permissions['delete_own']) {
      $this
        ->assertText($text);
    }
    else {
      $this
        ->assertNoText($text);
    }

    // Delete all addresses.
    $text = $this->basicUser->uid . '_other';
    if ($account->uc_addresses_permissions['delete_all']) {
      $this
        ->assertText($text);
    }
    else {
      $this
        ->assertNoText($text);
    }
  }

  /**
   * Tests if the view, edit and delete links are only
   * displayed for users that are allowed to perform these tasks.
   */
  public function testActionLinks() {

    // Setup View.
    $this
      ->createActionLinksView();
    $this
      ->doActionLinksTests($this->accounts['customerBasic']);
    $this
      ->doActionLinksTests($this->accounts['customerViewDef']);
    $this
      ->doActionLinksTests($this->accounts['customerView']);
    $this
      ->doActionLinksTests($this->accounts['customerEdit']);
    $this
      ->doActionLinksTests($this->accounts['customerDelete']);
    $this
      ->doActionLinksTests($this->accounts['adminViewDef']);
    $this
      ->doActionLinksTests($this->accounts['adminView']);
    $this
      ->doActionLinksTests($this->accounts['adminEdit']);
    $this
      ->doActionLinksTests($this->accounts['adminAll']);
  }

  /**
   * Tests if the right actions links are displayed for one particular
   * account.
   *
   * @param object $account
   *   The account to check access for.
   *
   * @return void
   */
  protected function doActionLinksTests($account) {
    $this
      ->drupalLogin($account);

    // Test view access.
    $this
      ->drupalGet('uc_addresses/action-links');

    // Get own addresses uri's.
    $own_address_default_uri = UcAddressesAddressBook::get($account->uid)
      ->getDefaultAddress()
      ->uri();
    $own_address_other_uri = UcAddressesAddressBook::get($account->uid)
      ->getAddressByName($account->uid . '_other')
      ->uri();

    // Get addresses of other user.
    $other_user_address_default_uri = UcAddressesAddressBook::get($this->basicUser->uid)
      ->getDefaultAddress()
      ->uri();
    $other_user_address_other_uri = UcAddressesAddressBook::get($this->basicUser->uid)
      ->getAddressByName($this->basicUser->uid . '_other')
      ->uri();

    // View own default addresses.
    if ($account->uc_addresses_permissions['view_own_def']) {
      $this
        ->assertRaw($own_address_default_uri['path'], 'User can see own default address.');
    }
    else {
      $this
        ->assertNoRaw($own_address_default_uri['path']);
    }

    // View own addresses.
    if ($account->uc_addresses_permissions['view_own']) {
      $this
        ->assertRaw($own_address_other_uri['path'], 'User can see own addresses.');
    }
    else {
      $this
        ->assertNoRaw($own_address_other_uri['path']);
    }

    // View all default addresses.
    if ($account->uc_addresses_permissions['view_all_def']) {
      $this
        ->assertRaw($other_user_address_default_uri['path'], 'User can see all default addresses.');
    }
    else {
      $this
        ->assertNoRaw($other_user_address_default_uri['path']);
    }

    // View all addresses.
    if ($account->uc_addresses_permissions['view_all']) {
      $this
        ->assertRaw($other_user_address_other_uri['path'], 'User can see all addresses.');
    }
    else {
      $this
        ->assertNoRaw($other_user_address_other_uri['path']);
    }

    // Edit own addresses.
    if ($account->uc_addresses_permissions['edit_own']) {
      $this
        ->assertRaw($own_address_other_uri['path'] . '/edit', 'User can edit own addresses.');
    }
    else {
      $this
        ->assertNoRaw($own_address_other_uri['path'] . '/edit');
    }

    // Edit all addresses.
    if ($account->uc_addresses_permissions['edit_all']) {
      $this
        ->assertRaw($other_user_address_other_uri['path'] . '/edit', 'User can edit all addresses.');
    }
    else {
      $this
        ->assertNoRaw($other_user_address_other_uri['path'] . '/edit');
    }

    // Delete own addresses.
    if ($account->uc_addresses_permissions['delete_own']) {
      $this
        ->assertRaw($own_address_other_uri['path'] . '/delete', 'User can delete own addresses.');
    }
    else {
      $this
        ->assertNoRaw($own_address_other_uri['path'] . '/delete');
    }

    // Delete all addresses.
    if ($account->uc_addresses_permissions['delete_all']) {
      $this
        ->assertRaw($other_user_address_other_uri['path'] . '/delete', 'User can delete all addresses.');
    }
    else {
      $this
        ->assertNoRaw($other_user_address_other_uri['path'] . '/delete');
    }
  }

  /**
   * Tests if the display access plugin works as expected.
   */
  public function testDisplayAccessPlugin() {

    // Setup View.
    $this
      ->createDisplayAccessView();

    // Test display access.
    $this
      ->doDisplayAccessTests('uc_addresses_display_access', 403);
  }

  /**
   * Tests if the argument validator plugins work as expected.
   */
  public function testArgumentValidatorPlugins() {

    // Check the Views version. Some settings are different when Views 2 is used.
    if (version_compare(views_api_version(), 3, '<')) {

      // Setup View for Views 2.
      $this
        ->createArgumentValidatorView2();
    }
    else {
      $this
        ->createArgumentValidatorView3();
    }

    // Test display access.
    $this
      ->doDisplayAccessTests('uc_addresses_argument_validator', 404);
  }

  /**
   * Tests for each user if he/she should have access to pages:
   * - representing a listing of his/her own addresses;
   * - representing a View of his/her own default billing address;
   * - representing a View of his/her own non-default address;
   * - representing a listing of addresses of an other user;
   * - representing a View a default billing address of an other user;
   * - representing a View a non-default address of an other user;
   *
   * This method is used by the display access plugin test and the
   * argument validator plugin test as they are basically equal
   * in functionality.
   *
   * @param string $user_path
   *   The path to embed in user/[uid]/[user_path]_[access_type].
   * @param string $fail_response
   *   (optional) The response code when the user should not have access.
   *   Defaults to 403.
   *
   * @return void
   */
  public function doDisplayAccessTests($user_path, $fail_response = 403) {

    // Define types of access.
    $access_types = array(
      'view',
      'edit',
      'delete',
    );

    // Get addresses for basic user.
    $other_user_address_default = UcAddressesAddressBook::get($this->basicUser->uid)
      ->getDefaultAddress();
    $other_user_address_other = UcAddressesAddressBook::get($this->basicUser->uid)
      ->getAddressByName($this->basicUser->uid . '_other');
    foreach ($this->accounts as $account) {
      $this
        ->drupalLogin($account);
      $addressBook = UcAddressesAddressBook::get($account->uid);
      $default_address = $addressBook
        ->getDefaultAddress();
      $other_address = $addressBook
        ->getAddressByName($account->uid . '_other');

      // Test access per access type.
      foreach ($access_types as $access_type) {

        // Test for access for any own addresses.
        $base_own_path = 'user/' . $account->uid . '/' . $user_path . '_' . $access_type;
        $this
          ->drupalGet($base_own_path);
        if ($access_type == 'view') {

          // Take "view own default" permission.
          $this
            ->assertAddressAccessResponse($account, $access_type, $account, TRUE, $fail_response);
        }
        else {
          $this
            ->assertAddressAccessResponse($account, $access_type, $account, FALSE, $fail_response);
        }

        // Test access for own default address.
        $this
          ->drupalGet($base_own_path . '/' . $default_address
          ->getId());
        $this
          ->assertAddressAccessResponse($account, $access_type, $account, TRUE, $fail_response);

        // Test access for own non-default address.
        $this
          ->drupalGet($base_own_path . '/' . $other_address
          ->getId());
        $this
          ->assertAddressAccessResponse($account, $access_type, $account, FALSE, $fail_response);

        // Test for access for any addresses of an other user.
        $base_other_path = 'user/' . $this->basicUser->uid . '/' . $user_path . '_' . $access_type;
        $this
          ->drupalGet($base_other_path);
        if ($access_type == 'view') {

          // Take "view all default" permission.
          $this
            ->assertAddressAccessResponse($account, $access_type, $this->basicUser, TRUE, $fail_response);
        }
        else {
          $this
            ->assertAddressAccessResponse($account, $access_type, $this->basicUser, FALSE, $fail_response);
        }

        // Test access for default address of an other user.
        $this
          ->drupalGet($base_other_path . '/' . $other_user_address_default
          ->getId());
        $this
          ->assertAddressAccessResponse($account, $access_type, $this->basicUser, TRUE, $fail_response);

        // Test access for non-default address of an other user.
        $this
          ->drupalGet($base_other_path . '/' . $other_user_address_other
          ->getId());
        $this
          ->assertAddressAccessResponse($account, $access_type, $this->basicUser, FALSE, $fail_response);
      }
    }
  }

  /**
   * Pass if the user with access get's a 200 and 403 if the user should
   * not have access.
   *
   * @param object $account
   *   The current logged in user.
   * @param string $access_type
   *   The permission to check: view, edit or delete.
   * @param string $owner
   *   The address owner.
   * @param boolean $is_default_address
   *   (optional) If access is checked for a default address or not.
   * @param string $fail_response
   *   (optional) The response code when the user should not have access.
   *   Defaults to 403.
   */
  protected function assertAddressAccessResponse($account, $access_type, $owner, $is_default_address = FALSE, $fail_response = 403) {

    // Prepare assert message.
    $access_own = $account->uc_addresses_permissions[$access_type . '_own'];
    $access_all = $account->uc_addresses_permissions[$access_type . '_all'];
    switch ($access_type) {
      case 'view':
        if ($is_default_address) {
          $access_own = $account->uc_addresses_permissions['view_own_def'];
          $access_all = $account->uc_addresses_permissions['view_all_def'];
        }
        break;
      case 'delete':
        if ($is_default_address) {
          $access_own = FALSE;
          $access_all = FALSE;
        }
        break;
    }
    $message_vars = array(
      '!name' => check_plain($account->name),
      '!access_type' => $access_type,
      '!access_own' => $access_own ? '' : 'NOT ',
      '!access_all' => $access_all ? '' : 'NOT ',
      '!default' => $is_default_address ? ' default' : '',
    );
    if ($account->uid == $owner->uid) {
      $message = strtr('User !name may !access_own!access_type own!default addresses.', $message_vars);
      $this
        ->assertResponse($access_own ? 200 : $fail_response, $message);
    }
    else {
      $message = strtr('User !name may !access_all!access_type all!default addresses.', $message_vars);
      $this
        ->assertResponse($access_all ? 200 : $fail_response, $message);
    }
  }

  /**
   * Tests if the row plugin works as expected.
   */
  function testAddressRowStyle() {

    // Setup View.
    $view = $this
      ->createAddressRowStyleView();

    // Test Views page for each type of user.
    foreach ($this->accounts as $account) {
      $this
        ->drupalLogin($account);
      $addressBook = UcAddressesAddressBook::get($account->uid);
      $default_address = $addressBook
        ->getDefaultAddress();
      $other_address = $addressBook
        ->getAddressByName($account->uid . '_other');

      // Go to Views page with the user's default address.
      $this
        ->drupalGet('uc_addresses/address-row-style/' . $default_address
        ->getId());
      $this
        ->assertAddressLabel($default_address);

      // Assert that the "default" label is presented.
      $this
        ->assertText(t('Default billing address'));

      // Assert view, edit and delete links.
      if ($account->uc_addresses_permissions['view_own_def']) {
        $this
          ->assertLink(t('View address'));
      }
      else {
        $this
          ->assertNoLink(t('View address'));
      }
      if ($account->uc_addresses_permissions['edit_own']) {
        $this
          ->assertLink(t('Edit address'));
      }
      else {
        $this
          ->assertNoLink(t('Edit address'));
      }
      $this
        ->assertNoLink(t('Delete address'));

      // Go to Views page with the user's other address.
      $this
        ->drupalGet('uc_addresses/address-row-style/' . $other_address
        ->getId());
      $this
        ->assertAddressLabel($other_address);

      // Assert that the "default" label is NOT presented.
      $this
        ->assertNoText(t('Default billing address'));

      // Assert view, edit and delete links.
      if ($account->uc_addresses_permissions['view_own']) {
        $this
          ->assertLink(t('View address'));
      }
      else {
        $this
          ->assertNoLink(t('View address'));
      }
      if ($account->uc_addresses_permissions['edit_own']) {
        $this
          ->assertLink(t('Edit address'));
      }
      else {
        $this
          ->assertNoLink(t('Edit address'));
      }
      if ($account->uc_addresses_permissions['delete_own']) {
        $this
          ->assertLink(t('Delete address'));
      }
      else {
        $this
          ->assertNoLink(t('Delete address'));
      }
    }

    // Login as an user that may view, edit and delete all addresses.
    $account = $this->accounts['adminAll'];
    $this
      ->drupalLogin($account);
    $addressBook = UcAddressesAddressBook::get($account->uid);
    $default_address = $addressBook
      ->getDefaultAddress();
    $other_address = $addressBook
      ->getAddressByName($account->uid . '_other');

    // Turn off all options of the address row style.
    $display = $view->display['default'];
    $display->display_options['row_options']['view_link'] = 0;
    $display->display_options['row_options']['edit_link'] = 0;
    $display->display_options['row_options']['delete_link'] = 0;
    $display->display_options['row_options']['default_flags'] = 0;

    // Save View.
    $view
      ->save();

    // Go to Views page with the user's default address again and
    // ensure various elements are gone now.
    $this
      ->drupalGet('uc_addresses/address-row-style/' . $default_address
      ->getId());
    $this
      ->assertAddressLabel($default_address);
    $this
      ->assertNoText(t('Default billing address'));
    $this
      ->assertNoLink(t('View address'));
    $this
      ->assertNoLink(t('Edit address'));
    $this
      ->assertNoLink(t('Delete address'));

    // Do the same for the user's other address.
    $this
      ->drupalGet('uc_addresses/address-row-style/' . $other_address
      ->getId());
    $this
      ->assertAddressLabel($other_address);
    $this
      ->assertNoText(t('Default billing address'));
    $this
      ->assertNoLink(t('View address'));
    $this
      ->assertNoLink(t('Edit address'));
    $this
      ->assertNoLink(t('Delete address'));
  }

  /**
   * Creates a View for access filters test.
   *
   * @return object
   *   The created View.
   */
  protected function createAccessFiltersView() {
    views_include('view');
    $view = new view();
    $view->vid = 'new';
    $view->name = 'uc_addresses_access_filters';
    $view->description = 'Used to test if address access filters work as expected.';
    $view->tag = 'default';
    $view->base_table = 'uc_addresses';
    $view->human_name = 'uc_addresses_access_filters';
    $view->core = 6;
    $view->api_version = '3.0';
    $view->disabled = FALSE;

    /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view
      ->new_display('default', 'Master', 'default');
    $handler->display->display_options['access']['type'] = 'none';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'none';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';

    // For Views 6.x-2.x to show all items.
    $handler
      ->override_option('items_per_page', 0);

    /* Field: Ubercart Addresses: Address ID */
    $handler->display->display_options['fields']['aid']['id'] = 'aid';
    $handler->display->display_options['fields']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['aid']['field'] = 'aid';

    /* Field: Ubercart Addresses: Address name */
    $handler->display->display_options['fields']['address_name']['id'] = 'address_name';
    $handler->display->display_options['fields']['address_name']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['address_name']['field'] = 'address_name';

    /* Display: uc_addresses_view_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_view_access', 'page_1');
    $handler->display->display_options['defaults']['filters'] = FALSE;

    /* Filter: Ubercart Addresses: Access */
    $handler->display->display_options['filters']['access_view']['id'] = 'access_view';
    $handler->display->display_options['filters']['access_view']['table'] = 'uc_addresses';
    $handler->display->display_options['filters']['access_view']['field'] = 'access_view';
    $handler->display->display_options['filters']['access_view']['value'] = '1';
    $handler->display->display_options['path'] = 'uc_addresses/view';

    /* Display: uc_addresses_edit_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_edit_access', 'page_2');
    $handler->display->display_options['defaults']['filters'] = FALSE;

    /* Filter: Ubercart Addresses: Edit access */
    $handler->display->display_options['filters']['access_edit']['id'] = 'access_edit';
    $handler->display->display_options['filters']['access_edit']['table'] = 'uc_addresses';
    $handler->display->display_options['filters']['access_edit']['field'] = 'access_edit';
    $handler->display->display_options['filters']['access_edit']['value'] = '1';
    $handler->display->display_options['path'] = 'uc_addresses/edit';

    /* Display: uc_addresses_delete_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_delete_access', 'page_3');
    $handler->display->display_options['defaults']['filters'] = FALSE;

    /* Filter: Ubercart Addresses: Delete access */
    $handler->display->display_options['filters']['access_delete']['id'] = 'access_delete';
    $handler->display->display_options['filters']['access_delete']['table'] = 'uc_addresses';
    $handler->display->display_options['filters']['access_delete']['field'] = 'access_delete';
    $handler->display->display_options['filters']['access_delete']['value'] = '1';
    $handler->display->display_options['path'] = 'uc_addresses/delete';

    // Save View.
    $this
      ->UcAddressesSaveView($view);
    return $view;
  }

  /**
   * Creates a View for Action links test.
   *
   * @return object
   *   The created View.
   */
  protected function createActionLinksView() {
    views_include('view');
    $view = new view();
    $view->vid = 'new';
    $view->name = 'uc_addresses_action_links';
    $view->description = 'Used to test if address action links work as expected.';
    $view->tag = 'default';
    $view->base_table = 'uc_addresses';
    $view->human_name = 'uc_addresses_action_links';
    $view->core = 6;
    $view->api_version = '3.0';
    $view->disabled = FALSE;

    /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view
      ->new_display('default', 'Master', 'default');
    $handler->display->display_options['access']['type'] = 'none';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'none';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';

    // For Views 6.x-2.x to show all items.
    $handler
      ->override_option('items_per_page', 0);

    /* Field: Ubercart Addresses: Address ID */
    $handler->display->display_options['fields']['aid']['id'] = 'aid';
    $handler->display->display_options['fields']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['aid']['field'] = 'aid';

    /* Field: Ubercart Addresses: Address name */
    $handler->display->display_options['fields']['address_name']['id'] = 'address_name';
    $handler->display->display_options['fields']['address_name']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['address_name']['field'] = 'address_name';

    /* Field: Ubercart Addresses: Link */
    $handler->display->display_options['fields']['view']['id'] = 'view';
    $handler->display->display_options['fields']['view']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['view']['field'] = 'view';

    /* Field: Ubercart Addresses: Edit link */
    $handler->display->display_options['fields']['edit']['id'] = 'edit';
    $handler->display->display_options['fields']['edit']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['edit']['field'] = 'edit';

    /* Field: Ubercart Addresses: Delete link */
    $handler->display->display_options['fields']['delete']['id'] = 'delete';
    $handler->display->display_options['fields']['delete']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['delete']['field'] = 'delete';

    /* Display: Page */
    $handler = $view
      ->new_display('page', 'Page', 'page_1');
    $handler->display->display_options['path'] = 'uc_addresses/action-links';

    // Save View.
    $this
      ->UcAddressesSaveView($view);
    return $view;
  }

  /**
   * Creates a View for Display access test.
   *
   * @return object
   *   The created View.
   */
  protected function createDisplayAccessView() {
    views_include('view');
    $view = new view();
    $view->vid = 'new';
    $view->name = 'uc_addresses_display_access';
    $view->description = 'Used to test if display access restrictions work as expected.';
    $view->tag = 'default';
    $view->base_table = 'uc_addresses';
    $view->human_name = 'uc_addresses_display_access';
    $view->core = 6;
    $view->api_version = '3.0';
    $view->disabled = FALSE;

    /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view
      ->new_display('default', 'Master', 'default');
    $handler->display->display_options['items_per_page'] = 0;
    $handler->display->display_options['access']['type'] = 'none';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'none';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';

    // For Views 6.x-2.x to show all items.
    $handler
      ->override_option('items_per_page', 0);

    /* Field: Ubercart Addresses: Address ID */
    $handler->display->display_options['fields']['aid']['id'] = 'aid';
    $handler->display->display_options['fields']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['aid']['field'] = 'aid';

    /* Field: Ubercart Addresses: Address name */
    $handler->display->display_options['fields']['address_name']['id'] = 'address_name';
    $handler->display->display_options['fields']['address_name']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['address_name']['field'] = 'address_name';

    /* Argument: Ubercart Addresses: User ID */
    $handler->display->display_options['arguments']['uid']['id'] = 'uid';
    $handler->display->display_options['arguments']['uid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['uid']['field'] = 'uid';
    $handler->display->display_options['arguments']['uid']['default_action'] = 'not found';
    $handler->display->display_options['arguments']['uid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['uid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['uid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['uid']['validate_type'] = 'none';
    $handler->display->display_options['arguments']['uid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['uid']['not'] = 0;

    /* Argument: Ubercart Addresses: Address ID */
    $handler->display->display_options['arguments']['aid']['id'] = 'aid';
    $handler->display->display_options['arguments']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['aid']['field'] = 'aid';
    $handler->display->display_options['arguments']['aid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['aid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['aid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['aid']['validate_type'] = 'none';
    $handler->display->display_options['arguments']['aid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['aid']['not'] = 0;

    /* Display: uc_addresses_view_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_view_access', 'uc_addresses_view_access');
    $handler->display->display_options['defaults']['access'] = FALSE;
    $handler->display->display_options['access']['type'] = 'uc_addresses_views_access';
    $handler->display->display_options['access']['uid_argument'] = 'uid';
    $handler->display->display_options['access']['aid_argument'] = 'aid';
    $handler->display->display_options['access']['access_type'] = 'view';
    $handler->display->display_options['path'] = 'user/%/uc_addresses_display_access_view';
    $handler->display->display_options['menu']['type'] = 'tab';
    $handler->display->display_options['menu']['title'] = 'AddressBookView';
    $handler->display->display_options['menu']['weight'] = '0';

    /* Display: uc_addresses_edit_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_edit_access', 'uc_addresses_edit_access');
    $handler->display->display_options['defaults']['access'] = FALSE;
    $handler->display->display_options['access']['type'] = 'uc_addresses_views_access';
    $handler->display->display_options['access']['uid_argument'] = 'uid';
    $handler->display->display_options['access']['aid_argument'] = 'aid';
    $handler->display->display_options['access']['access_type'] = 'edit';
    $handler->display->display_options['path'] = 'user/%/uc_addresses_display_access_edit';
    $handler->display->display_options['menu']['type'] = 'tab';
    $handler->display->display_options['menu']['title'] = 'AddressBookEdit';
    $handler->display->display_options['menu']['weight'] = '0';

    /* Display: uc_addresses_delete_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_delete_access', 'uc_addresses_delete_access');
    $handler->display->display_options['defaults']['access'] = FALSE;
    $handler->display->display_options['access']['type'] = 'uc_addresses_views_access';
    $handler->display->display_options['access']['uid_argument'] = 'uid';
    $handler->display->display_options['access']['aid_argument'] = 'aid';
    $handler->display->display_options['access']['access_type'] = 'delete';
    $handler->display->display_options['path'] = 'user/%/uc_addresses_display_access_delete';
    $handler->display->display_options['menu']['type'] = 'tab';
    $handler->display->display_options['menu']['title'] = 'AddressBookDelete';
    $handler->display->display_options['menu']['weight'] = '0';

    // Save View.
    $this
      ->UcAddressesSaveView($view);
    return $view;
  }

  /**
   * Creates a View for Argument validator test for Views 2.
   *
   * @return object
   *   The created View.
   */
  protected function createArgumentValidatorView2() {
    views_include('view');
    $view = new view();
    $view->vid = 'new';
    $view->name = 'uc_addresses_argument_validator';
    $view->description = 'Used to test if display access restrictions work as expected.';
    $view->tag = 'default';
    $view->base_table = 'uc_addresses';
    $view->core = 6;
    $view->api_version = '2';
    $view->disabled = FALSE;

    /* Edit this to true to make a default view disabled initially */
    $handler = $view
      ->new_display('default', 'Master', 'default');
    $handler
      ->override_option('fields', array(
      'aid' => array(
        'id' => 'aid',
        'table' => 'uc_addresses',
        'field' => 'aid',
      ),
      'address_name' => array(
        'id' => 'address_name',
        'table' => 'uc_addresses',
        'field' => 'address_name',
      ),
    ));
    $handler
      ->override_option('access', array(
      'type' => 'none',
    ));
    $handler
      ->override_option('cache', array(
      'type' => 'none',
    ));
    $handler
      ->override_option('items_per_page', 0);
    $handler = $view
      ->new_display('page', 'uc_addresses_view_access', 'uc_addresses_view_access');
    $handler
      ->override_option('arguments', array(
      'uid' => array(
        'id' => 'uid',
        'table' => 'uc_addresses',
        'field' => 'uid',
        'default_action' => 'not found',
        'style_plugin' => 'default_summary',
        'default_argument_type' => 'fixed',
        'default_argument_skip_url' => 0,
        'validate_type' => 'uc_addresses_user_address_access',
        'validate_fail' => 'not found',
        'validate_uc_addresses_user_argument_type' => 'uid',
        'validate_uc_addresses_user_restrict_roles' => FALSE,
        'validate_uc_addresses_user_roles' => array(),
        'validate_uc_addresses_user_access_type' => 'view',
        'break_phrase' => 0,
        'not' => 0,
      ),
      'aid' => array(
        'id' => 'aid',
        'table' => 'uc_addresses',
        'field' => 'aid',
        'style_plugin' => 'default_summary',
        'default_argument_type' => 'fixed',
        'default_argument_skip_url' => 0,
        'validate_type' => 'uc_addresses_address_access',
        'validate_fail' => 'not found',
        'validate_uc_addresses_address_access_type' => 'view',
        'break_phrase' => 0,
        'not' => 0,
      ),
    ));
    $handler
      ->override_option('path', 'user/%/uc_addresses_argument_validator_view');
    $handler
      ->override_option('menu', array(
      'type' => 'tab',
      'title' => 'AddressBookView',
      'description' => '',
      'weight' => '0',
      'name' => 'navigation',
    ));
    $handler
      ->override_option('tab_options', array(
      'type' => 'none',
      'title' => '',
      'description' => '',
      'weight' => 0,
      'name' => 'navigation',
    ));
    $handler = $view
      ->new_display('page', 'uc_addresses_edit_access', 'uc_addresses_edit_access');
    $handler
      ->override_option('arguments', array(
      'uid' => array(
        'id' => 'uid',
        'table' => 'uc_addresses',
        'field' => 'uid',
        'default_action' => 'not found',
        'style_plugin' => 'default_summary',
        'default_argument_type' => 'fixed',
        'default_argument_skip_url' => 0,
        'validate_type' => 'uc_addresses_user_address_access',
        'validate_fail' => 'not found',
        'validate_uc_addresses_user_argument_type' => 'uid',
        'validate_uc_addresses_user_restrict_roles' => FALSE,
        'validate_uc_addresses_user_roles' => array(),
        'validate_uc_addresses_user_access_type' => 'edit',
        'break_phrase' => 0,
        'not' => 0,
      ),
      'aid' => array(
        'id' => 'aid',
        'table' => 'uc_addresses',
        'field' => 'aid',
        'style_plugin' => 'default_summary',
        'default_argument_type' => 'fixed',
        'default_argument_skip_url' => 0,
        'validate_type' => 'uc_addresses_address_access',
        'validate_fail' => 'not found',
        'validate_uc_addresses_address_access_type' => 'edit',
        'break_phrase' => 0,
        'not' => 0,
      ),
    ));
    $handler
      ->override_option('path', 'user/%/uc_addresses_argument_validator_edit');
    $handler
      ->override_option('menu', array(
      'type' => 'tab',
      'title' => 'AddressBookEdit',
      'description' => '',
      'weight' => '0',
      'name' => 'navigation',
    ));
    $handler
      ->override_option('tab_options', array(
      'type' => 'none',
      'title' => '',
      'description' => '',
      'weight' => 0,
      'name' => 'navigation',
    ));
    $handler = $view
      ->new_display('page', 'uc_addresses_delete_access', 'uc_addresses_delete_access');
    $handler
      ->override_option('arguments', array(
      'uid' => array(
        'id' => 'uid',
        'table' => 'uc_addresses',
        'field' => 'uid',
        'default_action' => 'not found',
        'style_plugin' => 'default_summary',
        'default_argument_type' => 'fixed',
        'default_argument_skip_url' => 0,
        'validate_type' => 'uc_addresses_user_address_access',
        'validate_fail' => 'not found',
        'validate_uc_addresses_user_argument_type' => 'uid',
        'validate_uc_addresses_user_restrict_roles' => FALSE,
        'validate_uc_addresses_user_roles' => array(),
        'validate_uc_addresses_user_access_type' => 'delete',
        'break_phrase' => 0,
        'not' => 0,
      ),
      'aid' => array(
        'id' => 'aid',
        'table' => 'uc_addresses',
        'field' => 'aid',
        'style_plugin' => 'default_summary',
        'default_argument_type' => 'fixed',
        'default_argument_skip_url' => 0,
        'validate_type' => 'uc_addresses_address_access',
        'validate_fail' => 'not found',
        'validate_uc_addresses_address_access_type' => 'delete',
        'break_phrase' => 0,
        'not' => 0,
      ),
    ));
    $handler
      ->override_option('path', 'user/%/uc_addresses_argument_validator_delete');
    $handler
      ->override_option('menu', array(
      'type' => 'tab',
      'title' => 'AddressBookDelete',
      'description' => '',
      'weight' => '0',
      'name' => 'navigation',
    ));
    $handler
      ->override_option('tab_options', array(
      'type' => 'none',
      'title' => '',
      'description' => '',
      'weight' => 0,
      'name' => 'navigation',
    ));

    // Save View.
    $this
      ->UcAddressesSaveView($view);
    return $view;
  }

  /**
   * Creates a View for Argument validator test for Views 3.
   *
   * @return object
   *   The created View.
   */
  protected function createArgumentValidatorView3() {
    views_include('view');
    $view = new view();
    $view->vid = 'new';
    $view->name = 'uc_addresses_argument_validator';
    $view->description = 'Used to test if display access restrictions work as expected.';
    $view->tag = 'default';
    $view->base_table = 'uc_addresses';
    $view->human_name = 'uc_addresses_argument_validator';
    $view->core = 6;
    $view->api_version = '3.0';
    $view->disabled = FALSE;

    /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view
      ->new_display('default', 'Master', 'default');
    $handler->display->display_options['items_per_page'] = 0;
    $handler->display->display_options['access']['type'] = 'none';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'none';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';

    /* Field: Ubercart Addresses: Address ID */
    $handler->display->display_options['fields']['aid']['id'] = 'aid';
    $handler->display->display_options['fields']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['aid']['field'] = 'aid';

    /* Field: Ubercart Addresses: Address name */
    $handler->display->display_options['fields']['address_name']['id'] = 'address_name';
    $handler->display->display_options['fields']['address_name']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['address_name']['field'] = 'address_name';

    /* Display: uc_addresses_view_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_view_access', 'uc_addresses_view_access');
    $handler->display->display_options['defaults']['arguments'] = FALSE;

    /* Argument: Ubercart Addresses: User ID */
    $handler->display->display_options['arguments']['uid']['id'] = 'uid';
    $handler->display->display_options['arguments']['uid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['uid']['field'] = 'uid';
    $handler->display->display_options['arguments']['uid']['default_action'] = 'not found';
    $handler->display->display_options['arguments']['uid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['uid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['uid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['uid']['validate_type'] = 'uc_addresses_user_address_access';
    $handler->display->display_options['arguments']['uid']['validate_options']['access_type'] = 'view';
    $handler->display->display_options['arguments']['uid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['uid']['not'] = 0;

    /* Argument: Ubercart Addresses: Address ID */
    $handler->display->display_options['arguments']['aid']['id'] = 'aid';
    $handler->display->display_options['arguments']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['aid']['field'] = 'aid';
    $handler->display->display_options['arguments']['aid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['aid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['aid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['aid']['validate_type'] = 'uc_addresses_address_access';
    $handler->display->display_options['arguments']['aid']['validate_options']['access_type'] = 'view';
    $handler->display->display_options['arguments']['aid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['aid']['not'] = 0;
    $handler->display->display_options['path'] = 'user/%/uc_addresses_argument_validator_view';
    $handler->display->display_options['menu']['type'] = 'tab';
    $handler->display->display_options['menu']['title'] = 'AddressBookView';
    $handler->display->display_options['menu']['weight'] = '0';

    /* Display: uc_addresses_edit_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_edit_access', 'uc_addresses_edit_access');
    $handler->display->display_options['defaults']['arguments'] = FALSE;

    /* Argument: Ubercart Addresses: User ID */
    $handler->display->display_options['arguments']['uid']['id'] = 'uid';
    $handler->display->display_options['arguments']['uid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['uid']['field'] = 'uid';
    $handler->display->display_options['arguments']['uid']['default_action'] = 'not found';
    $handler->display->display_options['arguments']['uid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['uid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['uid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['uid']['validate_type'] = 'uc_addresses_user_address_access';
    $handler->display->display_options['arguments']['uid']['validate_options']['access_type'] = 'edit';
    $handler->display->display_options['arguments']['uid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['uid']['not'] = 0;

    /* Argument: Ubercart Addresses: Address ID */
    $handler->display->display_options['arguments']['aid']['id'] = 'aid';
    $handler->display->display_options['arguments']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['aid']['field'] = 'aid';
    $handler->display->display_options['arguments']['aid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['aid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['aid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['aid']['validate_type'] = 'uc_addresses_address_access';
    $handler->display->display_options['arguments']['aid']['validate_options']['access_type'] = 'edit';
    $handler->display->display_options['arguments']['aid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['aid']['not'] = 0;
    $handler->display->display_options['path'] = 'user/%/uc_addresses_argument_validator_edit';
    $handler->display->display_options['menu']['type'] = 'tab';
    $handler->display->display_options['menu']['title'] = 'AddressBookEdit';
    $handler->display->display_options['menu']['weight'] = '0';

    /* Display: uc_addresses_delete_access */
    $handler = $view
      ->new_display('page', 'uc_addresses_delete_access', 'uc_addresses_delete_access');
    $handler->display->display_options['defaults']['arguments'] = FALSE;

    /* Argument: Ubercart Addresses: User ID */
    $handler->display->display_options['arguments']['uid']['id'] = 'uid';
    $handler->display->display_options['arguments']['uid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['uid']['field'] = 'uid';
    $handler->display->display_options['arguments']['uid']['default_action'] = 'not found';
    $handler->display->display_options['arguments']['uid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['uid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['uid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['uid']['validate_type'] = 'uc_addresses_user_address_access';
    $handler->display->display_options['arguments']['uid']['validate_options']['access_type'] = 'delete';
    $handler->display->display_options['arguments']['uid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['uid']['not'] = 0;

    /* Argument: Ubercart Addresses: Address ID */
    $handler->display->display_options['arguments']['aid']['id'] = 'aid';
    $handler->display->display_options['arguments']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['aid']['field'] = 'aid';
    $handler->display->display_options['arguments']['aid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['aid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['aid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['aid']['validate_type'] = 'uc_addresses_address_access';
    $handler->display->display_options['arguments']['aid']['validate_options']['access_type'] = 'delete';
    $handler->display->display_options['arguments']['aid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['aid']['not'] = 0;
    $handler->display->display_options['path'] = 'user/%/uc_addresses_argument_validator_delete';
    $handler->display->display_options['menu']['type'] = 'tab';
    $handler->display->display_options['menu']['title'] = 'AddressBookDelete';
    $handler->display->display_options['menu']['weight'] = '0';

    // Save View.
    $this
      ->UcAddressesSaveView($view);
    return $view;
  }

  /**
   * Creates a View for address row style View.
   */
  protected function createAddressRowStyleView() {
    views_include('view');
    $view = new view();
    $view->vid = 'new';
    $view->name = 'uc_addresses_address_row_style';
    $view->description = '';
    $view->tag = 'default';
    $view->base_table = 'uc_addresses';
    $view->human_name = 'uc_addresses_address_row_style';
    $view->core = 6;
    $view->api_version = '2.0';
    $view->disabled = FALSE;

    /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view
      ->new_display('default', 'Master', 'default');
    $handler->display->display_options['access']['type'] = 'none';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'none';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'uc_addresses';
    $handler->display->display_options['row_options']['view_link'] = 1;
    $handler->display->display_options['row_options']['edit_link'] = 1;
    $handler->display->display_options['row_options']['delete_link'] = 1;
    $handler->display->display_options['row_options']['default_flags'] = 1;

    // For Views 6.x-2.x to show all items.
    $handler
      ->override_option('items_per_page', 0);

    /* Field: Ubercart Addresses: Address ID */
    $handler->display->display_options['fields']['aid']['id'] = 'aid';
    $handler->display->display_options['fields']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['fields']['aid']['field'] = 'aid';

    /* Contextual filter: Ubercart Addresses: Address ID */
    $handler->display->display_options['arguments']['aid']['id'] = 'aid';
    $handler->display->display_options['arguments']['aid']['table'] = 'uc_addresses';
    $handler->display->display_options['arguments']['aid']['field'] = 'aid';
    $handler->display->display_options['arguments']['aid']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['aid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['aid']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['aid']['break_phrase'] = 0;
    $handler->display->display_options['arguments']['aid']['validate_type'] = 'none';
    $handler->display->display_options['arguments']['aid']['validate_fail'] = 'not found';
    $handler->display->display_options['arguments']['aid']['not'] = 0;

    /* Display: Page */
    $handler = $view
      ->new_display('page', 'Page', 'page');
    $handler->display->display_options['path'] = 'uc_addresses/address-row-style/%';

    // Save View.
    $this
      ->UcAddressesSaveView($view);
    return $view;
  }

  /**
   * Tests if the default view works as expected.
   */
  public function testDefaultView() {

    // Enable the default view.
    $view = views_get_view('uc_addresses_address_book');
    $view->disabled = FALSE;
    $this
      ->UcAddressesSaveView($view);

    // Get addresses for basic user.
    $other_user_address_default = UcAddressesAddressBook::get($this->basicUser->uid)
      ->getDefaultAddress();
    $other_user_address_other = UcAddressesAddressBook::get($this->basicUser->uid)
      ->getAddressByName($this->basicUser->uid . '_other');
    foreach ($this->accounts as $account) {
      $this
        ->drupalLogin($account);
      $addressBook = UcAddressesAddressBook::get($account->uid);
      $default_address = $addressBook
        ->getDefaultAddress();
      $other_address = $addressBook
        ->getAddressByName($account->uid . '_other');

      // Test if the user can view his/her own address book if he/she
      // has access.
      $this
        ->viewAddressBook($account, $account->uc_addresses_permissions['view_own_def']);

      // Test if the user's default address is displayed when the user
      // may view his/her own default addresses.
      if ($account->uc_addresses_permissions['view_own_def']) {
        $this
          ->assertAddressLabel($default_address);

        // Ensure the View is used to display the address book.
        $this
          ->assertRaw('view-uc-addresses-address-book');
      }
      else {
        $this
          ->assertNoAddressLabel($default_address);
      }

      // Test if the user's other address is displayed when the user
      // may view all of his/her own addresses.
      if ($account->uc_addresses_permissions['view_own']) {
        $this
          ->assertAddressLabel($other_address);
      }
      else {
        $this
          ->assertNoAddressLabel($other_address);
      }

      // Test if the user can view other address books if he/she is allowed
      // to view them.
      $this
        ->viewAddressBook($this->basicUser, $account->uc_addresses_permissions['view_all_def']);

      // Test if the other user's default address is displayed when
      // the user may view all default addresses.
      if ($account->uc_addresses_permissions['view_all_def']) {
        $this
          ->assertAddressLabel($other_user_address_default);
      }
      else {
        $this
          ->assertNoAddressLabel($other_user_address_default);
      }

      // Test if the other user's other address is displayed when
      // the user may view all addresses.
      if ($account->uc_addresses_permissions['view_all']) {
        $this
          ->assertAddressLabel($other_user_address_other);
      }
      else {
        $this
          ->assertNoAddressLabel($other_user_address_other);
      }
    }
  }

}

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::$originalPrefix protected property The original database prefix, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
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::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.
DrupalTestCase::errorHandler public function Handle errors during test runs.
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::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 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::$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::$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.
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 does not exist in the current page by the given 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::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::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::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 Internal helper function; Create a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions. The permissions correspond to the names given on the privileges page.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
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::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::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::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
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.
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.
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
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.
UcAddressesViewsTestCase::$accounts protected property Array of accounts.
UcAddressesViewsTestCase::assertAddressAccessResponse protected function Pass if the user with access get's a 200 and 403 if the user should not have access.
UcAddressesViewsTestCase::createAccessFiltersView protected function Creates a View for access filters test.
UcAddressesViewsTestCase::createActionLinksView protected function Creates a View for Action links test.
UcAddressesViewsTestCase::createAddressRowStyleView protected function Creates a View for address row style View.
UcAddressesViewsTestCase::createArgumentValidatorView2 protected function Creates a View for Argument validator test for Views 2.
UcAddressesViewsTestCase::createArgumentValidatorView3 protected function Creates a View for Argument validator test for Views 3.
UcAddressesViewsTestCase::createDisplayAccessView protected function Creates a View for Display access test.
UcAddressesViewsTestCase::doAccessFilterTests protected function Tests if the address access filters work for one particular account.
UcAddressesViewsTestCase::doActionLinksTests protected function Tests if the right actions links are displayed for one particular account.
UcAddressesViewsTestCase::doDisplayAccessTests public function Tests for each user if he/she should have access to pages:
UcAddressesViewsTestCase::getInfo public static function Describes this test.
UcAddressesViewsTestCase::setUp public function Setup. Overrides UcAddressesTestCase::setUp
UcAddressesViewsTestCase::testAccessFilters public function Tests if the address access filters work as expected.
UcAddressesViewsTestCase::testActionLinks public function Tests if the view, edit and delete links are only displayed for users that are allowed to perform these tasks.
UcAddressesViewsTestCase::testAddressRowStyle function Tests if the row plugin works as expected.
UcAddressesViewsTestCase::testArgumentValidatorPlugins public function Tests if the argument validator plugins work as expected.
UcAddressesViewsTestCase::testDefaultView public function Tests if the default view works as expected.
UcAddressesViewsTestCase::testDisplayAccessPlugin public function Tests if the display access plugin works as expected.
UcAddressesViewsTestCase::UcAddressesCreateUsers protected function Create users, each with different uc_addresses permissions.
UcAddressesViewsTestCase::UcAddressesSaveView protected function Saves a View and clears caches.