You are here

public function CommerceCheckoutTestProcess::testCommerceCheckoutAccessPages in Commerce Core 7

Test order completion page access.

File

modules/checkout/tests/commerce_checkout.test, line 476
Functional tests for the commerce checkout module.

Class

CommerceCheckoutTestProcess
Test checkout process.

Code

public function testCommerceCheckoutAccessPages() {

  // Log in as normal user.
  $this
    ->drupalLogin($this->store_customer);

  // Order creation, in cart status.
  $this->order = $this
    ->createDummyOrder($this->store_customer->uid);

  // At this point, the rest of checkout pages shouldn't be accessible.
  $this
    ->assertCheckoutPageAccessible($this->order, '');
  $this
    ->assertCheckoutPageNotAccessible($this->order, 'review');
  $this
    ->assertCheckoutPageNotAccessible($this->order, 'payment');
  $this
    ->assertCheckoutPageNotAccessible($this->order, 'complete');

  // Generate random information, as city, postal code, etc.
  $address_info = $this
    ->generateAddressInformation();

  // 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']);

  // Check if the country has been selected correctly, this uses XPath as the
  //  ajax call replaces the element and the id may change
  $this
    ->assertFieldByXPath("//select[starts-with(@id, 'edit-customer-profile-billing-commerce-customer-address')]//option[@selected='selected']", 'US', t('Country selected'));

  // 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'],
  );
  $this
    ->drupalPost(NULL, $info, t('Continue to next step'));

  // At this point, only first page and review should be accessible, but the
  //  rest shouldn't.
  $this
    ->assertCheckoutPageAccessible($this->order, '');
  $this
    ->assertCheckoutPageAccessible($this->order, 'review');
  $this
    ->assertCheckoutPageNotAccessible($this->order, 'payment');
  $this
    ->assertCheckoutPageNotAccessible($this->order, 'complete');

  // Fill in the payment method and continue the process.
  $this
    ->drupalPost(NULL, array(), t('Continue to next step'));

  // At this point, only the complete page should be accessible.
  $this
    ->assertCheckoutPageNotAccessible($this->order, '');
  $this
    ->assertCheckoutPageNotAccessible($this->order, 'review');
  $this
    ->assertCheckoutPageNotAccessible($this->order, 'payment');
  $this
    ->assertCheckoutPageAccessible($this->order, 'complete');
}