You are here

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

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

Test the order administration.

File

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

Class

UCXFOrderTestCase
Order testcase

Code

public function testOrder() {

  // Setup default fields
  $this
    ->setupFields();
  $address_fields = UCXF_FieldList::getAllAddressFields();
  $custom_fields = UCXF_FieldList::getAllCustomFields();
  $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_information')) {
      $formfieldname = 'ucxf_information[information_' . $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_delivery')) {
      $formfieldname = '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 = '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(), $extra_values, 'delivery_');
  $billing_values = $this
    ->getEditValues($address_fields, array(), $extra_values, 'billing_');
  $extra_values = array(
    $this->hiddenPhpField => $this
      ->randomString(8),
  );
  $info_values = $this
    ->getEditValues($custom_fields, array(
    'ucxf_information',
  ), $extra_values, 'information_');
  $edit = array_merge($delivery_values['form_values'], $billing_values['form_values'], $info_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);
  $this
    ->checkValuesInDatabase($info_values['values'], $order->order_id, UCXF_Value::UCXF_VALUE_ORDER_INFO);
}