You are here

public function CommerceCheckoutTestProcess::testCommerceCheckoutProcessAnonymousNonExistingUser in Commerce Core 7

Test the checkout process with anonymous user using an e-mail addres that doesn't exists in the system, the final result is that the user gets the account created and the order is assigned to that user.

File

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

Class

CommerceCheckoutTestProcess
Test checkout process.

Code

public function testCommerceCheckoutProcessAnonymousNonExistingUser() {

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

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

  // Generate random information, as user mail, city, etc.
  $user_mail = $this
    ->randomName() . '@example.com';
  $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]' => $user_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);

  // Check if the order completion triggered the user creation rule.
  $user = user_load(reset($order)->uid);
  $this
    ->assertEqual($user->mail, $user_mail, t('The e-mail address of the owner of the order matches the one in the checkout input'));
  $this
    ->assertTrue($this->store_customer->uid < $user->uid, t('User id of the new user is higher than the last user created then it is a new account'));
}