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