You are here

protected function CommercePaymentUITest::createOrderAndGoToPayment in Commerce Core 7

Create a dummy order and go to checkout payment page.

2 calls to CommercePaymentUITest::createOrderAndGoToPayment()
CommercePaymentUITest::testCommercePaymentCheckout in modules/payment/tests/commerce_payment_ui.test
Test the payment on checkout process using an authenticated user.
CommercePaymentUITest::testCommercePaymentMethodsAdministration in modules/payment/tests/commerce_payment_ui.test
Test payment method rules conditions.

File

modules/payment/tests/commerce_payment_ui.test, line 49
Functional tests for the commerce payment module user interface.

Class

CommercePaymentUITest
Test payment user interface.

Code

protected function createOrderAndGoToPayment($user = NULL, $products = array()) {
  if (empty($user)) {
    $user = $this->store_customer;
  }

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

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

  // Go to checkout page.
  $this
    ->drupalGet($this
    ->getCommerceUrl('checkout'));

  // Check if the page resolves and if the default panes are present.
  $this
    ->assertResponse(200, t('Store customer user is able to access the checkout page'));
  $this
    ->assertTitle(t('Checkout') . ' | Drupal', t('Checkout page successfully loaded'));

  // 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]' => $address_info['administrative_area'],
    'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
  );
  $this
    ->drupalPost(NULL, $info, t('Continue to next step'));

  // Check for default panes and information in this checkout phase.
  $this
    ->assertTitle(t('Review order') . ' | Drupal', t('Review order page successfully loaded'));
}