You are here

function UbercartCartLinksTestCase::testCartLinksProductActionMessage in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_cart_links/tests/uc_cart_links.test \UbercartCartLinksTestCase::testCartLinksProductActionMessage()

Tests cart links on a page under a variety of conditions.

File

uc_cart_links/uc_cart_links.test, line 171
Ubercart Cart Links Tests.

Class

UbercartCartLinksTestCase
SimpleTests for Ubercart Cart Links.

Code

function testCartLinksProductActionMessage() {

  // 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 product action message display
  //
  // Turn on display of product action message
  $this
    ->setCartLinksUIProductActionMessage(TRUE);

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

  // Pick one of the links at random
  $test_link = array_rand($cart_links);
  $this
    ->clickLink(t('Cart Link #@link', array(
    '@link' => $test_link,
  )));
  $this
    ->assertText(t('Cart link product action: @link', array(
    '@link' => substr($cart_links[$test_link], 10),
  )), t('Cart link product action message found.'));

  // Empty cart (press remove button)
  $this
    ->drupalPost('cart', array(), t('Remove'));
  $this
    ->assertText('There are no products in your shopping cart.');

  // Turn off display of product action message
  $this
    ->setCartLinksUIProductActionMessage(FALSE);

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

  // Pick one of the links at random
  $test_link = array_rand($cart_links);
  $this
    ->clickLink(t('Cart Link #@link', array(
    '@link' => $test_link,
  )));
  $this
    ->assertNoText(t('Cart link product action: @link', array(
    '@link' => substr($cart_links[$test_link], 10),
  )), t('Cart link product action message not present.'));
  $this
    ->drupalLogout();
}