public function UCXFTestCase::checkout in Extra Fields Checkout Pane 6.2
Same name and namespace in other branches
- 7 uc_extra_fields_pane.test \UCXFTestCase::checkout()
Overrides UbercartTestHelper::checkout().
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 400 - 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();
$custom_fields = UCXF_FieldList::getAllCustomFields();
$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),
)));
// Check if the textfield in the extra information pane is prefilled with 'default text'.
$this
->assertFieldByName('panes[extra_information][information_' . $this->infoTextField . ']', 'default text', t('The field %field has a default value.', array(
'%field' => $this
->getFieldname($this->infoTextField),
)));
// Fill in value for every field
$delivery_values = $this
->getEditValues($address_fields, array(
'panes',
'delivery',
), array(), 'delivery_');
$billing_values = $this
->getEditValues($address_fields, array(
'panes',
'billing',
), array(), 'billing_');
$info_values = $this
->getEditValues($custom_fields, array(
'panes',
'extra_information',
), array(), 'information_');
$edit = array_merge($delivery_values['form_values'], $billing_values['form_values'], $info_values['form_values'], $edit);
// Follow the logics of standard Ubercart checkout.
$order = parent::checkout($edit);
// $order can be an integer or an object.
if (is_numeric($order)) {
$order_id = $order;
$this
->pass(t('An order (!type) was created properly by UbercartTestHelper::checkout().', array(
'!type' => gettype($order),
)));
}
elseif (is_object($order)) {
$order_id = $order->order_id;
$this
->pass(t('An order (!type) was created properly by UbercartTestHelper::checkout().', array(
'!type' => gettype($order),
)));
}
else {
// We got something unexpected back from Ubercart.
// Note a failure and skip other checks in this method.
$this
->fail(t('An order (!type) was created properly by UbercartTestHelper::checkout().', array(
'!type' => gettype($order),
)));
return $order;
}
// Check if every value is saved correctly.
$this
->checkValuesInDatabase($delivery_values['values'], $order_id, UCXF_Value::UCXF_VALUE_ORDER_DELIVERY);
$this
->checkValuesInDatabase($billing_values['values'], $order_id, UCXF_Value::UCXF_VALUE_ORDER_BILLING);
$this
->checkValuesInDatabase($info_values['values'], $order_id, UCXF_Value::UCXF_VALUE_ORDER_INFO);
// Check if token values are properly generated.
$this
->checkTokens($delivery_values['values'], $order_id, UCXF_Value::UCXF_VALUE_ORDER_DELIVERY);
$this
->checkTokens($billing_values['values'], $order_id, UCXF_Value::UCXF_VALUE_ORDER_BILLING);
$this
->checkTokens($info_values['values'], $order_id, UCXF_Value::UCXF_VALUE_ORDER_INFO);
// Return the same as what UbercartTestHelper::checkout() returned.
return $order;
}