You are here

public function CommerceOrderUIAdminTest::testCommerceOrderUIDeleteOrder in Commerce Core 7

Test the deletion of an order.

File

modules/order/tests/commerce_order_ui.test, line 321
Functional tests for the commerce order UI module.

Class

CommerceOrderUIAdminTest
Functional tests for the commerce order UI module.

Code

public function testCommerceOrderUIDeleteOrder() {

  // Log in as a normal user.
  $this
    ->drupalLogin($this->store_customer);

  // Navigate to the page to delete the order.
  $this
    ->drupalGet('admin/commerce/orders/' . $this->order->order_id . '/delete');
  $this
    ->assertResponse(403, t('Normal user is not able to delete orders'));

  // Log in as store admin.
  $this
    ->drupalLogin($this->store_admin);

  // Navigate to the page to delete the order.
  $this
    ->drupalGet('admin/commerce/orders/' . $this->order->order_id . '/delete');

  // The confirmation page is accesible and the form is ok.
  $this
    ->assertResponse(200, t('Store admin user can access the order deletion page'));
  $this
    ->assertText(t('Deleting this order cannot be undone.'), t('The confirmation message for order delete is displayed'));

  // Delete the order.
  $this
    ->drupalPost(NULL, array(), t('Delete'));

  // Reload the order from database.
  $orders = commerce_order_load_multiple(array(
    $this->order->order_id,
  ), array(), TRUE);
  $order = reset($orders);
  $this
    ->assertFalse($order, t('Order has been deleted from database'));

  // Check if the confirmation message is displayed.
  $this
    ->assertText(t('Order @number has been deleted.', array(
    '@number' => $this->order->order_number,
  )), t('Order message for deletion is displayed with the correct order number'));

  // Check if the order is present in the page.
  $this
    ->assertText(t('No orders have been created yet.'), t('After deleting the only order created, there is no order left in the order admin screen'));
}