public function CartCheckoutTest::testAnonymousCheckoutAccountGenerated in Ubercart 8.4
Tests generating a user account upon anonymous checkout.
File
- uc_cart/
tests/ src/ Functional/ CartCheckoutTest.php, line 317
Class
- CartCheckoutTest
- Tests the cart and checkout functionality.
Namespace
Drupal\Tests\uc_cart\FunctionalCode
public function testAnonymousCheckoutAccountGenerated() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
$this
->addToCart($this->product);
$this
->checkout();
$assert
->responseContains('Your order is complete!');
// Test new account email.
$mails = $this
->getMails([
'id' => 'user_register_no_approval_required',
]);
$mail = array_pop($mails);
$account = $mail['params']['account'];
$this
->assertNotEmpty($account->name->value, 'New username is not empty.');
$this
->assertNotEmpty($account->password, 'New password is not empty.');
$this
->assertNotSame(FALSE, strpos($mail['body'], $account->name->value), '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'], $account->name->value), 'Invoice body contains username.');
$this
->assertNotSame(FALSE, strpos($mail['body'], $account->password), 'Invoice body contains password.');
// We can check the password now we know it.
$assert
->pageTextContains($account->name->value, 'Username is shown on screen.');
$assert
->pageTextContains($account->password, 'Password is shown on screen.');
// 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' => $account->name->value,
'pass' => $account->password,
];
$this
->drupalGet('user');
$this
->submitForm($edit, 'Log in');
}