You are here

public function UbercartCartLinksTestCase::testCartLinksAllowEmptying in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_cart_links/uc_cart_links.test \UbercartCartLinksTestCase::testCartLinksAllowEmptying()

Tests Cart Links cart empty action.

File

uc_cart_links/tests/uc_cart_links.test, line 229
Ubercart Cart Links Tests.

Class

UbercartCartLinksTestCase
SimpleTests for Ubercart Cart Links.

Code

public function testCartLinksAllowEmptying() {

  // Create product.
  $products[] = $this
    ->createCartLinksProduct(FALSE);

  // Create a product class.
  $products[] = $this
    ->createCartLinksProduct(FALSE);

  // later ...
  // Create some valid Cart Links for these products.
  $link_array = $this
    ->createValidCartLinks($products);
  $cart_links = $link_array['links'];
  $link_data = $link_array['data'];

  // Create a page containing these links.
  $page = $this
    ->createCartLinksPage($cart_links);
  $this
    ->drupalLogin($this->adminUser);

  //
  // Test empty cart action.
  //
  // Allow links to empty cart.
  $this
    ->setCartLinksUIAllowEmptying(TRUE);

  // Go to page with Cart Links.
  $this
    ->drupalGet('node/' . $page->nid);

  // Pick one of the links at random and add it to the cart.
  $test_link_0 = array_rand($cart_links);
  $this
    ->clickLink(t('Cart Link #@link', array(
    '@link' => $test_link_0,
  )));

  // Pick another link at random and prepend an 'e-' so it will empty cart.
  $in_cart = $cart_links[$test_link_0];

  // (Don't want to use the same link.)
  unset($cart_links[$test_link_0]);
  $test_link = array_rand($cart_links);
  $this
    ->drupalGet(str_replace('add/p', 'add/e-p', $cart_links[$test_link]));
  $this
    ->assertText(t('The current contents of your shopping cart will be lost. Are you sure you want to continue?'), t('Empty cart confirmation page found.'));

  // Allow.
  $this
    ->drupalPost(NULL, array(), t('Confirm'));

  // Verify the cart doesn't have the first item and does have the second item.
  $this
    ->drupalGet('cart');
  $this
    ->assertText($link_data[$test_link]['title'], t('Product title correct in cart.'));
  $this
    ->assertNoText($link_data[$test_link_0]['title'], t('Cart was emptied by Cart Link.'));

  // Still have something ($test_link) in the cart.
  // Forbid links to empty cart.
  $this
    ->setCartLinksUIAllowEmptying(FALSE);

  // Re-use $test_link_0 and prepend an 'e-' so it will (try to) empty cart.
  $this
    ->drupalGet(str_replace('add/p', 'add/e-p', $in_cart));

  // Verify the cart has both items - cart wasn't emptied.
  $this
    ->drupalGet('cart');
  $this
    ->assertText($link_data[$test_link_0]['title'], t('Cart was not emptied by Cart Link.'));
  $this
    ->assertText($link_data[$test_link]['title'], t('Cart was not emptied by Cart Link.'));
  $this
    ->drupalLogout();
}