1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Test file for pm_block_user.module
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
class PrivatemsgBlockUserCase extends PrivatemsgBaseTestCase {
|
8 |
|
|
/**
|
9 |
|
|
* Implements getInfo().
|
10 |
|
|
*/
|
11 |
|
|
public static function getInfo() {
|
12 |
|
|
return array(
|
13 |
|
|
'name' => t('User blocking functionality.'),
|
14 |
|
|
'description' => t('Test blocking and unblocking of users'),
|
15 |
|
|
'group' => t('Privatemsg'),
|
16 |
|
|
);
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
function setUp() {
|
20 |
|
|
parent::setUp('privatemsg', 'pm_block_user');
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Test role blocking rules.
|
25 |
|
|
*/
|
26 |
|
|
function testRoleBlockRecipient() {
|
27 |
|
|
// User id 3, Role id 4.
|
28 |
|
|
$author_user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'access user profiles'));
|
29 |
|
|
// User id 4, Role id 5.
|
30 |
|
|
$blocked_user = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'access user profiles'));
|
31 |
|
|
// User id 5, Role id 6.
|
32 |
|
|
$admin_user = $this->drupalCreateUser(array('administer privatemsg settings'));
|
33 |
|
|
|
34 |
|
|
// Login the admin user and set up the role blocking rules.
|
35 |
|
|
$this->drupalLogin($admin_user);
|
36 |
|
|
|
37 |
|
|
$this->drupalPost('admin/config/messaging/privatemsg/block', array(), t('More'));
|
38 |
|
|
// If this fails we still have the default empty block user form.
|
39 |
|
|
$this->assertNoText(t('No rules have been added'), t('The block form now allows adding rules.'));
|
40 |
|
|
|
41 |
|
|
// If author role is 4 and recipent role is 5, disallow sending of messages.
|
42 |
|
|
$edit = array(
|
43 |
|
|
'block_actions[0][author]' => 3,
|
44 |
|
|
'block_actions[0][recipient]' => 4,
|
45 |
|
|
'block_actions[0][action]' => 1,
|
46 |
|
|
'block_actions[0][enabled]' => 1,
|
47 |
|
|
);
|
48 |
|
|
$this->drupalPost(NULL, $edit, t('Save configuration'));
|
49 |
|
|
|
50 |
|
|
// Verify that the user doesn't show up in the autocomplete.
|
51 |
|
|
// Login the user that will write a message to the user with the blocked role.
|
52 |
|
|
$this->drupalLogin($author_user);
|
53 |
|
|
|
54 |
|
|
$this->drupalGet('messages/new');
|
55 |
|
|
$this->assertText(t('Write new message'), t('Author user can write messages.'));
|
56 |
|
|
|
57 |
|
|
$this->drupalGet('messages/autocomplete/' . $blocked_user->name);
|
58 |
|
|
$this->assertNoText($blocked_user->name, t('User with blocked role does not appear in autocomplete results.'));
|
59 |
|
|
|
60 |
|
|
// Verify that link to send private message to blocked user is not shown on their profile page.
|
61 |
|
|
$this->drupalGet('user/' . $blocked_user->uid);
|
62 |
|
|
$this->assertNoText(t('Send this user a private message'), t("Author user cannot see link to send blocked user a message on blocked user's profile."));
|
63 |
|
|
|
64 |
|
|
// Verify that it is not possible to manually write a message to blocked user.
|
65 |
|
|
$this->drupalGet('messages/new');
|
66 |
|
|
$message = array(
|
67 |
|
|
'recipient' => $blocked_user->name,
|
68 |
|
|
'subject' => $this->randomName(20),
|
69 |
|
|
'body[value]' => $this->randomName(50),
|
70 |
|
|
);
|
71 |
|
|
|
72 |
|
|
$this->drupalPost('messages/new', $message, t('Send message'));
|
73 |
|
|
$this->assertText(t('You are not permitted to send messages to @recipient.' , array('@recipient' => $blocked_user->name)), t('Author user message to blocked user has been blocked.'));
|
74 |
|
|
|
75 |
|
|
// Verify that unblocked user can receive message from a multi-recipient message that includes blocked user.
|
76 |
|
|
$this->drupalGet('messages/new');
|
77 |
|
|
$message = array(
|
78 |
|
|
'recipient' => $admin_user->name . ', ' . $blocked_user->name,
|
79 |
|
|
'subject' => $this->randomName(20),
|
80 |
|
|
'body[value]' => $this->randomName(50),
|
81 |
|
|
);
|
82 |
|
|
|
83 |
|
|
$this->drupalPost('messages/new', $message, t('Send message'));
|
84 |
|
|
$this->assertText(t('You are not permitted to send messages to @recipient.' , array('@recipient' => $blocked_user->name)), t('Author user message to blocked user has been blocked.'));
|
85 |
|
|
$this->assertText(t('A message has been sent to @recipient.', array('@recipient' => $admin_user->name)), t('Author user message sent to admin user.'));
|
86 |
|
|
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
function testBlockAndUnblock() {
|
91 |
|
|
// Create needed users.
|
92 |
|
|
$user1 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'access user profiles'));
|
93 |
|
|
$user2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'access user profiles'));
|
94 |
|
|
$user3 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'access user profiles'));
|
95 |
|
|
|
96 |
|
|
// Set up a simple conversation.
|
97 |
|
|
$return = privatemsg_new_thread(array($user2, $user3), $subject = $this->randomName(20), $this->randomString(50), array('author' => $user1));
|
98 |
|
|
privatemsg_reply($return['message']->thread_id, $this->randomString(50), array('author' => $user2));
|
99 |
|
|
privatemsg_reply($return['message']->thread_id, $this->randomString(50), array('author' => $user3));
|
100 |
|
|
|
101 |
|
|
$this->drupalLogin($user1);
|
102 |
|
|
|
103 |
|
|
// Visit profile page of user 2 and verify that there is a link to write a
|
104 |
|
|
// message.
|
105 |
|
|
$this->drupalGet('user/' . $user2->uid);
|
106 |
|
|
$this->assertText(t('Send this user a private message'));
|
107 |
|
|
|
108 |
|
|
$this->drupalGet('messages');
|
109 |
|
|
$this->clickLink($subject);
|
110 |
|
|
|
111 |
|
|
// Block user2.
|
112 |
|
|
$this->clickLink(t('Block'));
|
113 |
|
|
$this->drupalPost(NULL, array(), t('Block @user', array('@user' => $user2->name)));
|
114 |
|
|
$this->assertText(t('@user has been blocked from sending you any further messages.', array('@user' => $user2->name)), t('Confirmation message displayed'));
|
115 |
|
|
|
116 |
|
|
// Block user3.
|
117 |
|
|
$this->clickLink(t('Block'));
|
118 |
|
|
$this->drupalPost(NULL, array(), t('Block @user', array('@user' => $user3->name)));
|
119 |
|
|
$this->assertText(t('@user has been blocked from sending you any further messages.', array('@user' => $user3->name)), t('Confirmation message displayed'));
|
120 |
|
|
|
121 |
|
|
// Visit blocked users list.
|
122 |
|
|
$this->drupalGet('messages/blocked');
|
123 |
|
|
|
124 |
|
|
$this->assertText($user2->name, t('User 2 displayed as blocked'));
|
125 |
|
|
$this->assertText($user3->name, t('User 3 displayed as blocked'));
|
126 |
|
|
|
127 |
|
|
// Unblock user2.
|
128 |
|
|
|
129 |
|
|
// Blocked users are sorted alphabetically, check which one is the first
|
130 |
|
|
// one in the list and set index based on that.
|
131 |
|
|
$rows = $this->xpath('//tbody/tr');
|
132 |
|
|
|
133 |
|
|
$index = (int) !($user2->name == (string)$rows[0]->td[0]->a);
|
134 |
|
|
$this->clickLink(t('unblock'), $index);
|
135 |
|
|
$this->drupalPost(NULL, array(), t('Unblock @user', array('@user' => $user2->name)));
|
136 |
|
|
$this->assertText(t('@user is now allowed to send you new messages.', array('@user' => $user2->name)), t('Confirmation message displayed'));
|
137 |
|
|
|
138 |
|
|
$this->assertText($user3->name, t('User 3 still displayed as blocked'));
|
139 |
|
|
|
140 |
|
|
// Unblock user3.
|
141 |
|
|
$this->clickLink(t('unblock'));
|
142 |
|
|
$this->drupalPost(NULL, array(), t('Unblock @user', array('@user' => $user3->name)));
|
143 |
|
|
$this->assertText(t('@user is now allowed to send you new messages.', array('@user' => $user3->name)), t('Confirmation message displayed'));
|
144 |
|
|
|
145 |
|
|
$this->drupalGet('messages/blocked');
|
146 |
|
|
$this->assertNoText($user2->name, t('User 2 not displayed as blocked anymore'));
|
147 |
|
|
$this->assertNoText($user3->name, t('User 3 not displayed as blocked anymore'));
|
148 |
|
|
|
149 |
|
|
// Block users again.
|
150 |
|
|
$edit = array('name' => $user2->name . ', ' . $user3->name);
|
151 |
|
|
$this->drupalPost(NULL, $edit, t('Block user'));
|
152 |
|
|
$this->assertText(t('@user has been blocked from sending you any further messages.', array('@user' => $user2->name)), t('Confirmation message displayed'));
|
153 |
|
|
$this->assertText(t('@user has been blocked from sending you any further messages.', array('@user' => $user3->name)), t('Confirmation message displayed'));
|
154 |
|
|
|
155 |
|
|
$this->drupalGet('messages');
|
156 |
|
|
$this->clickLink($subject);
|
157 |
|
|
|
158 |
|
|
$this->assertNoLink(t('Block'), t('No "Block user" links displayed.'));
|
159 |
|
|
|
160 |
|
|
// Log in as user2 and try to send messages to user1.
|
161 |
|
|
$this->drupalLogin($user2);
|
162 |
|
|
|
163 |
|
|
// Access profile to see if there is a write message link.
|
164 |
|
|
$this->drupalGet('user/' . $user1->uid);
|
165 |
|
|
$this->assertNoText(t('Send this user a private message'));
|
166 |
|
|
|
167 |
|
|
$edit = array(
|
168 |
|
|
'recipient' => $user1->name,
|
169 |
|
|
'subject' => $subject2 = $this->randomName(20),
|
170 |
|
|
'body[value]' => $this->randomName(50),
|
171 |
|
|
);
|
172 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
173 |
|
|
$this->assertRaw(t('%user has chosen to block messages from you.', array('%user' => $user1->name)), t('User 1 blocks user 2 message displayed'));
|
174 |
|
|
$this->assertText(t('You are not allowed to send this message because all recipients are blocked.'));
|
175 |
|
|
|
176 |
|
|
$edit = array(
|
177 |
|
|
'recipient' => $user1->name . ', ' . $user3->name,
|
178 |
|
|
'subject' => $subject3 = $this->randomName(20),
|
179 |
|
|
'body[value]' => $this->randomName(50),
|
180 |
|
|
);
|
181 |
|
|
$this->drupalPost('messages/new', $edit, t('Send message'));
|
182 |
|
|
$this->assertRaw(t('%user has chosen to block messages from you.', array('%user' => $user1->name)), t('User 1 blocks user 2 message displayed'));
|
183 |
|
|
$this->assertText(t('A message has been sent to @user.', array('@user' => $user3->name)), t('Message sent to user 3'));
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
// Try to reply to an existing thread.
|
187 |
|
|
$this->drupalGet('messages');
|
188 |
|
|
$this->clickLink($subject);
|
189 |
|
|
|
190 |
|
|
$edit = array('body[value]' => $reply = $this->randomName(50));
|
191 |
|
|
$this->drupalPost(NULL, $edit, t('Send message'));
|
192 |
|
|
$this->assertText(t('@user has chosen to block messages from you.', array('@user' => $user1->name)));
|
193 |
|
|
$this->assertText(t('A message has been sent to @user.', array('@user' => $user3->name)), t('Message sent to user 3'));
|
194 |
|
|
|
195 |
|
|
// Login as user1 again and check that we didn't recieve the messages.
|
196 |
|
|
$this->drupalLogin($user1);
|
197 |
|
|
$this->drupalGet('messages');
|
198 |
|
|
|
199 |
|
|
// Check that we didn't get the new messages.
|
200 |
|
|
$this->assertNoLink($subject2);
|
201 |
|
|
$this->assertNoLink($subject3);
|
202 |
|
|
|
203 |
|
|
// Check that we don't see the new messages.
|
204 |
|
|
$this->clickLink($subject);
|
205 |
|
|
$this->assertNoText($reply);
|
206 |
|
|
}
|
207 |
|
|
} |