function UbercartCartCheckoutTestCase::testCart in Ubercart 6.2
Same name and namespace in other branches
- 7.3 uc_cart/tests/uc_cart.test \UbercartCartCheckoutTestCase::testCart()
File
- uc_cart/
uc_cart.test, line 117 - Shopping cart and checkout tests.
Class
- UbercartCartCheckoutTestCase
- Tests the cart and checkout functionality.
Code
function testCart() {
// Test the empty cart.
$this
->drupalGet('cart');
$this
->assertText('There are no products in your shopping cart.');
// Add an item to the cart.
$this
->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
$this
->assertText($this->product->title . ' added to your shopping cart.');
// Test the cart page.
$this
->drupalGet('cart');
$this
->assertText($this->product->title, t('The product is in the cart.'));
$this
->assertFieldByName('items[0][qty]', 1, t('The product quantity is 1.'));
// Add the item again.
$this
->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
$this
->assertText('Your item(s) have been updated.');
// Test the cart page again.
$this
->drupalGet('cart');
$this
->assertFieldByName('items[0][qty]', 2, t('The product quantity is 2.'));
// Update the quantity.
$qty = mt_rand(3, 100);
$this
->drupalPost('cart', array(
'items[0][qty]' => $qty,
), t('Update cart'));
$this
->assertText('Your cart has been updated.');
$this
->assertFieldByName('items[0][qty]', $qty, t('The product quantity was updated.'));
// Update the quantity to zero.
$this
->drupalPost('cart', array(
'items[0][qty]' => 0,
), t('Update cart'));
$this
->assertText('Your cart has been updated.');
$this
->assertText('There are no products in your shopping cart.');
// Test the remove item button.
$this
->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
$this
->drupalPost('cart', array(), t('Remove'));
$this
->assertText($this->product->title . ' removed from your shopping cart.');
$this
->assertText('There are no products in your shopping cart.');
$this
->drupalLogout();
}