You are here

public function CommerceOrderUIAdminTest::testCommerceOrderUIEditOrder in Commerce Core 7

Test general edit form fields of an order.

File

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

Class

CommerceOrderUIAdminTest
Functional tests for the commerce order UI module.

Code

public function testCommerceOrderUIEditOrder() {

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

  // Navigate to the order edit page, it shouldn't be accessible.
  $this
    ->drupalGet('admin/commerce/orders/' . $this->order->order_id . '/edit');
  $this
    ->assertResponse(403, t('Normal user is not able to access the order edit admin screen'));

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

  // Access the edit page of the order.
  $this
    ->drupalGet('admin/commerce/orders/' . $this->order->order_id . '/edit');
  $this
    ->assertResponse(200, t('Store admin user can access the order edit admin screen'));

  // Update some values, like the owner of the order, datestamp, etc.
  $timestamp = REQUEST_TIME;
  $edit = array(
    'name' => '',
    'log' => $this
      ->randomName(),
    'date_created' => format_date($timestamp, 'custom', 'Y-m-d H:i:s O'),
    'date_placed' => format_date($timestamp, 'custom', 'Y-m-d H:i:s O'),
    'status' => 'completed',
  );

  // Save the order.
  $this
    ->drupalPost(NULL, $edit, t('Save order', array(), array(
    'context' => 'a drupal commerce order',
  )));

  // Reload the order from database.
  $orders = commerce_order_load_multiple(array(
    $this->order->order_id,
  ), array(), TRUE);
  $order = reset($orders);
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

  // Check the order properties.
  $this
    ->pass(t('Order in database assertions:'));
  $this
    ->assertTrue($order_wrapper->uid
    ->value() == 0, t('Order owner correctly updated'));
  $this
    ->assertTrue($order->log == $edit['log'], t('Order log correctly updated'));
  $this
    ->assertTrue($order_wrapper->created
    ->value() == $timestamp, t('Order created date correctly updated'));
  $this
    ->assertTrue($order_wrapper->placed
    ->value() == $timestamp, t('Order placed date correctly updated'));
  $this
    ->assertTrue($order_wrapper->status
    ->value() == $edit['status'], t('Order status correctly updated'));

  // Check if the values have been changed. Log is not checked because it
  // is a message for each revision.
  $this
    ->pass(t('Order in screen assertions:'));
  $this
    ->assertFieldById('edit-name', $edit['name'], t('Name correctly modified'));
  $this
    ->assertFieldById('edit-date-created', $edit['date_created'], t('Created date changed correctly'));
  $this
    ->assertFieldById('edit-date-placed', $edit['date_placed'], t('Placed date changed correctly'));
  $this
    ->assertOptionSelected('edit-status', $edit['status'], t('Status changed'));
}