You are here

function UbercartCartCheckoutTestCase::testCheckoutComplete in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_cart/tests/uc_cart.test \UbercartCartCheckoutTestCase::testCheckoutComplete()

File

uc_cart/uc_cart.test, line 342
Shopping cart and checkout tests.

Class

UbercartCartCheckoutTestCase
Tests the cart and checkout functionality.

Code

function testCheckoutComplete() {

  // Payment notification is received first.
  $order_data = array(
    'primary_email' => 'simpletest@ubercart.org',
  );
  $order = $this
    ->createOrder($order_data);
  uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);
  uc_cart_complete_sale($order);

  // Check that a new account was created.
  $this
    ->assertTrue($order->data['complete_sale'] == 'new_user', 'A new account was created.');

  // 3 e-mails: new account, customer invoice, admin invoice
  $mails = $this
    ->drupalGetMails();
  $this
    ->assertEqual(count($mails), 3, '3 e-mails were sent.');
  variable_del('drupal_test_email_collector');
  $password = $mails[0]['params']['account']->password;
  $this
    ->assertTrue(!empty($password), 'New password is not empty.');
  $this
    ->assertTrue(strpos($mails[0]['body'], $password) !== FALSE, 'Mail body contains password.');

  // Different user, sees the checkout page first.
  $order_data = array(
    'primary_email' => 'simpletest2@ubercart.org',
  );
  $order = $this
    ->createOrder($order_data);
  uc_cart_complete_sale($order, TRUE);
  uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);

  // Check that a new account was created.
  $this
    ->assertTrue($order->data['complete_sale'] == 'new_user', 'A new account was created.');

  // 3 e-mails: new account, customer invoice, admin invoice
  $mails = $this
    ->drupalGetMails();
  $this
    ->assertEqual(count($mails), 3, '3 e-mails were sent.');
  variable_del('drupal_test_email_collector');
  $password = $mails[0]['params']['account']->password;
  $this
    ->assertTrue(!empty($password), 'New password is not empty.');
  $this
    ->assertTrue(strpos($mails[0]['body'], $password) !== FALSE, 'Mail body contains password.');

  // Same user, new order.
  $order = $this
    ->createOrder($order_data);
  uc_cart_complete_sale($order, TRUE);
  uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);

  // Check that no new account was created.
  $this
    ->assertTrue($order->data['complete_sale'] == 'existing_user', 'The order was attached to an existing account.');

  // 2 e-mails: customer invoice, admin invoice
  $mails = $this
    ->drupalGetMails();
  $this
    ->assertEqual(count($mails), 2, '2 e-mails were sent.');
  variable_del('drupal_test_email_collector');
}