public function OrderAdminTest::testAdminOrderView in Commerce Core 8.2
Tests that an admin can view an order's details.
File
- modules/
order/ tests/ src/ FunctionalJavascript/ OrderAdminTest.php, line 405
Class
- OrderAdminTest
- Tests the order admin UI.
Namespace
Drupal\Tests\commerce_order\FunctionalJavascriptCode
public function testAdminOrderView() {
// Start from an order without any order items.
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $this
->createEntity('commerce_order', [
'type' => 'default',
'store_id' => $this->store
->id(),
'mail' => $this->loggedInUser
->getEmail(),
'state' => 'draft',
'uid' => $this->loggedInUser,
]);
// First test that the current admin user can see the order.
$this
->drupalGet($order
->toUrl()
->toString());
$this
->assertSession()
->pageTextContains($this->loggedInUser
->getEmail());
// Confirm that the order item table is showing the empty text.
$this
->assertSession()
->pageTextContains('There are no order items yet.');
$this
->assertSession()
->pageTextNotContains('Subtotal');
// Confirm that the transition buttons are visible and functional.
$workflow = $order
->getState()
->getWorkflow();
$transitions = $workflow
->getAllowedTransitions($order
->getState()
->getId(), $order);
foreach ($transitions as $transition) {
$this
->assertSession()
->linkExists($transition
->getLabel());
}
$this
->click('a.button#edit-place');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains('Are you sure you want to apply this transition?');
$this
->assertSession()
->linkExists('Cancel');
$this
->assertSession()
->buttonExists('Confirm');
// Note, there is some odd behavior calling the `press()` method on the
// button, so after asserting it exists, click via this method.
$this
->click('button:contains("Confirm")');
$this
->assertSession()
->linkNotExists('Place order');
$this
->assertSession()
->linkNotExists('Cancel order');
// The order was modified and needs to be reloaded.
$order = $this
->reloadEntity($order);
// Add an order item, confirm that it is displayed.
$order_item = $this
->createEntity('commerce_order_item', [
'type' => 'default',
'unit_price' => [
'number' => '999',
'currency_code' => 'USD',
],
]);
$order
->setItems([
$order_item,
]);
$order
->save();
$this
->drupalGet($order
->toUrl()
->toString());
$this
->assertSession()
->pageTextNotContains('There are no order items yet.');
$this
->assertSession()
->pageTextContains('$999.00');
$this
->assertSession()
->pageTextContains('Subtotal');
// Logout and check that anonymous users cannot see the order admin screen.
$this
->drupalLogout();
$this
->drupalGet($order
->toUrl()
->toString());
$this
->assertSession()
->pageTextContains('Access denied');
}