1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
class ForumAccessBaseTestCase extends ForumTestCase {
|
12
|
|
13
|
protected $admin_rid;
|
14
|
protected $webmaster_rid;
|
15
|
protected $forum_admin_rid;
|
16
|
protected $edndel_any_content_rid;
|
17
|
protected $edndel_own_content_rid;
|
18
|
protected $edit_any_content_rid;
|
19
|
protected $edit_own_content_rid;
|
20
|
protected $delete_any_content_rid;
|
21
|
protected $delete_own_content_rid;
|
22
|
protected $create_content_rid;
|
23
|
protected $anon_rid;
|
24
|
protected $auth_rid;
|
25
|
protected $user1;
|
26
|
protected $webmaster_user;
|
27
|
protected $forum_admin_user;
|
28
|
protected $edndel_any_content_user;
|
29
|
protected $edndel_own_content_user;
|
30
|
protected $edit_any_content_user;
|
31
|
protected $edit_own_content_user;
|
32
|
protected $delete_any_content_user;
|
33
|
protected $delete_own_content_user;
|
34
|
protected $create_content_user;
|
35
|
protected $auth_user;
|
36
|
protected $moderator;
|
37
|
protected $time;
|
38
|
protected $accounts;
|
39
|
protected $rids;
|
40
|
protected $accesses;
|
41
|
|
42
|
|
43
|
|
44
|
|
45
|
function setUp($modules = array()) {
|
46
|
if (!isset($this->time)) {
|
47
|
$this->time = time();
|
48
|
}
|
49
|
$this->timeLimit = 2345;
|
50
|
$this->pass("timeLimit set to $this->timeLimit.");
|
51
|
parent::setUp();
|
52
|
if (!module_exists('forum_access')) {
|
53
|
module_enable(array('acl', 'chain_menu_access', 'forum_access'), FALSE);
|
54
|
}
|
55
|
$this->assertTrue(module_exists('acl'), t('Module %module enabled!', array('%module' => 'acl')), 'Setup');
|
56
|
$this->assertTrue(module_exists('chain_menu_access'), t('Module %module enabled!', array('%module' => 'chain_menu_access')), 'Setup');
|
57
|
$this->assertTrue(module_exists('forum_access'), t('Module %module enabled!', array('%module' => 'forum_access')), 'Setup');
|
58
|
$modules = array('devel', 'devel_node_access') + $modules;
|
59
|
$files = system_rebuild_module_data();
|
60
|
$available_modules = array();
|
61
|
foreach ($modules as $module) {
|
62
|
if (!empty($files[$module]) && !module_exists($module)) {
|
63
|
$available_modules[] = $module;
|
64
|
}
|
65
|
}
|
66
|
if (!empty($available_modules)) {
|
67
|
module_enable($available_modules);
|
68
|
}
|
69
|
parent::resetAll();
|
70
|
$this->accesses = array('view', 'create', 'update', 'delete');
|
71
|
}
|
72
|
|
73
|
|
74
|
|
75
|
|
76
|
|
77
|
|
78
|
|
79
|
|
80
|
function setUp2() {
|
81
|
$this->user1 = user_load(1);
|
82
|
|
83
|
$password = user_password();
|
84
|
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
|
85
|
$account = array(
|
86
|
'name' => 'user1',
|
87
|
'pass' => user_hash_password(trim($password)),
|
88
|
);
|
89
|
|
90
|
db_update('users')
|
91
|
->fields($account)
|
92
|
->condition('uid', 1)
|
93
|
->execute();
|
94
|
|
95
|
$this->user1 = user_load(1, TRUE);
|
96
|
$this->user1->pass_raw = $password;
|
97
|
|
98
|
|
99
|
$this->drupalLogin($this->user1);
|
100
|
$this->drupalPost('admin/reports/status/rebuild', array(), t('Rebuild permissions'));
|
101
|
|
102
|
if (module_exists('devel_node_access')) {
|
103
|
|
104
|
$this->drupalGet('admin/config/development/devel');
|
105
|
$this->assertResponse(200);
|
106
|
$this->drupalPost('admin/config/development/devel', array(
|
107
|
'devel_node_access_debug_mode' => '1',
|
108
|
), t('Save configuration'));
|
109
|
$this->assertResponse(200, 'Devel Node Access configuration saved.');
|
110
|
|
111
|
|
112
|
$this->drupalPost('admin/structure/block/list', array(
|
113
|
'blocks[devel_node_access_dna_user][region]' => 'footer',
|
114
|
), t('Save blocks'));
|
115
|
}
|
116
|
if (module_exists('devel')) {
|
117
|
$this->drupalPost('admin/config/development/devel', array(
|
118
|
'devel_error_handlers[]' => array(1, 2, 4),
|
119
|
), t('Save configuration'));
|
120
|
$this->assertResponse(200, 'Devel configuration saved.');
|
121
|
$this->drupalPost('admin/people/permissions/list', array(
|
122
|
'1[access devel information]' => 'access devel information',
|
123
|
'2[access devel information]' => 'access devel information',
|
124
|
), t('Save permissions'));
|
125
|
$this->assertResponse(200, 'Devel permissions saved.');
|
126
|
}
|
127
|
|
128
|
|
129
|
|
130
|
|
131
|
|
132
|
|
133
|
|
134
|
|
135
|
|
136
|
|
137
|
user_role_delete((int) reset($this->admin_user->roles));
|
138
|
user_role_delete((int) reset($this->edit_any_topics_user->roles));
|
139
|
user_role_delete((int) reset($this->edit_own_topics_user->roles));
|
140
|
user_delete($this->admin_user->uid);
|
141
|
user_delete($this->edit_any_topics_user->uid);
|
142
|
user_delete($this->edit_own_topics_user->uid);
|
143
|
user_delete($this->web_user->uid);
|
144
|
unset($this->web_user);
|
145
|
|
146
|
|
147
|
for ($i = 0; $i < 3; ++$i) {
|
148
|
$dummy_rid = (int) $this->drupalCreateRole(array(), 'dummy');
|
149
|
$dummy_user = $this->drupalCreateNamedUser('Dummy', array($dummy_rid));
|
150
|
user_role_delete($dummy_rid);
|
151
|
user_delete($dummy_user->uid);
|
152
|
}
|
153
|
|
154
|
|
155
|
$this->admin_rid = 3;
|
156
|
$this->webmaster_rid = (int) $this->drupalCreateRole(array('administer blocks', 'administer forums', 'administer nodes', 'administer comments', 'administer menu', 'administer taxonomy', 'create forum content', 'access content overview', 'access administration pages', 'view revisions', 'revert revisions', 'delete revisions'), '11 webmaster');
|
157
|
$this->forum_admin_rid = (int) $this->drupalCreateRole(array('administer forums', 'create forum content', 'edit any forum content', 'delete any forum content', ), '12 forum admin');
|
158
|
$this->edndel_any_content_rid = (int) $this->drupalCreateRole(array('create forum content', 'edit any forum content', 'delete any forum content', 'view own unpublished content'), '13 edndel any content');
|
159
|
$this->edndel_own_content_rid = (int) $this->drupalCreateRole(array('create forum content', 'edit own forum content', 'delete own forum content'), '14 edndel own content');
|
160
|
$this->edit_any_content_rid = (int) $this->drupalCreateRole(array('create forum content', 'edit any forum content', 'view own unpublished content'), '15 edit any content');
|
161
|
$this->edit_own_content_rid = (int) $this->drupalCreateRole(array('create forum content', 'edit own forum content', 'edit own comments'), '16 edit own content');
|
162
|
$this->delete_any_content_rid = (int) $this->drupalCreateRole(array('create forum content', 'delete any forum content', 'view own unpublished content'), '17 delete any content');
|
163
|
$this->delete_own_content_rid = (int) $this->drupalCreateRole(array('create forum content', 'delete own forum content', 'edit own comments'), '18 delete own content');
|
164
|
$this->create_content_rid = (int) $this->drupalCreateRole(array('create forum content'), '19 create content');
|
165
|
$this->anon_rid = DRUPAL_ANONYMOUS_RID;
|
166
|
$this->auth_rid = DRUPAL_AUTHENTICATED_RID;
|
167
|
|
168
|
|
169
|
$this->admin_user = $this->drupalCreateNamedUser('10_Administrator', array($this->admin_rid));
|
170
|
$this->webmaster_user = $this->drupalCreateNamedUser('11_Webmaster', array($this->webmaster_rid));
|
171
|
$this->forum_admin_user = $this->drupalCreateNamedUser('12_Forum_admin', array($this->forum_admin_rid));
|
172
|
$this->edndel_any_content_user = $this->drupalCreateNamedUser('13_EdNDel_any_content', array($this->edndel_any_content_rid));
|
173
|
$this->edndel_own_content_user = $this->drupalCreateNamedUser('14_EdNDel_own_content', array($this->edndel_own_content_rid));
|
174
|
$this->edit_any_content_user = $this->drupalCreateNamedUser('15_Edit_any_content', array($this->edit_any_content_rid));
|
175
|
$this->edit_own_content_user = $this->drupalCreateNamedUser('16_Edit_own_content', array($this->edit_own_content_rid));
|
176
|
$this->delete_any_content_user = $this->drupalCreateNamedUser('17_Delete_any_content', array($this->delete_any_content_rid));
|
177
|
$this->delete_own_content_user = $this->drupalCreateNamedUser('18_Delete_own_content', array($this->delete_own_content_rid));
|
178
|
$this->create_content_user = $this->drupalCreateNamedUser('19_Create_content', array($this->create_content_rid));
|
179
|
$this->auth_user = $this->drupalCreateNamedUser('20_Auth_only', array());
|
180
|
$this->moderator = $this->drupalCreateNamedUser('21_Moderator', array($this->create_content_rid));
|
181
|
|
182
|
$anon = drupal_anonymous_user();
|
183
|
$anon->name = check_plain(format_username($anon));
|
184
|
$this->accounts = array(
|
185
|
$this->user1, $this->admin_user, $this->webmaster_user, $this->forum_admin_user,
|
186
|
$this->edndel_any_content_user, $this->edndel_own_content_user,
|
187
|
$this->edit_any_content_user, $this->edit_own_content_user,
|
188
|
$this->delete_any_content_user, $this->delete_own_content_user,
|
189
|
$this->create_content_user, $this->auth_user, $this->moderator,
|
190
|
);
|
191
|
$this->rids = array(
|
192
|
$this->anon_rid, $this->auth_rid, $this->admin_rid,
|
193
|
$this->webmaster_rid, $this->forum_admin_rid, $this->edndel_any_content_rid, $this->edndel_own_content_rid,
|
194
|
$this->edit_any_content_rid, $this->edit_own_content_rid,
|
195
|
$this->delete_any_content_rid, $this->delete_own_content_rid, $this->create_content_rid,
|
196
|
);
|
197
|
|
198
|
$this->drupalGet('admin/people/permissions/list');
|
199
|
$this->assertResponse(200, '^^^ Permissions');
|
200
|
$this->drupalGet('admin/people', array('query' => array('sort' => 'asc', 'order' => drupal_encode_path(t('Username')))));
|
201
|
$this->assertResponse(200, '^^^ Users');
|
202
|
}
|
203
|
|
204
|
function testForum() {
|
205
|
|
206
|
$this->pass('==========================<br />Empty testForum() @' . (time() - $this->time));
|
207
|
}
|
208
|
|
209
|
function testAddOrphanTopic() {
|
210
|
|
211
|
$this->pass('==========================<br />Empty testAddOrphanTopic() @' . (time() - $this->time));
|
212
|
}
|
213
|
|
214
|
function testEnableForumField() {
|
215
|
|
216
|
$this->pass('==========================<br />Empty testEnableForumField() @' . (time() - $this->time));
|
217
|
}
|
218
|
|
219
|
|
220
|
|
221
|
|
222
|
|
223
|
|
224
|
|
225
|
|
226
|
|
227
|
|
228
|
|
229
|
|
230
|
protected function assertFieldEnabled($id, $message = '') {
|
231
|
$elements = $this->xpath('//input[@id=:id]', array(':id' => $id));
|
232
|
return $this->assertTrue(isset($elements[0]) && empty($elements[0]['disabled']), $message ? $message : t('Field @id is enabled.', array('@id' => $id)), t('Browser'));
|
233
|
}
|
234
|
|
235
|
|
236
|
|
237
|
|
238
|
|
239
|
|
240
|
|
241
|
|
242
|
|
243
|
|
244
|
|
245
|
protected function assertFieldDisabled($id, $message = '') {
|
246
|
$elements = $this->xpath('//input[@id=:id]', array(':id' => $id));
|
247
|
return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['disabled']), $message ? $message : t('Field @id is disabled.', array('@id' => $id)), t('Browser'));
|
248
|
}
|
249
|
|
250
|
|
251
|
|
252
|
|
253
|
|
254
|
|
255
|
|
256
|
|
257
|
|
258
|
|
259
|
|
260
|
|
261
|
|
262
|
|
263
|
|
264
|
|
265
|
protected function assertButton($label, $index = 0, $message = '', $group = 'Other') {
|
266
|
$links = $this->xpath('//input[contains(@type, submit)][contains(@value, :label)]', array(':label' => $label));
|
267
|
$message = ($message ? $message : t('Button with label %label found.', array('%label' => $label)));
|
268
|
return $this->assert(isset($links[$index]), $message, $group);
|
269
|
}
|
270
|
|
271
|
|
272
|
|
273
|
|
274
|
|
275
|
|
276
|
|
277
|
|
278
|
|
279
|
|
280
|
|
281
|
|
282
|
|
283
|
protected function assertNoButton($label, $message = '', $group = 'Other') {
|
284
|
$links = $this->xpath('//input[contains(@type, submit)][contains(@value, :label)]', array(':label' => $label));
|
285
|
$message = ($message ? $message : t('Button with label %label found.', array('%label' => $label)));
|
286
|
return $this->assert(empty($links), $message, $group);
|
287
|
}
|
288
|
|
289
|
|
290
|
|
291
|
|
292
|
|
293
|
|
294
|
|
295
|
|
296
|
|
297
|
|
298
|
|
299
|
|
300
|
|
301
|
protected function drupalCreateNamedUser($name, $rids = array()) {
|
302
|
|
303
|
$rids2 = array();
|
304
|
foreach ($rids as $rid) {
|
305
|
$rids2[$rid] = $rid;
|
306
|
}
|
307
|
$edit = array();
|
308
|
$edit['name'] = $name;
|
309
|
$edit['mail'] = $edit['name'] . '@example.com';
|
310
|
$edit['roles'] = $rids2;
|
311
|
$edit['pass'] = user_password();
|
312
|
$edit['status'] = 1;
|
313
|
|
314
|
$account = user_save(drupal_anonymous_user(), $edit);
|
315
|
|
316
|
$this->assertTrue(!empty($account->uid), t('User %name created, uid=%uid.', array('%name' => $edit['name'], '%uid' => $account->uid)), t('User login'));
|
317
|
if (empty($account->uid)) {
|
318
|
return FALSE;
|
319
|
}
|
320
|
|
321
|
|
322
|
$account->pass_raw = $edit['pass'];
|
323
|
return $account;
|
324
|
}
|
325
|
|
326
|
protected function createForumTopicWithTitle($forum, $title) {
|
327
|
$node = $this->createForumTopic((array) $forum);
|
328
|
$node = node_load($node->nid);
|
329
|
$node->title = $title;
|
330
|
$node->shadow = FALSE;
|
331
|
node_save($node);
|
332
|
return $node;
|
333
|
}
|
334
|
|
335
|
protected function createForumCommentWithText($node, $text) {
|
336
|
static $cid = 0;
|
337
|
$this->drupalPost("node/$node->nid", array(
|
338
|
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $text,
|
339
|
), t('Save'));
|
340
|
$this->assertResponse(200);
|
341
|
$this->assertText($text, "Comment '$text' found, too.");
|
342
|
return comment_load(++$cid);
|
343
|
}
|
344
|
|
345
|
protected function isFieldChecked($id) {
|
346
|
$elements = $this->xpath('//input[@id=:id]', array(':id' => $id));
|
347
|
return isset($elements[0]) && !empty($elements[0]['checked']);
|
348
|
}
|
349
|
|
350
|
|
351
|
|
352
|
|
353
|
|
354
|
|
355
|
|
356
|
|
357
|
|
358
|
|
359
|
function checkForum($forum, $is_default = FALSE) {
|
360
|
$this->drupalLogin($this->user1);
|
361
|
|
362
|
$this->drupalGet("admin/structure/forum/edit/forum/$forum->tid");
|
363
|
$this->assertResponse(200, "^^^ '$forum->name' exists.");
|
364
|
|
365
|
foreach ($this->accounts as $key => $account) {
|
366
|
|
367
|
$account->access = array();
|
368
|
foreach ($account->roles as $rid => $role_name) {
|
369
|
foreach ($this->accesses as $access) {
|
370
|
if ($this->isFieldChecked("edit-forum-access-grants-checkboxes-$access-$rid")) {
|
371
|
$account->access[$access] = $access;
|
372
|
}
|
373
|
}
|
374
|
}
|
375
|
}
|
376
|
|
377
|
foreach ($this->accounts as $key => $account) {
|
378
|
|
379
|
$account->node = $this->createForumTopicWithTitle($forum, "Topic for $account->name");
|
380
|
$account->comment = $this->createForumCommentWithText($account->node, "Comment for $account->name");
|
381
|
}
|
382
|
|
383
|
$this->drupalGet("forum/$forum->tid");
|
384
|
$this->assertResponse(200, "^^^ '$forum->name' initial topics.");
|
385
|
|
386
|
foreach ($this->accounts as $key => $account) {
|
387
|
$is_super_user = user_access('bypass node access', $account) || ($account->uid == $this->moderator->uid && !$is_default);
|
388
|
|
389
|
if (!empty($account->uid)) {
|
390
|
$this->drupalLogin($account);
|
391
|
}
|
392
|
else {
|
393
|
$this->drupalLogout();
|
394
|
}
|
395
|
|
396
|
|
397
|
$this->drupalGet('forum');
|
398
|
|
399
|
if (empty($account->access['view']) && !$is_super_user) {
|
400
|
$this->assertResponse(403, "^^^ $account->name cannot see the Forum Overview");
|
401
|
}
|
402
|
elseif ((empty($account->access['create']) || !user_access('create forum content', $account)) && !$is_super_user) {
|
403
|
$this->assertResponse(200, 'Forum Overview');
|
404
|
$this->assertNoLink(t('Add new Forum topic'), "^^^ $account->name cannot post in the '$forum->name'.");
|
405
|
}
|
406
|
else {
|
407
|
$this->assertResponse(200, 'Forum Overview');
|
408
|
$this->assertLink($forum->name, 0, "^^^ $account->name can see the '$forum->name'.");
|
409
|
$this->assertLink(t('Add new Forum topic'), 0, "^^^ $account->name can post in the '$forum->name'.");
|
410
|
}
|
411
|
|
412
|
foreach (array('any', 'own') as $test_type) {
|
413
|
|
414
|
|
415
|
$comment = &$account->comment;
|
416
|
$node = &$account->node;
|
417
|
if ((empty($account->access['view']) || !user_access('access content', $account)) && !$is_super_user) {
|
418
|
$this->drupalGet("forum/$forum->tid");
|
419
|
$this->assertResponse(404, "^^^ $account->name cannot access '$forum->name'.");
|
420
|
$this->drupalGet("node/$node->nid");
|
421
|
$this->assertResponse(403, "^^^ $account->name cannot access $test_type topic.");
|
422
|
$this->drupalGet("node/$node->nid/edit");
|
423
|
$this->assertResponse(403, "$account->name cannot edit $test_type topic (not accessible).");
|
424
|
$this->drupalGet("comment/$comment->cid");
|
425
|
$this->assertResponse(403, "^^^ $account->name cannot access comment '$comment->subject'.");
|
426
|
}
|
427
|
else {
|
428
|
$this->drupalGet("forum/$forum->tid");
|
429
|
$this->assertResponse(200, "^^^ '$forum->name' as $account->name.");
|
430
|
|
431
|
$this->assertLink($node->title);
|
432
|
$this->clickLink($node->title);
|
433
|
$this->assertResponse(200, "^^^ $account->name can access $test_type topic.");
|
434
|
$this->assertText($comment->subject, "Comment '$comment->subject' found, too.");
|
435
|
|
436
|
|
437
|
|
438
|
if (!$is_super_user && (!user_access('access comments', $account) || empty($account->access['view'])) && !user_access('administer comments', $account)) {
|
439
|
$this->assertNoLinkByHref("/comment/$comment->cid#comment-$comment->cid");
|
440
|
$this->drupalGet("comment/$comment->cid");
|
441
|
$this->assertResponse(403, "^^^ $account->name cannot see comment '$comment->subject'.");
|
442
|
}
|
443
|
else {
|
444
|
$this->assertLinkByHref(url("comment/$comment->cid", array('fragment' => "comment-$comment->cid")));
|
445
|
|
446
|
if (((!user_access('post comments', $account) && !user_access('post comments without approval', $account)) || empty($account->access['create'])) && !$is_super_user) {
|
447
|
if (!$account->uid) {
|
448
|
$this->assertLinkByHref("/user/login?destination=node/$node->nid#comment-form");
|
449
|
}
|
450
|
$this->assertNoLink(t('Add new comment'));
|
451
|
$this->assertNoText(t('Add new comment'));
|
452
|
$this->assertNoLink(t('reply'));
|
453
|
$this->drupalGet("comment/$comment->cid");
|
454
|
$this->assertResponse(200, '^^^ ' . "Comment '$comment->subject' is visible to $account->name'.");
|
455
|
$this->drupalGet("comment/reply/$node->nid");
|
456
|
$this->assertResponse(403);
|
457
|
$this->drupalGet("comment/reply/$node->nid/$comment->cid");
|
458
|
$this->assertResponse(403);
|
459
|
}
|
460
|
else {
|
461
|
$this->assertText(t('Add new comment'));
|
462
|
$this->assertLink(t('reply'));
|
463
|
$this->assertLinkByHref("comment/reply/$node->nid/$comment->cid");
|
464
|
$this->drupalGet("comment/reply/$node->nid/$comment->cid");
|
465
|
$this->assertResponse(200);
|
466
|
}
|
467
|
|
468
|
|
469
|
global $user;
|
470
|
drupal_save_session(FALSE);
|
471
|
$user_save = $user;
|
472
|
$user = $account;
|
473
|
|
474
|
$comment_access_edit = FALSE;
|
475
|
$user = $user_save;
|
476
|
drupal_save_session(TRUE);
|
477
|
$this->drupalGet("comment/$comment->cid");
|
478
|
$this->assertResponse(200);
|
479
|
if (empty($account->access['update']) && !$is_super_user && !$comment_access_edit && !user_access('administer comments', $account) && !user_access('edit any forum content', $account) && !($account->uid == $comment->uid && user_access('edit own forum content', $account))) {
|
480
|
$this->assertNoLink(t('edit'));
|
481
|
$this->drupalGet("comment/$comment->cid/edit");
|
482
|
$this->assertResponse(403);
|
483
|
}
|
484
|
else {
|
485
|
$this->assertLink(t('edit'));
|
486
|
$this->clickLink(t('edit'));
|
487
|
$this->assertResponse(200);
|
488
|
$this->drupalGet("comment/$comment->cid/edit");
|
489
|
$this->assertResponse(200);
|
490
|
$this->assertText($comment->subject);
|
491
|
$comment->subject .= ' (updated)';
|
492
|
$this->drupalPost("comment/$comment->cid/edit", array(
|
493
|
'subject' => $comment->subject,
|
494
|
), t('Save'));
|
495
|
$this->assertText(t("Your comment has been posted."));
|
496
|
}
|
497
|
|
498
|
|
499
|
$this->drupalGet("comment/$comment->cid");
|
500
|
if ((empty($account->access['delete'])) && !$is_super_user && !user_access('administer comments', $account) && !user_access('delete any forum content', $account) && !($account->uid == $comment->uid && user_access('delete own forum content', $account))) {
|
501
|
$this->assertNoLink(t('delete'));
|
502
|
$this->drupalGet("comment/$comment->cid/delete");
|
503
|
$this->assertResponse(403);
|
504
|
}
|
505
|
else {
|
506
|
$this->assertText($comment->subject);
|
507
|
$this->assertLink(t('delete'));
|
508
|
$this->clickLink(t('delete'));
|
509
|
$this->assertResponse(200);
|
510
|
$this->drupalGet("comment/$comment->cid/delete");
|
511
|
$this->assertResponse(200);
|
512
|
$this->drupalPost("comment/$comment->cid/delete", array(), t('Delete'));
|
513
|
$this->assertText(t('The comment and all its replies have been deleted.'));
|
514
|
$this->assertNoText($comment->subject);
|
515
|
unset($account->comment);
|
516
|
}
|
517
|
}
|
518
|
|
519
|
|
520
|
$this->drupalGet("node/$node->nid");
|
521
|
$this->assertResponse(200);
|
522
|
if (empty($account->access['update']) && !user_access('edit any forum content', $account) &&
|
523
|
!(user_access('edit own forum content', $account) && $node->uid == $account->uid) &&
|
524
|
!$is_super_user) {
|
525
|
$this->assertNoLink(t('Edit'));
|
526
|
$this->drupalGet("node/$node->nid/edit");
|
527
|
$this->assertResponse(403, "$account->name cannot edit $test_type topic.");
|
528
|
}
|
529
|
else {
|
530
|
$this->assertLink(t('Edit'));
|
531
|
$this->clickLink(t('Edit'));
|
532
|
$this->assertResponse(200, "^^^ $account->name can edit $test_type topic.");
|
533
|
|
534
|
|
535
|
if ($is_super_user || user_access('administer nodes', $account)) {
|
536
|
$this->assertText(t('Revision information'), "$account->name sees Revision information.");
|
537
|
$this->assertText(t('Comment settings'), "$account->name sees Comment settings.");
|
538
|
$this->assertText(t('Publishing options'), "$account->name sees Publishing options.");
|
539
|
if (user_access('administer nodes', $account)) {
|
540
|
$this->assertText(t('Menu settings'), "$account->name sees Menu settings.");
|
541
|
$this->assertText(t('Authoring information'), "$account->name sees Authoring information.");
|
542
|
}
|
543
|
else {
|
544
|
$this->assertNoText(t('Menu settings'), "$account->name does not see Menu settings.");
|
545
|
$this->assertNoText(t('Authoring information'), "$account->name does not see Authoring information.");
|
546
|
}
|
547
|
}
|
548
|
else {
|
549
|
$this->assertNoText(t('Revision information'), "$account->name does not see Revision information.");
|
550
|
$this->assertNoText(t('Comment settings'), "$account->name does not see Comment settings.");
|
551
|
$this->assertNoText(t('Publishing options'), "$account->name does not see Publishing options.");
|
552
|
$this->assertNoText(t('Menu settings'), "$account->name does not see Menu settings.");
|
553
|
$this->assertNoText(t('Authoring information'), "$account->name does not see Authoring information.");
|
554
|
}
|
555
|
|
556
|
|
557
|
if (empty($account->access['delete']) && !user_access('delete any forum content', $account) &&
|
558
|
!(user_access('delete own forum content', $account) && $node->uid == $account->uid) &&
|
559
|
!$is_super_user) {
|
560
|
$this->assertNoButton(t('Delete'), 0, $account->name . ' has no Delete button.');
|
561
|
}
|
562
|
else {
|
563
|
$this->assertButton(t('Delete'), 0, $account->name . ' has a Delete button.');
|
564
|
}
|
565
|
|
566
|
|
567
|
$node->title = $node->title . ' (changed)';
|
568
|
$this->drupalPost("node/$node->nid/edit", array(
|
569
|
'title' => $node->title,
|
570
|
), t('Save'));
|
571
|
$this->assertText(t('Forum topic !title has been updated.', array('!title' => $node->title)));
|
572
|
}
|
573
|
|
574
|
|
575
|
if (empty($account->access['delete']) && !user_access('delete any forum content', $account) &&
|
576
|
!(user_access('delete own forum content', $account) && $node->uid == $account->uid) &&
|
577
|
!$is_super_user) {
|
578
|
$this->drupalGet("node/$node->nid/delete");
|
579
|
$this->assertResponse(403, "$account->name cannot delete $test_type topic.");
|
580
|
}
|
581
|
else {
|
582
|
$this->drupalPost("node/$node->nid/delete", array(), t('Delete'));
|
583
|
$this->assertText(t('Forum topic !title has been deleted.', array('!title' => $node->title)));
|
584
|
}
|
585
|
}
|
586
|
|
587
|
if ($test_type == 'any' && (!empty($account->access['view']) || $is_super_user)) {
|
588
|
|
589
|
if ((empty($account->access['create']) || !user_access('create forum content', $account)) && !$is_super_user) {
|
590
|
$this->drupalGet('forum');
|
591
|
if (empty($account->uid)) {
|
592
|
$this->assertLinkByHref('/user/login?destination=forum');
|
593
|
}
|
594
|
else {
|
595
|
$this->assertResponse(200, "^^^ $account->name can see the Forum Overview, but...");
|
596
|
$this->assertText(t('You are not allowed to post new content in the forum.'));
|
597
|
}
|
598
|
$this->drupalGet("node/add/forum/$forum->tid");
|
599
|
$this->assertResponse(403, "^^^ $account->name cannot create a forum topic in '$forum->name'.");
|
600
|
break;
|
601
|
}
|
602
|
else {
|
603
|
$this->drupalGet('forum');
|
604
|
$this->assertNoText(t('You are not allowed to post new content in the forum.'));
|
605
|
$this->assertLink(t('Add new Forum topic'));
|
606
|
$this->clickLink(t('Add new Forum topic'));
|
607
|
$this->assertResponse(200, "^^^ $account->name can create a forum topic.");
|
608
|
$this->drupalGet("node/add/forum/$forum->tid");
|
609
|
$this->assertResponse(200, "^^^ $account->name can create a forum topic in '$forum->name'.");
|
610
|
$this->drupalGet('forum');
|
611
|
$this->assertLink(t('Add new Forum topic'));
|
612
|
$this->drupalPost("node/add/forum/$forum->tid", array(
|
613
|
'title' => "Topic 1 by $account->name",
|
614
|
), t('Save'));
|
615
|
$node = $account->node = $this->createForumTopicWithTitle($forum, "Topic 2 by $account->name");
|
616
|
$this->drupalGet('node/' . $node->nid );
|
617
|
|
618
|
$account->comment = $this->createForumCommentWithText($node, "Comment by $account->name");
|
619
|
|
620
|
$this->drupalGet("forum/$forum->tid");
|
621
|
$this->assertResponse(200, "^^^ '$forum->name' as $account->name (own topic).");
|
622
|
}
|
623
|
}
|
624
|
}
|
625
|
}
|
626
|
|
627
|
$this->drupalLogin($this->user1);
|
628
|
$this->drupalGet("forum/$forum->tid");
|
629
|
$this->assertResponse(200, "^^^ '$forum->name' remaining topics.");
|
630
|
}
|
631
|
|
632
|
|
633
|
function createFAForum($id, $tag, $description, array $accesses) {
|
634
|
$edit = array(
|
635
|
'name' => "Forum $id $tag",
|
636
|
'description' => $description,
|
637
|
'parent[0]' => 0,
|
638
|
'weight' => '0',
|
639
|
);
|
640
|
$forum = (object) ($edit + array('tid' => 2));
|
641
|
$edit["forum_access[grants][checkboxes][view][1]"] = FALSE;
|
642
|
$edit["forum_access[grants][checkboxes][view][2]"] = FALSE;
|
643
|
$edit["forum_access[grants][checkboxes][create][2]"] = FALSE;
|
644
|
foreach (array($this->webmaster_rid, $this->forum_admin_rid, $this->edit_any_content_rid, $this->edit_own_content_rid, $this->create_content_rid, $this->admin_rid, $this->anon_rid, $this->auth_rid) as $rid) {
|
645
|
foreach ($accesses as $access) {
|
646
|
$key = "$access-$rid";
|
647
|
if (array_search($key, array('update-3', 'delete-3')) === FALSE) {
|
648
|
$edit["forum_access[grants][checkboxes][$access][$rid]"] = TRUE;
|
649
|
}
|
650
|
}
|
651
|
}
|
652
|
$this->drupalPost('admin/structure/forum/add/forum', $edit, t('Save'));
|
653
|
$this->assertResponse(200, "'$forum->name' added.");
|
654
|
|
655
|
|
656
|
$acl_id = _forum_access_get_acl($forum->tid);
|
657
|
$this->assertNotNull($acl_id);
|
658
|
acl_add_user($acl_id, $this->moderator->uid);
|
659
|
$this->assertTrue(acl_has_user($acl_id, $this->moderator->uid), t('User %moderator is moderator.', array('%user' => $this->moderator->uid)));
|
660
|
|
661
|
|
662
|
$this->drupalGet("admin/structure/forum/edit/forum/$forum->tid");
|
663
|
$this->assertResponse(200, "^^^ '$forum->name' exists, with these settings.");
|
664
|
$this->drupalGet('forum');
|
665
|
$this->assertResponse(200, 'Forum Overview');
|
666
|
return $forum;
|
667
|
}
|
668
|
|
669
|
function createAndCheckForum($id, $tag, $description, array $accesses) {
|
670
|
$this->setUp2();
|
671
|
taxonomy_term_delete(1);
|
672
|
$this->pass("#########################<br />#$id - $tag Configuration test @" . (time() - $this->time), '<a id="jump1" href="#jump2">/\<br />######<br />\/</a>');
|
673
|
$forum = $this->createFAForum($id, $tag, $description, $accesses);
|
674
|
$this->checkForum($forum);
|
675
|
$this->pass("#########################<br />#$id - END $tag Configuration test @" . (time() - $this->time), '<a id="jump2" href="#jump3">/\<br />######<br />\/</a>');
|
676
|
}
|
677
|
|
678
|
|
679
|
|
680
|
|
681
|
function dpm($input, $name = NULL) {
|
682
|
if (module_exists('devel') && user_access('access devel information')) {
|
683
|
$export = kprint_r($input, TRUE, $name);
|
684
|
$trigger_error = 'trigger_error';
|
685
|
$trigger_error($export);
|
686
|
}
|
687
|
}
|
688
|
|
689
|
|
690
|
|
691
|
|
692
|
function wpm($input, $name = NULL) {
|
693
|
if (module_exists('devel') && user_access('access devel information')) {
|
694
|
$export = kprint_r($input, TRUE, $name);
|
695
|
watchdog('debug', $export);
|
696
|
}
|
697
|
}
|
698
|
}
|