public function UbercartCartLinksTestCase::testCartLinksMessages in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_cart_links/uc_cart_links.test \UbercartCartLinksTestCase::testCartLinksMessages()
Tests Cart Links messages.
To stop the default "xxx was added to your shopping cart" message for a product, use the argument "_s". For example /cart/add/p23_s "_s" is an argument to the "p" action, and suppresses the message for this product only. Other products added by other actions in the Cart Link will still show the message. e.g. /cart/add/p23_s-p15 will show a message for product 15 but not for product 23.
To insert your own message, first define your message in the Cart Links messages panel on the Cart Links settings page, by entering for example "99|My message text". Then use the action "-m99" (a dash, not an underscore) to add the message. For example, /cart/add/p23-m99
Note that just specifying "-m99" will display both your message 99 and the default message, unless you have turned off the default message with "_s".
For additional messages, add additional actions, e.g. "-m99-m1337".
File
- uc_cart_links/
tests/ uc_cart_links.test, line 416 - Ubercart Cart Links Tests.
Class
- UbercartCartLinksTestCase
- SimpleTests for Ubercart Cart Links.
Code
public function testCartLinksMessages() {
// 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);
// Need to be admin to define messages.
$this
->drupalLogin($this->adminUser);
// Define some messages.
$messages = array();
for ($i = 0; $i < 15; $i++) {
$key = mt_rand(1, 999);
$messages[$key] = $key . '|' . $this
->randomName(32);
}
$this
->setCartLinksUIMessages($messages);
//
// Test message display.
//
// Go to page with Cart Links.
$this
->drupalGet('node/' . $page->nid);
// Pick one link at random and append an '-m<#>' to display a message.
$test_link = array_rand($cart_links);
$message_key = array_rand($messages);
$message_text = explode('|', $messages[$message_key]);
$this
->drupalGet($cart_links[$test_link] . '-m' . $message_key);
$this
->assertText(t('@message', array(
'@message' => $message_text[1],
)), t('Message @key displayed.', array(
'@key' => $message_key,
)));
// Empty cart (press remove button).
$this
->drupalPost('cart', array(), t('Remove'));
$this
->assertText('There are no products in your shopping cart.');
$this
->drupalLogout();
}