public function CommercePriceTableTest::testCommercePriceTableCart in Commerce Price Table 7
Test cart behaviors such as adding quantities.
File
- tests/
commerce_price_table.test, line 201 - Functional tests for the commerce price table module.
Class
- CommercePriceTableTest
- Test price table features.
Code
public function testCommercePriceTableCart() {
// First add price table info to a product.
// Access to a product edit.
$this
->drupalGet('admin/commerce/products/' . $this->product->product_id . '/edit');
// Add price table information and save.
$edit = array(
'field_price_table[und][0][amount]' => 100,
'field_price_table[und][0][min_qty]' => 1,
'field_price_table[und][0][max_qty]' => 10,
);
$this
->drupalPostAJAX(NULL, $edit, 'field_price_table_add_more');
$edit = array(
'field_price_table[und][1][amount]' => 50,
'field_price_table[und][1][min_qty]' => 11,
'field_price_table[und][1][max_qty]' => 20,
);
$this
->drupalPostAJAX(NULL, $edit, 'field_price_table_add_more');
$edit = array(
'field_price_table[und][2][amount]' => 10,
'field_price_table[und][2][min_qty]' => 21,
'field_price_table[und][2][max_qty]' => -1,
);
$this
->drupalPostAJAX(NULL, $edit, 'field_price_table_add_more');
$this
->drupalPost(NULL, array(), t('Save product'));
// Login with customer
$this
->drupalLogin($this->store_customer);
// Access the product display page and add it to the cart.
$this
->drupalPost('node/' . $this->product_node->nid, array(), t('Add to cart'));
// Access the cart and check if the price is right.
$this
->drupalGet($this
->getCommerceUrl('cart'));
// Modify the quantity several times and check the price.
$qty = $this
->xpath("//input[starts-with(@name, 'edit_quantity')]");
$this
->assertRaw(commerce_currency_format(10000, 'USD'), t('Price amount for 1 item is correct.'));
$this
->drupalPost($this
->getCommerceUrl('cart'), array(
(string) $qty[0]['name'] => 11,
), t('Update cart'));
$this
->assertFieldByXPath("//input[starts-with(@id, 'edit-edit-quantity')]", 11, t('Cart updated with new quantity: 11'));
$this
->assertRaw(commerce_currency_format(5000 * 11, 'USD'), t('Price amount for 11 items is correct.'));
$this
->drupalPost($this
->getCommerceUrl('cart'), array(
(string) $qty[0]['name'] => 21,
), t('Update cart'));
$this
->assertFieldByXPath("//input[starts-with(@id, 'edit-edit-quantity')]", 21, t('Cart updated with new quantity: 21'));
$this
->assertRaw(commerce_currency_format(1000 * 21, 'USD'), t('Price amount for 21 items is correct.'));
}