You are here

protected function CommerceCheckoutTestProcess::prepareAnonymousEnviroment in Commerce Core 7

Helper function to prepare an anonymous enviroment, it sets the user, products and prepares a cart.

4 calls to CommerceCheckoutTestProcess::prepareAnonymousEnviroment()
CommerceCheckoutTestProcess::testCommerceCheckoutProcessAnonymousExistingUser in modules/checkout/tests/commerce_checkout.test
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.
CommerceCheckoutTestProcess::testCommerceCheckoutProcessAnonymousNonExistingUser in modules/checkout/tests/commerce_checkout.test
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.
CommerceCheckoutTestProcess::testCommerceCheckoutProcessAnonymousUser in modules/checkout/tests/commerce_checkout.test
Test the checkout process with anonymous user.
CommerceCheckoutTestProcess::testCommerceCheckoutValidatePanesAnonymousUser in modules/checkout/tests/commerce_checkout.test
Test the checkout validation panes with anonymous user.

File

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

Class

CommerceCheckoutTestProcess
Test checkout process.

Code

protected function prepareAnonymousEnviroment() {

  // Login as admin user to grant permissions.
  $this
    ->drupalLogin($this->site_admin);
  user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
    'access checkout' => TRUE,
  ));

  // Create a dummy product display content type.
  $this
    ->createDummyProductDisplayContentType();

  // Create dummy product display nodes (and their corresponding product
  //  entities).
  $sku = 'PROD-01';
  $product_name = 'Product One';
  $this->product = $this
    ->createDummyProduct($sku, $product_name);
  $this->product_node = $this
    ->createDummyProductNode(array(
    $this->product->product_id,
  ), $product_name);

  // Logout to test the checkout process with anonymous user.
  $this
    ->drupalLogout();

  // Override user variable to get the enviroment fully set.
  global $user;
  $user = user_load(0);

  // Submit the add to cart form.
  $this
    ->drupalPost('node/' . $this->product_node->nid, array(), t('Add to cart'));

  // Get the order for the anonymous user.
  $orders = commerce_order_load_multiple(array(), array(
    'uid' => $user->uid,
    'status' => 'cart',
  ), TRUE);
  $this->order = reset($orders);

  // Reset the cache as we don't want to keep the lock.
  entity_get_controller('commerce_order')
    ->resetCache();
}