You are here

function UcAddressesViewsTestCase::testAddressRowStyle in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 tests/uc_addresses.views.test \UcAddressesViewsTestCase::testAddressRowStyle()

Tests if the row plugin works as expected.

File

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

Class

UcAddressesViewsTestCase
Test cases for Views integration.

Code

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'));
}