public function CommerceCheckoutTestProcess::testCommerceCheckoutValidatePanesAnonymousUser in Commerce Core 7
Test the checkout validation panes with anonymous user.
File
- modules/
checkout/ tests/ commerce_checkout.test, line 194 - Functional tests for the commerce checkout module.
Class
- CommerceCheckoutTestProcess
- Test checkout process.
Code
public function testCommerceCheckoutValidatePanesAnonymousUser() {
// Prepare the cart for Anonymous.
$this
->prepareAnonymousEnviroment();
// Access to checkout page.
$this
->drupalGet($this
->getCommerceUrl('checkout'));
// Test billing information and account information panes.
$this
->assertText(t('Billing information'), t('Billing information pane is present in the checkout page'));
$this
->assertText(t('Account information'), t('Account information pane is present in the checkout page'));
// Test validation messages not filling any information.
$this
->drupalPost(NULL, array(), t('Continue to next step'));
// Get all panes from the system to get their forms.
$panes = commerce_checkout_panes();
// Test the validation of Billing Information pane.
$callback = commerce_checkout_pane_callback($panes['customer_profile_billing'], 'checkout_form');
$pane_form = drupal_get_form($callback, $panes['customer_profile_billing'], $this->order);
foreach (element_children($pane_form['commerce_customer_address'][LANGUAGE_NONE][0]) as $key) {
$element = $pane_form['commerce_customer_address'][LANGUAGE_NONE][0][$key];
if ($element['#required'] && empty($element['#default_value'])) {
$this
->assertText(t('!pane_message field is required', array(
'!pane_message' => $element['#title'],
)), t('Check required billing information pane messages'));
}
}
// Test the validation of Account pane.
$callback = commerce_checkout_pane_callback($panes['account'], 'checkout_form');
$pane_form = drupal_get_form($callback, $panes['account'], $this->order);
foreach (element_children($pane_form['login']) as $key) {
if ($pane_form['login'][$key]['#required']) {
$this
->assertText(t('!pane_message field is required', array(
'!pane_message' => $pane_form['login'][$key]['#title'],
)), t('Check required account pane message.'));
}
}
// Generate random information, as city name, postal code etc.
$address_info = $this
->generateAddressInformation();
// Also generate a not-valid mail address.
$user_mail = $this
->randomName();
// Fill in the billing address information
$billing_pane = $this
->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
$this
->drupalPostAJAX(NULL, array(
(string) $billing_pane[0]['name'] => 'US',
), (string) $billing_pane[0]['name']);
// Fill in the required information for billing pane, with a random State.
$info = array(
'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
);
// Also add the mail for the account pane.
$info += array(
'account[login][mail]' => $user_mail,
);
// Go to the next checkout step with the required information.
$this
->drupalPost(NULL, $info, t('Continue to next step'));
// Check if the wrong e-mail address fails validation.
$this
->assertRaw(t('The e-mail address %mail is not valid.', array(
'%mail' => $user_mail,
)), t('A warning message is displayed when the e-mail address for the anonymous user is not valid'));
// Fix it and continue to next step.
$user_mail = $this
->randomName() . '@example.com';
$info['account[login][mail]'] = $user_mail;
$this
->drupalPost(NULL, $info, t('Continue to next step'));
$this
->assertNoRaw(t('The e-mail address %mail is not valid.', array(
'%mail' => $user_mail,
)), t('A warning message is not displayed when the e-mail address for the anonymous user is valid'));
// Finish checkout process for good.
$this
->drupalPost(NULL, array(), t('Continue to next step'));
}