function UbercartCartLinksTestCase::testCartLinksBasicFunctionality in Ubercart 6.2
Same name and namespace in other branches
- 7.3 uc_cart_links/tests/uc_cart_links.test \UbercartCartLinksTestCase::testCartLinksBasicFunctionality()
Tests cart links on a page under a variety of conditions.
File
- uc_cart_links/
uc_cart_links.test, line 84 - Ubercart Cart Links Tests.
Class
- UbercartCartLinksTestCase
- SimpleTests for Ubercart Cart Links.
Code
function testCartLinksBasicFunctionality() {
// 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'];
// Need to test incorrect links as well:
// links which add invalid attributes
// links which omit required attributes
// Create a page containing these links
$page = $this
->createCartLinksPage($cart_links);
//
// Test clicking on links
//
foreach ($cart_links as $key => $test_link) {
$this
->drupalGet('node/' . $page->nid);
// Look for link on page
$this
->assertLink(t('Cart Link #@link', array(
'@link' => $key,
)), 0, t('Cart Link #@link found on page.', array(
'@link' => $key,
)));
// Click on link
$this
->clickLink(t('Cart Link #@link', array(
'@link' => $key,
)));
// Check for notice that item was added (this notice is set ON
// by default, see admin/store/settings/cart/edit)
$this
->assertText(t('@title added to your shopping cart.', array(
'@title' => $link_data[$key]['title'],
)), t('Product @title added to cart.', array(
'@title' => $link_data[$key]['title'],
)));
// Check contents of cart
$this
->drupalGet('cart');
$this
->assertText($link_data[$key]['title'], t('Product title correct in cart.'));
$this
->assertFieldByName('items[0][qty]', $link_data[$key]['qty'], t('Product quantity correct in cart.'));
// Check for correct attribute name(s) in cart
foreach ($link_data[$key]['attributes'] as $label => $attribute) {
$this
->assertText($label . ':', t('Attribute @label correct in cart.', array(
'@label' => $label,
)));
foreach ($attribute as $option) {
// Check for correct option name(s) in cart
$this
->assertText($option, t('Option @name correct in cart.', array(
'@name' => $option,
)));
}
}
// Use the same link, but this time append an '_m0' to turn
// off message display for this product
$this
->drupalGet($test_link . '_m0');
// Default add-to-cart message is different when adding a duplicate item
$this
->assertNoText(t('Your item(s) have been updated.'), t('Default add-to-cart message suppressed.'));
// Empty cart (press remove button)
$this
->drupalPost('cart', array(), t('Remove'));
$this
->assertText('There are no products in your shopping cart.');
}
}