You are here

public function UbercartCartCheckoutTestCase::testCheckoutRoleAssignment in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_cart/uc_cart.test \UbercartCartCheckoutTestCase::testCheckoutRoleAssignment()

File

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

Class

UbercartCartCheckoutTestCase
Tests the cart and checkout functionality.

Code

public function testCheckoutRoleAssignment() {

  // Add role assignment to the test product.
  $rid = $this
    ->drupalCreateRole(array(
    'access content',
  ));
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalPost('node/' . $this->product->nid . '/edit/features', array(
    'feature' => 'role',
  ), t('Add'));
  $this
    ->drupalPost(NULL, array(
    'uc_roles_role' => $rid,
  ), t('Save feature'));

  // Process an anonymous, shippable order.
  $item = clone $this->product;
  $item->qty = 1;
  $item->price = $item->sell_price;
  $item->data = array(
    'shippable' => TRUE,
  );
  $order = $this
    ->createOrder(array(
    'products' => array(
      $item,
    ),
  ));
  uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);

  // Find the order uid.
  $uid = db_query("SELECT uid FROM {uc_orders} ORDER BY order_id DESC")
    ->fetchField();
  $account = user_load($uid);
  $this
    ->assertTrue(isset($account->roles[$rid]), 'New user was granted role.');
  $order = uc_order_load($order->order_id);
  $this
    ->assertEqual($order->order_status, 'payment_received', 'Shippable order was set to payment received.');

  // 3 e-mails: new account, customer invoice, role assignment.
  $mails = $this
    ->drupalGetMails();
  $this
    ->assertEqual(count($mails), 3, '3 e-mails were sent.');
  variable_del('drupal_test_email_collector');

  // Test again with an existing email address and a non-shippable order.
  $item->data = array(
    'shippable' => FALSE,
  );
  $order = $this
    ->createOrder(array(
    'primary_email' => $this->customer->mail,
    'products' => array(
      $item,
    ),
  ));
  uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total);
  $account = user_load($this->customer->uid);
  $this
    ->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.');
  $order = uc_order_load($order->order_id);
  $this
    ->assertEqual($order->order_status, 'completed', 'Non-shippable order was set to completed.');

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