public function CommerceAjaxAddCartUI::testPopupEnabledCustomConfiguration in Commerce Ajax Add to Cart 7.2
Verify whether changed module configuations are working.
Tests carried out with popup confirmation popup message enabled.
File
- tests/
dc_ajax_add_cart_ui.test, line 244 - Functional tests for commerce ajax add to cart module.
Class
- CommerceAjaxAddCartUI
- Functional tests for commerce ajax add to cart module.
Code
public function testPopupEnabledCustomConfiguration() {
$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_success_message'] = 'Saman gadi me aa gya hai';
$edit['dc_ajax_add_cart_popup_product_name_label'] = 'display_label';
$edit['dc_ajax_add_cart_popup_product_quantity_label'] = 'no_display_label';
$edit['dc_ajax_add_cart_popup_product_price_label'] = 'no_display_label';
$edit['dc_ajax_add_cart_popup_product_total_label'] = 'no_display_label';
$edit['dc_ajax_add_cart_popup_checkout'] = 'Paise do';
$edit['dc_ajax_add_cart_popup_continue_shopping'] = 'Aur kharido';
$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 displayed.
$this
->assertRaw('<div class="add-cart-message-wrapper">', t('Popup message is displayed'));
// Verify popup success message.
$this
->assertRaw('<div class="added-product-message">' . variable_get('dc_ajax_add_cart_success_message') . '</div>', t('Popup message is found'));
// Verify product name label is shown.
$this
->assertRaw('<p class="name-label">' . t('Name') . ':</p>', t('Product name is shown'));
// Verify product quantity is shown and quantity label is not shown.
$this
->assertNoRaw('<p class="quantity-label">' . t('Quantity') . ':</p>', t('Quantity label is not shown'));
$this
->assertRaw('<p class="quantity">1</p>');
// Verify product price is shown and price label is not shown.
$this
->assertNoRaw('<p class="cost-incl-tax-label">' . t('Price') . ':</p>', t('Price label is not shown'));
$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'));
// Verify total price and total price label is not shown.
$this
->assertNoRaw('<p class="total-label">' . t('Total') . ':</p>', t('Total label is not shown'));
$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'));
// Verify checkout text in popup.
$this
->assertRaw('<a href="' . url('cart') . '">' . variable_get('dc_ajax_add_cart_popup_checkout') . '</a>', t('Checkout text in popup is found'));
// Verify continue shopping text in popup.
$this
->assertRaw('<div class="option-button continue" data-dismiss="add-cart-message">' . variable_get('dc_ajax_add_cart_popup_continue_shopping') . '</div>', t('Continue shopping text in popup is found'));
}
// @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();
// Now we check for remaining settings.
$this
->drupalLogin($this->storeAdmin);
// Hide cart setting turned on.
$edit = array();
$edit['dc_ajax_add_cart_hide_empty_cart'] = 1;
$this
->drupalPost('admin/commerce/config/ajax-cart', $edit, t('Save configuration'));
// Hide quantity and price display setting turned on.
// We are not POSTing the admin form because drupalPost() does not works
// well with ajax checkboxes.
variable_set('dc_ajax_add_cart_popup_product_quantity_display', 0);
variable_set('dc_ajax_add_cart_popup_product_price_display', 0);
$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 displayed.
$this
->assertRaw('<div class="add-cart-message-wrapper">', t('Popup message is displayed'));
// Verify popup success message.
$this
->assertRaw('<div class="added-product-message">' . variable_get('dc_ajax_add_cart_success_message') . '</div>', t('Popup message is found'));
// Verify product name label is shown.
$this
->assertRaw('<p class="name-label">' . t('Name') . ':</p>', t('Product name is shown'));
// Verify product quantity is not shown.
$this
->assertNoRaw('<div class="product-quantity">', t('Quantity is not shown'));
// Verify product price is not shown.
$this
->assertNoRaw('<div class="product-cost-incl-tax">', t('Price is not shown'));
// Verify total price and total price label is not shown.
$this
->assertNoRaw('<p class="total-label">' . t('Total') . ':</p>', t('Total label is not shown'));
$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'));
// Verify checkout text in popup.
$this
->assertRaw('<a href="' . url('cart') . '">' . variable_get('dc_ajax_add_cart_popup_checkout') . '</a>', t('Checkout text in popup is found'));
// Verify continue shopping text in popup.
$this
->assertRaw('<div class="option-button continue" data-dismiss="add-cart-message">' . variable_get('dc_ajax_add_cart_popup_continue_shopping') . '</div>', t('Continue shopping text in popup is found'));
}
// @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
->assertNoText(variable_get('dc_ajax_add_cart_empty_cart_message'), t('Empty cart message not 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();
}