public function CartCheckoutTest::testAnonymousCheckoutAccountProvided in Ubercart 8.4
Tests anonymous checkout with an existing account.
File
- uc_cart/
tests/ src/ Functional/ CartCheckoutTest.php, line 359
Class
- CartCheckoutTest
- Tests the cart and checkout functionality.
Namespace
Drupal\Tests\uc_cart\FunctionalCode
public function testAnonymousCheckoutAccountProvided() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
$settings = [
// Allow customer to specify username and password.
'uc_cart_new_account_name' => TRUE,
'uc_cart_new_account_password' => TRUE,
];
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/store/config/checkout');
$this
->submitForm($settings, 'Save configuration');
$this
->drupalLogout();
$username = $this
->randomMachineName(20);
$password = $this
->randomMachineName(20);
$this
->addToCart($this->product);
$this
->checkout([
'panes[customer][new_account][name]' => $username,
'panes[customer][new_account][pass]' => $password,
'panes[customer][new_account][pass_confirm]' => $password,
]);
$assert
->responseContains('Your order is complete!');
$assert
->pageTextContains($username, 'Username is shown on screen.');
$assert
->pageTextNotContains($password, 'Password is not shown on screen.');
// Test new account email.
$mails = $this
->getMails([
'id' => 'user_register_no_approval_required',
]);
$mail = array_pop($mails);
$this
->assertNotSame(FALSE, strpos($mail['body'], $username), 'Mail body contains username.');
// Test invoice email.
$mails = $this
->getMails([
'subject' => 'Your Order at Ubercart',
]);
$mail = array_pop($mails);
$this
->assertNotSame(FALSE, strpos($mail['body'], $username), 'Invoice body contains username.');
$this
->assertSame(FALSE, strpos($mail['body'], $password), 'Invoice body does not contain password.');
// Check that cart is now empty.
$this
->drupalGet('cart');
$assert
->pageTextContains('There are no products in your shopping cart.');
// Check that the password works.
$edit = [
'name' => $username,
'pass' => $password,
];
$this
->drupalGet('user');
$this
->submitForm($edit, 'Log in');
}