masquerade.test 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @file
  4. * masquerade.test
  5. *
  6. * Test the form permissions and switch ability of the Masquarade module.
  7. */
  8. class MasqueradeTestCase extends DrupalWebTestCase {
  9. public static function getInfo() {
  10. return array(
  11. 'name' => 'Masquerade tests',
  12. 'description' => 'Tests user switching with the Masquerade module.',
  13. 'group' => 'Masquerade',
  14. );
  15. }
  16. public function setUp() {
  17. parent::setUp('masquerade');
  18. }
  19. public function testMasquerade() {
  20. $admin_perms = array(
  21. 'administer site configuration',
  22. 'administer permissions',
  23. 'administer blocks',
  24. 'administer masquerade',
  25. 'administer users',
  26. 'access user profiles',
  27. 'masquerade as user',
  28. 'masquerade as any user',
  29. );
  30. $admin = $this->drupalCreateUser($admin_perms);
  31. $user = $this->drupalCreateUser();
  32. $this->drupalLogin($admin);
  33. // Test accessing the admin form
  34. $this->drupalGet('admin/config/people/masquerade');
  35. $this->assertText(t('Roles that are considered "administrators" for masquerading'));
  36. // Test enabling the Masquerade block
  37. $this->drupalGet('admin/structure/block/manage/masquerade/masquerade/configure');
  38. $this->assertText(t("'@module' block", array('@module' => 'Masquerade')));
  39. $edit = array(
  40. 'regions[bartik]' => 'content',
  41. 'regions[seven]' => 'content',
  42. );
  43. $this->drupalPost('admin/structure/block/manage/masquerade/masquerade/configure', $edit, t('Save block'));
  44. $this->assertText(t('The block configuration has been saved.'));
  45. // Test switch from user profile
  46. $this->drupalGet("user/{$user->uid}");
  47. $this->clickLink(t('Masquerade as @name', array('@name' => $user->name)));
  48. $this->assertText(t('You are now masquerading as @name.', array('@name' => $user->name)));
  49. // Test unswitch
  50. $this->drupalGet('');
  51. $this->clickLink(t('Switch back'));
  52. $this->assertText(t('You are no longer masquerading as @name and are now logged in as @admin.',
  53. array('@name' => $user->name, '@admin' => $admin->name)));
  54. // Test switch from masquerade block
  55. $edit = array(
  56. 'masquerade_user_field' => $user->name,
  57. );
  58. $this->drupalPost('', $edit, t('Go'));
  59. $this->assertText(t('You are now masquerading as @name.', array('@name' => $user->name)));
  60. }
  61. }