public function CartLinksTest::testCartLinksMessages in Ubercart 8.4
Tests Cart Links custom messages.
File
- uc_cart_links/
src/ Tests/ CartLinksTest.php, line 434
Class
- CartLinksTest
- Tests the Cart Links functionality.
Namespace
Drupal\uc_cart_links\TestsCode
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 = [];
for ($i = 0; $i < 15; $i++) {
$key = mt_rand(1, 999);
$messages[$key] = $key . '|' . $this
->randomMachineName(32);
}
$this
->setCartLinksUiMessages($messages);
//
// Test message display.
//
// Go to page with Cart Links.
$this
->drupalGet('node/' . $page
->id());
// 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', [
'@message' => $message_text[1],
]), SafeMarkup::format('Message @key displayed.', [
'@key' => $message_key,
]));
// Empty cart (press remove button).
$this
->drupalPostForm('cart', [], t('Remove'));
$this
->assertText(t('There are no products in your shopping cart.'));
$this
->drupalLogout();
}