123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * @file
- * Role assignment product feature tests.
- */
- /**
- * Tests the role purchase functionality.
- */
- class UbercartRolesTestCase extends UbercartTestHelper {
- public static function getInfo() {
- return array(
- 'name' => 'Roles',
- 'description' => 'Ensures that the purchase of roles functions correctly.',
- 'group' => 'Ubercart',
- );
- }
- /**
- * Overrides DrupalWebTestCase::setUp().
- */
- protected function setUp($modules = array(), $permissions = array()) {
- $modules = array('uc_payment', 'uc_payment_pack', 'uc_roles');
- // Needed to see/modify roles on the /user/%/edit page
- $permissions = array('administer permissions', 'administer users', 'view all role expirations');
- parent::setUp($modules, $permissions);
- }
- 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('/Ubercart: ' . preg_quote($account->roles[$rid]) . ' role granted/');
- // Delete the user.
- user_delete($order->uid);
- // Run cron to ensure deleted users are handled correctly.
- $this->drupalLogout();
- $this->cronRun();
- }
- function testRoleAdminDelete() {
- // 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 role appears on the user edit page.
- $this->drupalGet('user/' . $order->uid . '/edit');
- $this->assertText('Ubercart roles', 'Ubercart roles fieldset found.');
- $this->assertNoText('There are no pending expirations for roles this user.', 'User has a role expiration.');
- // Delete the role using the Drupal user edit page
- // by unchecking the role and submitting the form.
- $this->drupalPost(
- 'user/' . $order->uid . '/edit',
- array('roles[' . $rid . ']' => FALSE),
- t('Save')
- );
- // Test that the role was removed.
- $account = user_load($order->uid, TRUE);
- $this->assertFalse(isset($account->roles[$rid]), 'Role was removed from user.');
- // Test that the role expiration data was removed.
- $this->assertText('There are no pending expirations for roles this user.', 'User has no role expirations.');
- }
- }
|