You are here

public function UCXFOrderTestCase::testOrder in Extra Fields Checkout Pane 7

Same name and namespace in other branches
  1. 6.2 uc_extra_fields_pane.test \UCXFOrderTestCase::testOrder()

Test the order administration.

File

./uc_extra_fields_pane.test, line 894
Automated tests for Extra Fields Pane

Class

UCXFOrderTestCase
Order testcase

Code

public function testOrder() {

  // Setup default fields
  $this
    ->setupFields();
  $address_fields = UCXF_FieldList::getAllAddressFields();
  $edit = array();
  $values = array();

  // Create a new order.
  $order = uc_order_new($this->customer->uid);
  uc_order_comment_save($order->order_id, 0, t('Order created programmatically.'), 'admin');

  // Login as admin
  $this
    ->drupalLogin($this->adminUser);

  // Go to the order edit page.
  $this
    ->drupalGet('admin/store/orders/' . $order->order_id . '/edit');

  // Check if all address fields are available on the page.
  foreach ($address_fields as $field) {
    $this
      ->assertText($field
      ->output('label'), t('Field %field found on the page.', array(
      '%field' => $this
        ->getFieldname($field->db_name),
    )));
  }

  // Check if constant fields and php fields are now a textfield.
  $fields = array(
    'constant' => $this->constantField,
    'php' => $this->phpField,
    'hidden constant' => $this->hiddenConstantField,
    'hidden php' => $this->hiddenPhpField,
  );
  foreach ($fields as $type => $fieldname) {
    $field = UCXF_FieldList::getFieldByName($fieldname);
    if ($field
      ->in_pane('extra_delivery')) {
      $formfieldname = 'ship_to[address][delivery_' . $field->db_name . ']';
      $this
        ->assertFieldByName($formfieldname, '', t('Field %field of type %type is a textfield', array(
        '%field' => $field->label,
        '%type' => $type,
      )));
    }
    if ($field
      ->in_pane('extra_billing')) {
      $formfieldname = 'bill_to[address][billing_' . $field->db_name . ']';
      $this
        ->assertFieldByName($formfieldname, '', t('Field %field of type %type is a textfield', array(
        '%field' => $field->label,
        '%type' => $type,
      )));
    }
  }

  // Fill in value for every field.
  $extra_values = array(
    $this->constantField => $this
      ->randomString(8),
    $this->phpField => $this
      ->randomString(8),
    $this->hiddenConstantField => $this
      ->randomString(8),
  );
  $delivery_values = $this
    ->getEditValues($address_fields, array(
    'ship_to',
    'address',
  ), $extra_values, 'delivery_');
  $billing_values = $this
    ->getEditValues($address_fields, array(
    'bill_to',
    'address',
  ), $extra_values, 'billing_');
  $extra_values = array(
    $this->hiddenPhpField => $this
      ->randomString(8),
  );
  $edit = array_merge($delivery_values['form_values'], $billing_values['form_values'], $edit);

  // Post the values.
  $this
    ->drupalPost('admin/store/orders/' . $order->order_id . '/edit', $edit, t('Submit changes'));
  $this
    ->assertText(t('Order changes saved.'));

  // Check if the values are correctly saved to the database.
  $this
    ->checkValuesInDatabase($delivery_values['values'], $order->order_id, UCXF_Value::UCXF_VALUE_ORDER_DELIVERY);
  $this
    ->checkValuesInDatabase($billing_values['values'], $order->order_id, UCXF_Value::UCXF_VALUE_ORDER_BILLING);
}