You are here

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

Common tests carried out with default configuations of the module.

2 calls to CommerceAjaxAddCartUI::defaultConfigurationTests()
CommerceAjaxAddCartUI::testDefaultConfiguration in tests/dc_ajax_add_cart_ui.test
Verify whether default module configuations are working.
CommerceAjaxAddCartUI::testDefaultConfigurationCartPage in tests/dc_ajax_add_cart_ui.test
Verify whether default module configuations are working in cart page.

File

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

Class

CommerceAjaxAddCartUI
Functional tests for commerce ajax add to cart module.

Code

public function defaultConfigurationTests($cart_page = FALSE) {
  $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'),
    ));

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

    // Verify default popup success message.
    $this
      ->assertRaw('<div class="added-product-message">' . t('Item successfully added to cart') . '</div>', t('Default popup message is found'));

    // Verify product name label is not shown by default.
    $this
      ->assertNoRaw('<p class="name-label">' . t('Name') . ':</p>', t('Product name is not shown by default'));

    // Verify product quantity is shown and quantity label is shown by
    // default.
    $this
      ->assertRaw('<p class="quantity-label">' . t('Quantity') . ':</p>', t('Quantity is shown by default'));
    $this
      ->assertRaw('<p class="quantity">1</p>');

    // Verify product price is shown and price label is shown by default.
    $this
      ->assertRaw('<p class="cost-incl-tax-label">' . t('Price') . ':</p>', t('Price label is shown by default'));
    $this
      ->assertRaw('<p class="cost-incl-tax">' . commerce_currency_format($this->product[$items[$i]]->commerce_price[LANGUAGE_NONE][0]['amount'], $this->product[$items[$i]]->commerce_price[LANGUAGE_NONE][0]['currency_code']) . '</p>', t('Price is shown by default'));

    // Verify total price and total price label is shown by default.
    $this
      ->assertRaw('<p class="total-label">' . t('Total') . ':</p>', t('Total label is shown by default'));
    $this
      ->assertRaw('<p class="total-incl-tax">' . commerce_currency_format($this->product[$items[$i]]->commerce_price[LANGUAGE_NONE][0]['amount'], $this->product[$items[$i]]->commerce_price[LANGUAGE_NONE][0]['currency_code']) . '</p>', t('Total is shown by default'));

    // Verify default checkout text in popup.
    $this
      ->assertRaw('<a href="' . url('cart') . '">' . t('Go to checkout') . '</a>', t('Default checkout text in popup is found'));

    // Verify default continue shopping text in popup.
    $this
      ->assertRaw('<div class="option-button continue" data-dismiss="add-cart-message">' . t('Continue shopping') . '</div>', t('Default continue shopping text in popup is found'));
  }

  // @todo Figure out a way to close the popup.
  if (!$cart_page) {
    $this
      ->drupalGet('<front>');
  }
  else {
    $this
      ->drupalGet('cart');
  }

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

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

  // Verify default suffix text in teaser cart.
  $this
    ->assertTrue($this
    ->xpath('//a[contains(@class, "quantity") and @href=:href]', array(
    ':href' => url('cart'),
  )), t('Default plural suffix text found'));

  // Verify whether remove cart is shown as link by default.
  $this
    ->assertTrue($this
    ->xpath('//a[contains(@href, "remove-product/nojs") and text()=:label]', array(
    ':label' => t('Remove from cart'),
  )), t('Remove cart is shown as link by default'));

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

  // Verify default empty cart message.
  // Verify cart is not hidden when empty by default.
  // Verify default empty cart teaser message.
  $remove_cart_link = $this
    ->xpath('//a[contains(@href, "remove-product/nojs")]');
  for ($i = 0; $i < count($remove_cart_link); $i++) {
    $this
      ->clickLinkAjax(t('Remove from cart'));
  }
  $this
    ->assertText(t('Shopping cart is empty'), t('Default empty cart message found'));
  $empty_cart_teaser_message = $this
    ->xpath('//p[@class=:class and text()=:message]', array(
    ':class' => 'empty-cart',
    ':message' => t('Empty'),
  ));
  $this
    ->assertTrue($empty_cart_teaser_message, t('Default empty teaser cart message found'));
  $this
    ->drupalLogout();
}