public function CartLinksTest::testCartLinksProductActionMessage in Ubercart 8.4
Tests Cart Links product action messages.
File
- uc_cart_links/
src/ Tests/ CartLinksTest.php, line 203
Class
- CartLinksTest
- Tests the Cart Links functionality.
Namespace
Drupal\uc_cart_links\TestsCode
public 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
->id());
// Pick one of the links at random.
$test_link = array_rand($cart_links);
$this
->clickLink(t('Cart Link #@link', [
'@link' => $test_link,
]));
$this
->assertText(t('Cart Link product action: @link', [
'@link' => substr($cart_links[$test_link], 10),
]), 'Cart Link product action message found.');
// Check that the redirect to the cart worked.
$this
->assertUrl('cart');
// Empty cart (press remove button).
$this
->drupalPostForm('cart', [], '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
->id());
// Pick one of the links at random.
$test_link = array_rand($cart_links);
$this
->clickLink(t('Cart Link #@link', [
'@link' => $test_link,
]));
$this
->assertNoText(t('Cart Link product action: @link', [
'@link' => substr($cart_links[$test_link], 10),
]), 'Cart Link product action message not present.');
$this
->drupalLogout();
}