public function OrderAdminTest::testResendReceipt in Commerce Core 8.2
Tests resending the order receipt.
File
- modules/
order/ tests/ src/ FunctionalJavascript/ OrderAdminTest.php, line 362
Class
- OrderAdminTest
- Tests the order admin UI.
Namespace
Drupal\Tests\commerce_order\FunctionalJavascriptCode
public function testResendReceipt() {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $this
->createEntity('commerce_order', [
'type' => 'default',
'mail' => $this->loggedInUser
->getEmail(),
'uid' => $this->loggedInUser,
'store_id' => $this->store,
'locked' => TRUE,
]);
// No access until the order has been placed.
$this
->drupalGet($order
->toUrl('resend-receipt-form'));
$this
->assertSession()
->pageTextContains('Access denied');
// Placing the order sends the receipt.
$transition = $order
->getState()
->getTransitions();
$order
->getState()
->applyTransition($transition['place']);
$order
->save();
$emails = $this
->getMails();
$this
->assertEquals(1, count($emails));
$email = array_pop($emails);
$this
->assertEquals('Order #' . $order
->getOrderNumber() . ' confirmed', $email['subject']);
// Change the order number to differentiate from automatic email.
$order
->setOrderNumber('2018/01');
$order
->save();
$this
->drupalGet($order
->toUrl('resend-receipt-form'));
$this
->assertSession()
->pageTextContains(t('Are you sure you want to resend the receipt for order @label?', [
'@label' => $order
->label(),
]));
$this
->submitForm([], t('Resend receipt'));
$emails = $this
->getMails();
$this
->assertEquals(2, count($emails));
$email = array_pop($emails);
$this
->assertEquals('Order #2018/01 confirmed', $email['subject']);
$this
->assertSession()
->pageTextContains("Order receipt resent.");
}