uc_roles.test 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @file
  4. * Role assignment product feature tests.
  5. */
  6. /**
  7. * Tests the role purchase functionality.
  8. */
  9. class UbercartRolesTestCase extends UbercartTestHelper {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Roles',
  13. 'description' => 'Ensures that the purchase of roles functions correctly.',
  14. 'group' => 'Ubercart',
  15. );
  16. }
  17. /**
  18. * Overrides DrupalWebTestCase::setUp().
  19. */
  20. function setUp() {
  21. $modules = array('uc_payment', 'uc_payment_pack', 'uc_roles');
  22. $permissions = array();
  23. parent::setUp($modules, $permissions);
  24. }
  25. function testRolePurchaseCheckout() {
  26. // Add role assignment to the test product.
  27. $rid = $this->drupalCreateRole(array('access content'));
  28. $this->drupalLogin($this->adminUser);
  29. $this->drupalPost('node/' . $this->product->nid . '/edit/features', array('feature' => 'role'), t('Add'));
  30. $edit = array(
  31. 'uc_roles_role' => $rid,
  32. 'end_override' => TRUE,
  33. 'uc_roles_expire_relative_duration' => 1,
  34. 'uc_roles_expire_relative_granularity' => 'day',
  35. );
  36. $this->drupalPost(NULL, $edit, t('Save feature'));
  37. // Check out with the test product.
  38. $this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
  39. $order = $this->checkout();
  40. uc_payment_enter($order->order_id, 'other', $order->order_total);
  41. // Test that the role was granted.
  42. $account = user_load($order->uid);
  43. $this->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.');
  44. // Test that the email is correct.
  45. $mail = $this->findMail('/Ubercart: ' . preg_quote($account->roles[$rid]) . ' role granted/');
  46. // Delete the user.
  47. user_delete($order->uid);
  48. // Run cron to ensure deleted users are handled correctly.
  49. $this->drupalLogout();
  50. $this->cronRun();
  51. }
  52. }