You are here

function UbercartRolesTestCase::testRolePurchaseCheckout in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_roles/tests/uc_roles.test \UbercartRolesTestCase::testRolePurchaseCheckout()

File

uc_roles/uc_roles.test, line 27
Role assignment product feature tests.

Class

UbercartRolesTestCase
Tests the role purchase functionality.

Code

function testRolePurchaseCheckout() {

  // 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'));
  $edit = array(
    'uc_roles_role' => $rid,
    'end_override' => TRUE,
    'uc_roles_expire_relative_duration' => 1,
    'uc_roles_expire_relative_granularity' => 'day',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save feature'));

  // Check out with the test product.
  $this
    ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
  $order = $this
    ->checkout();
  uc_payment_enter($order->order_id, 'other', $order->order_total);

  // Test that the role was granted.
  $account = user_load($order->uid);
  $this
    ->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.');

  // Test that the email is correct.
  $mail = $this
    ->findMail('/Our store: ' . preg_quote($account->roles[$rid]) . ' role granted/');

  // Delete the user.
  user_delete(array(), $order->uid);

  // Run cron to ensure deleted users are handled correctly.
  $this
    ->drupalLogout();
  $this
    ->cronRun();
}