You are here

public function UbercartCartCheckoutTestCase::testCart in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_cart/uc_cart.test \UbercartCartCheckoutTestCase::testCart()

Tests basic cart functionality.

File

uc_cart/tests/uc_cart.test, line 122
Shopping cart and checkout tests.

Class

UbercartCartCheckoutTestCase
Tests the cart and checkout functionality.

Code

public function testCart() {
  module_enable(array(
    'uc_cart_entity_test',
  ));

  // 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.');
  $this
    ->assertText('hook_uc_cart_item_insert fired');

  // 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.');
  $this
    ->assertText('hook_uc_cart_item_update fired');

  // 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.'));
  $this
    ->assertText('hook_uc_cart_item_update fired');

  // 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.');
  $this
    ->assertText('hook_uc_cart_item_delete fired');

  // 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
    ->assertText('hook_uc_cart_item_delete fired');
}