You are here

public function CommerceCheckoutTestProcess::testCommerceCheckoutProcessAnonymousExistingUser in Commerce Core 7

Test the checkout process with anonymous user using an e-mail address that belongs to an existing user, the final result should be the order assigned to the existing user.

File

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

Class

CommerceCheckoutTestProcess
Test checkout process.

Code

public function testCommerceCheckoutProcessAnonymousExistingUser() {

  // Prepare the cart for Anonymous.
  $this
    ->prepareAnonymousEnviroment();

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

  // Generate random information.
  $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']);

  // 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]' => $this->store_customer->mail,
  );

  // Go to the next checkout step with the required information.
  $this
    ->drupalPost(NULL, $info, t('Continue to next step'));

  // Finish checkout process
  $this
    ->drupalPost(NULL, array(), t('Continue to next step'));

  // Reload the order directly from db to check its owner.
  $order = commerce_order_load_multiple(array(
    $this->order->order_id,
  ), array(), TRUE);

  // Assert that the owner of the order is the owner of the e-mail address used.
  $this
    ->assertEqual($this->store_customer->uid, reset($order)->uid, t('The order has been correctly assigned to the user owner of the mail address'));
}