You are here

public function UCXFTestCase::checkout in Extra Fields Checkout Pane 7

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

Overrides UbercartTestHelper::checkout().

Return value

object An Ubercart order object, if checkout succeeded. False otherwise.

Overrides UbercartTestHelper::checkout

1 call to UCXFTestCase::checkout()
UCXFCheckoutTestCase::testCheckout in ./uc_extra_fields_pane.test
Test if checkout works as expected.

File

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

Class

UCXFTestCase
Base class for all Extra Fields Pane test cases.

Code

public function checkout($edit = array()) {
  $all_fields = UCXF_FieldList::getAllFields();
  $address_fields = UCXF_FieldList::getAllAddressFields();
  $values = array();
  $this
    ->drupalPost('cart', array(), 'Checkout');

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

  // Check if constant and php-string are present on the page.
  $this
    ->assertText('A constant, ', t('The field %field is correctly displayed on the page.', array(
    '%field' => $this
      ->getFieldname($this->constantField),
  )));
  $this
    ->assertText('A string', t('The field %field is correctly displayed on the page.', array(
    '%field' => $this
      ->getFieldname($this->phpField),
  )));

  // Ensure hidden constant/php-string fields are NOT present on the page.
  $this
    ->assertNoText('hidden constant', t('The field %field is correctly hidden from the page.', array(
    '%field' => $this
      ->getFieldname($this->hiddenConstantField),
  )));
  $this
    ->assertNoText('hidden string', t('The field %field is correctly hidden from the page.', array(
    '%field' => $this
      ->getFieldname($this->hiddenPhpField),
  )));

  // Fill in value for every field
  $delivery_values = $this
    ->getEditValues($address_fields, array(
    'panes',
    'delivery',
    'address',
  ), array(), 'delivery_');
  $billing_values = $this
    ->getEditValues($address_fields, array(
    'panes',
    'billing',
    'address',
  ), array(), 'billing_');
  $edit = array_merge($delivery_values['form_values'], $billing_values['form_values'], $edit);

  // Follow the logics of standard Ubercart checkout.
  $order = $this
    ->UbercartCheckout($edit);

  // Check if every value is saved correctly.
  $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);

  // Check if token values are properly generated.
  $this
    ->checkTokens($delivery_values['values'], $order->order_id, UCXF_Value::UCXF_VALUE_ORDER_DELIVERY);
  $this
    ->checkTokens($billing_values['values'], $order->order_id, UCXF_Value::UCXF_VALUE_ORDER_BILLING);
  return $order;
}