You are here

public function CommerceAjaxAddCartUI::testPopupDisabledCustomConfiguration in Commerce Ajax Add to Cart 7.2

Verify whether changed module configuations are working.

Tests carried out with popup confirmation popup message disabled.

File

tests/dc_ajax_add_cart_ui.test, line 438
Functional tests for commerce ajax add to cart module.

Class

CommerceAjaxAddCartUI
Functional tests for commerce ajax add to cart module.

Code

public function testPopupDisabledCustomConfiguration() {
  $image_remove_cart_path = drupal_get_path('module', 'dc_ajax_add_cart') . '/images/remove-from-cart.png';

  // Alter default configurations.
  $this
    ->drupalLogin($this->storeAdmin);

  // First we let display the cart if it is empty.
  $edit = array();
  $edit['dc_ajax_add_cart_checkout_redirect'] = 'checkout_page';
  $edit['dc_ajax_add_cart_show_labels'] = 'no_label';
  $edit['dc_ajax_add_cart_empty_cart_message'] = 'Khali gadi';
  $edit['dc_ajax_add_cart_remove_cart'] = 'image';
  $edit['dc_ajax_add_cart_update_quantity'] = 1;
  $this
    ->drupalPost('admin/commerce/config/ajax-cart', $edit, t('Save configuration'));
  $edit = array();
  $edit['dc_ajax_add_cart_empty_cart_teaser_message'] = 'Khali hai';
  $edit['dc_ajax_add_cart_item_suffix_text_singular'] = 'saman';
  $edit['dc_ajax_add_cart_item_suffix_text_plural'] = 'samans';
  $this
    ->drupalPost('admin/commerce/config/ajax-cart/cart-teaser', $edit, t('Save configuration'));

  // First we check with visibility of quantity and price turned on.
  $edit = array();
  $edit['dc_ajax_add_cart_display_popup'] = 'no_display_popup_message';
  $this
    ->drupalPost('admin/commerce/config/ajax-cart/pop-up-message', $edit, t('Save configuration'));
  $this
    ->drupalLogout();

  // Tests for the new configuration.
  $items = array();
  $this
    ->drupalLogin($this->storeCustomer);

  // Randomly add two items to cart.
  for ($i = 0; $i <= 1; $i++) {
    $items[$i] = mt_rand(0, 9);
    $this
      ->drupalPostAJAX('node/' . $this->productNode[$items[$i]]->nid, array(), array(
      'op' => t('Add to cart'),
    ), 'system/ajax', array(), array(), 'commerce-cart-add-to-cart-form-' . $this->productNode[$items[$i]]->nid);

    // Verify popup message is not displayed.
    $this
      ->assertNoRaw('<div class="add-cart-message-wrapper">', t('Popup message is displayed'));
  }

  // @todo Figure out a way to close the popup.
  $this
    ->drupalGet('<front>');

  // Verify checkout link path.
  $this
    ->assertLinkByHref(url('checkout'), 0, t('Checkout link path point to checkout page'));

  // Verify labels are not displayed.
  $this
    ->assertFalse($this
    ->xpath('//th[@class=:class and text()=:label]', array(
    ':class' => 'quantity-label',
    ':label' => t('Quantity'),
  )), t('Quantity label not found'));
  $this
    ->assertFalse($this
    ->xpath('//th[@class=:class and text()=:label]', array(
    ':class' => 'item-label',
    ':label' => t('Items'),
  )), t('Item label not found'));
  $this
    ->assertFalse($this
    ->xpath('//th[@class=:class and text()=:label]', array(
    ':class' => 'price-label',
    ':label' => t('Price'),
  )), t('Price label not found'));

  // Verify suffix text in teaser cart.
  $this
    ->assertRaw('<a href="' . url('cart') . '" class="quantity">' . count($items) . ' samans</a>', t('Plural suffix text found'));

  // Verify whether remove cart is shown as image.
  $this
    ->assertTrue($this
    ->xpath('//a[contains(@href, "remove-product/nojs")]/img[contains(@src, :src) and @title=:title]', array(
    ':title' => t('Remove from cart'),
    ':src' => $image_remove_cart_path,
  )), t('Remove cart is shown as image'));

  // Verify whether cart is updateable.
  $this
    ->assertFieldByXPath('//input[@type="text" and contains(@id, "edit-quantity-") and contains(@name, "quantity_")]', NULL, t('Cart is updateable'));

  // Verify empty cart message.
  // Verify empty cart teaser message.
  // @todo Use API to click image and remove item from cart.
  $order = commerce_cart_order_load($this->storeCustomer->uid);
  commerce_cart_order_empty($order);
  $this
    ->drupalGet('<front>');
  $this
    ->assertText(variable_get('dc_ajax_add_cart_empty_cart_message'), t('Empty cart message found'));
  $empty_cart_teaser_message = $this
    ->xpath('//p[@class=:class and text()=:message]', array(
    ':class' => 'empty-cart',
    ':message' => variable_get('dc_ajax_add_cart_empty_cart_teaser_message'),
  ));
  $this
    ->assertTrue($empty_cart_teaser_message, t('Empty teaser cart message found'));
  $this
    ->drupalLogout();
}