uc_roles.test 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. protected function setUp($modules = array(), $permissions = array()) {
  21. $modules = array('uc_payment', 'uc_payment_pack', 'uc_roles');
  22. // Needed to see/modify roles on the /user/%/edit page
  23. $permissions = array('administer permissions', 'administer users', 'view all role expirations');
  24. parent::setUp($modules, $permissions);
  25. }
  26. function testRolePurchaseCheckout() {
  27. // Add role assignment to the test product.
  28. $rid = $this->drupalCreateRole(array('access content'));
  29. $this->drupalLogin($this->adminUser);
  30. $this->drupalPost('node/' . $this->product->nid . '/edit/features', array('feature' => 'role'), t('Add'));
  31. $edit = array(
  32. 'uc_roles_role' => $rid,
  33. 'end_override' => TRUE,
  34. 'uc_roles_expire_relative_duration' => 1,
  35. 'uc_roles_expire_relative_granularity' => 'day',
  36. );
  37. $this->drupalPost(NULL, $edit, t('Save feature'));
  38. // Check out with the test product.
  39. $this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
  40. $order = $this->checkout();
  41. uc_payment_enter($order->order_id, 'other', $order->order_total);
  42. // Test that the role was granted.
  43. $account = user_load($order->uid);
  44. $this->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.');
  45. // Test that the email is correct.
  46. $mail = $this->findMail('/Ubercart: ' . preg_quote($account->roles[$rid]) . ' role granted/');
  47. // Delete the user.
  48. user_delete($order->uid);
  49. // Run cron to ensure deleted users are handled correctly.
  50. $this->drupalLogout();
  51. $this->cronRun();
  52. }
  53. function testRoleAdminDelete() {
  54. // Add role assignment to the test product.
  55. $rid = $this->drupalCreateRole(array('access content'));
  56. $this->drupalLogin($this->adminUser);
  57. $this->drupalPost('node/' . $this->product->nid . '/edit/features', array('feature' => 'role'), t('Add'));
  58. $edit = array(
  59. 'uc_roles_role' => $rid,
  60. 'end_override' => TRUE,
  61. 'uc_roles_expire_relative_duration' => 1,
  62. 'uc_roles_expire_relative_granularity' => 'day',
  63. );
  64. $this->drupalPost(NULL, $edit, t('Save feature'));
  65. // Check out with the test product.
  66. $this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
  67. $order = $this->checkout();
  68. uc_payment_enter($order->order_id, 'other', $order->order_total);
  69. // Test that the role was granted.
  70. $account = user_load($order->uid);
  71. $this->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.');
  72. // Test that the role appears on the user edit page.
  73. $this->drupalGet('user/' . $order->uid . '/edit');
  74. $this->assertText('Ubercart roles', 'Ubercart roles fieldset found.');
  75. $this->assertNoText('There are no pending expirations for roles this user.', 'User has a role expiration.');
  76. // Delete the role using the Drupal user edit page
  77. // by unchecking the role and submitting the form.
  78. $this->drupalPost(
  79. 'user/' . $order->uid . '/edit',
  80. array('roles[' . $rid . ']' => FALSE),
  81. t('Save')
  82. );
  83. // Test that the role was removed.
  84. $account = user_load($order->uid, TRUE);
  85. $this->assertFalse(isset($account->roles[$rid]), 'Role was removed from user.');
  86. // Test that the role expiration data was removed.
  87. $this->assertText('There are no pending expirations for roles this user.', 'User has no role expirations.');
  88. }
  89. }