| 1 |
<?php |
<?php |
| 2 |
// $Id: hidden.test,v 1.1 2008/12/12 19:23:35 ekes Exp $ |
// $Id: hidden.test,v 1.2 2008/12/13 18:42:43 ekes Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* Tests for hidden module. |
* Tests for hidden module. |
| 7 |
* |
* |
| 8 |
* @todo same but with comments |
* @todo XSS tests. |
|
* @todo ... |
|
| 9 |
*/ |
*/ |
| 10 |
|
|
| 11 |
/** |
/** |
| 17 |
protected $report_user; |
protected $report_user; |
| 18 |
protected $hide_user; |
protected $hide_user; |
| 19 |
protected $admin_user; |
protected $admin_user; |
| 20 |
|
protected $text_filter; |
| 21 |
|
protected $preg_filter; |
| 22 |
|
|
| 23 |
function setUp() { |
function setUp() { |
| 24 |
parent::setUp('hidden', 'comment'); |
parent::setUp('hidden', 'comment'); |
| 30 |
// Yes untested edge case able to hide but not see hidden. Make sense? |
// Yes untested edge case able to hide but not see hidden. Make sense? |
| 31 |
$this->hide_user = $this->drupalCreateUser(array('mark as hidden', 'access hidden')); |
$this->hide_user = $this->drupalCreateUser(array('mark as hidden', 'access hidden')); |
| 32 |
$this->admin_user = $this->drupalCreateUser(array('administer hidden')); |
$this->admin_user = $this->drupalCreateUser(array('administer hidden')); |
| 33 |
|
|
| 34 |
|
$this->text_filter = array( |
| 35 |
|
'title' => 'new filter name', |
| 36 |
|
'filter' => 'text to filter', |
| 37 |
|
'type' => HIDDEN_FILTER_PLAIN, |
| 38 |
|
'delay' => 0, |
| 39 |
|
'weight' => 0, |
| 40 |
|
'enabled' => 1, |
| 41 |
|
'uid' => $this->hide_user->uid, |
| 42 |
|
'rid' => 0, |
| 43 |
|
'publicnote' => 'Public reason for hiding', |
| 44 |
|
'privatenote' => 'Filter notes as the reason for hidden', |
| 45 |
|
); |
| 46 |
|
$this->preg_filter = array( |
| 47 |
|
'title' => 'preg filter name', |
| 48 |
|
'filter' => '/With \w+/', |
| 49 |
|
'type' => HIDDEN_FILTER_PREG, |
| 50 |
|
'delay' => 30, |
| 51 |
|
'weight' => -5, |
| 52 |
|
'enabled' => 1, |
| 53 |
|
'uid' => $this->admin_user->uid, |
| 54 |
|
'rid' => 1, |
| 55 |
|
); |
| 56 |
} |
} |
| 57 |
|
|
| 58 |
/** |
/** |
| 61 |
* Frequently required |
* Frequently required |
| 62 |
* @see HiddenHideUnitCase::testHiddenHiddenHide() for the first testing. |
* @see HiddenHideUnitCase::testHiddenHiddenHide() for the first testing. |
| 63 |
* |
* |
| 64 |
|
* @param $settings |
| 65 |
|
* array of settings |
| 66 |
|
* defaults ... 'type' 'node' but can be node type .... |
| 67 |
|
* |
| 68 |
* @return object |
* @return object |
| 69 |
* object without delay, only id (not nid|cid), or reason title. |
* object without delay, only id (not nid|cid), or reason title. |
| 70 |
*/ |
*/ |
| 76 |
'privatenote' => $this->randomName(34), |
'privatenote' => $this->randomName(34), |
| 77 |
'filter' => FALSE, |
'filter' => FALSE, |
| 78 |
); |
); |
| 79 |
|
// a specific node type is passed rather than 'node' or 'comment' |
| 80 |
|
if (isset($settings['node_type'])) { |
| 81 |
|
$node_type = $settings['node_type']; |
| 82 |
|
} |
| 83 |
|
else { |
| 84 |
|
$node_type = 'story'; |
| 85 |
|
} |
| 86 |
if (empty($settings['id'])) { |
if (empty($settings['id'])) { |
| 87 |
if (isset($settings['type']) && $settings['type'] == 'comment') { |
if (isset($settings['type']) && $settings['type'] == 'comment') { |
| 88 |
$comment = $this->hiddenCreateComment(); |
$comment = $this->hiddenCreateComment(array('type' => $node_type)); |
| 89 |
$defaults['id'] = $comment->cid; |
$defaults['id'] = $comment->cid; |
| 90 |
} |
} |
| 91 |
else { |
else { |
| 92 |
$node = $this->drupalCreateNode(); |
$new_user = $this->drupalCreateUser(array("create $node_type content")); |
| 93 |
|
$node = $this->drupalCreateNode(array('uid' => $new_user->uid, 'type' => $node_type)); |
| 94 |
$defaults['id'] = $node->nid; |
$defaults['id'] = $node->nid; |
| 95 |
} |
} |
| 96 |
} |
} |
| 117 |
'rid' => 1, |
'rid' => 1, |
| 118 |
'publicnote' => $this->randomName(73), |
'publicnote' => $this->randomName(73), |
| 119 |
); |
); |
| 120 |
|
// a specific node type is passed rather than 'node' or 'comment' |
| 121 |
|
if (isset($settings['node_type'])) { |
| 122 |
|
$node_type = $settings['type']; |
| 123 |
|
} |
| 124 |
|
else { |
| 125 |
|
$node_type = 'story'; |
| 126 |
|
} |
| 127 |
if (empty($settings['id'])) { |
if (empty($settings['id'])) { |
| 128 |
$node = $this->drupalCreateNode(); |
$new_user = $this->drupalCreateUser(array('create '. $node_type .' content')); |
| 129 |
|
$node = $this->drupalCreateNode(array('uid' => $new_user->uid, 'type' => $node_type)); |
| 130 |
$defaults['id'] = $node->nid; |
$defaults['id'] = $node->nid; |
| 131 |
} |
} |
| 132 |
if (empty($settings['uid'])) { |
if (empty($settings['uid'])) { |
| 159 |
'status' => COMMENT_PUBLISHED, |
'status' => COMMENT_PUBLISHED, |
| 160 |
); |
); |
| 161 |
if (empty($settings['uid'])) { |
if (empty($settings['uid'])) { |
| 162 |
global $user; |
$posting_user = $this->drupalCreateUser(array("post comments without approval")); |
| 163 |
$defaults['uid'] = $user->uid; |
$defaults['uid'] = $posting_user->uid; |
| 164 |
} |
} |
| 165 |
if (empty($settings['nid'])) { |
if (empty($settings['nid'])) { |
| 166 |
$node = $this->drupalCreateNode(array('type' => 'article', 'comment' => COMMENT_NODE_READ_WRITE)); |
if (! isset($settings['type'])) { |
| 167 |
|
$settings['type'] = 'story'; |
| 168 |
|
} |
| 169 |
|
$posting_user = $this->drupalCreateUser(array("create {$settings['type']} content")); |
| 170 |
|
$node = $this->drupalCreateNode(array('type' => $settings['type'], 'uid' => $posting_user->uid, 'comment' => COMMENT_NODE_READ_WRITE)); |
| 171 |
$defaults['nid'] = $node->nid; |
$defaults['nid'] = $node->nid; |
| 172 |
} |
} |
| 173 |
$settings += $defaults; |
$settings += $defaults; |
| 176 |
$this->assertEqual($comment->cid, $cid, t('Comment created')); |
$this->assertEqual($comment->cid, $cid, t('Comment created')); |
| 177 |
return $comment; |
return $comment; |
| 178 |
} |
} |
| 179 |
|
|
| 180 |
|
/** |
| 181 |
|
* Create hidden reason. |
| 182 |
|
* |
| 183 |
|
* @see HiddenCoreUnitCase::testHiddenReason() for first test |
| 184 |
|
* |
| 185 |
|
* @param $settings |
| 186 |
|
* array 'title' 'description' 'enabled' |
| 187 |
|
* @return |
| 188 |
|
* array as $settings plus 'rid' |
| 189 |
|
*/ |
| 190 |
|
function hiddenCreateReason($settings = array()) { |
| 191 |
|
$defaults = array( |
| 192 |
|
'title' => $this->randomName(11), |
| 193 |
|
'description' => $this->randomName(42), |
| 194 |
|
'enabled' => 1, |
| 195 |
|
); |
| 196 |
|
$settings += $defaults; |
| 197 |
|
$settings['rid'] = hidden_reason_create($settings['title'], $settings['description'], $settings['enabled']); |
| 198 |
|
return $settings; |
| 199 |
|
} |
| 200 |
} |
} |
| 201 |
|
|
| 202 |
/** |
/** |
| 203 |
* Unit test: hiding nodes and comments. |
* 'Unit' test: un/hiding nodes comments, add/remove/edit reasons |
| 204 |
*/ |
*/ |
| 205 |
class HiddenHideUnitCase extends HiddenHelperCase { |
class HiddenCoreUnitCase extends HiddenHelperCase { |
| 206 |
/** |
/** |
| 207 |
* Implementation of getInfo(). |
* Implementation of getInfo(). |
| 208 |
*/ |
*/ |
| 209 |
function getInfo() { |
function getInfo() { |
| 210 |
return array( |
return array( |
| 211 |
'name' => t('Hide node and comments'), |
'name' => t('Main functions test'), |
| 212 |
'description' => t('Test functions for hiding nodes and comments.'), |
'description' => t('Test main functions for hiding, reasons, filters.'), |
| 213 |
'group' => t('Hidden'), |
'group' => t('Hidden'), |
| 214 |
); |
); |
| 215 |
} |
} |
| 292 |
$reported_orginal = $this->hiddenCreateReported(); |
$reported_orginal = $this->hiddenCreateReported(); |
| 293 |
// @todo when there is an individual inteface for editing/viewing reported or query it |
// @todo when there is an individual inteface for editing/viewing reported or query it |
| 294 |
} |
} |
| 295 |
|
|
| 296 |
|
/** |
| 297 |
|
* Test creating, editing and removing reasons. |
| 298 |
|
*/ |
| 299 |
|
function testHiddenReason() { |
| 300 |
|
// Create reason and check it with retrieval functions |
| 301 |
|
$reason_original = $this->hiddenCreateReason(); |
| 302 |
|
$this->assertTrue($reason_original['rid'] > 0, t('Reason rid created')); |
| 303 |
|
$this->assertTrue(hidden_reason_check($reason_original['rid']), t('Reason check confirms a valid reason')); |
| 304 |
|
$reason_retrieved = hidden_reason_get($reason_original['rid']); |
| 305 |
|
foreach ($reason_original as $key => $value) { |
| 306 |
|
$this->assertEqual($value, $reason_retrieved->$key, t('Correct %key retrieved', array('%key' => $key))); |
| 307 |
|
} |
| 308 |
|
|
| 309 |
|
// Disable reason and check |
| 310 |
|
hidden_reason_disable($reason_original['rid']); |
| 311 |
|
$reason_retrieved = hidden_reason_get($reason_original['rid'], FALSE, FALSE); |
| 312 |
|
$this->assertFalse($reason_retrieved->enabled, t('Reason disabled')); |
| 313 |
|
// And enable again |
| 314 |
|
hidden_reason_enable($reason_original['rid']); |
| 315 |
|
$reason_retrieved = hidden_reason_get($reason_original['rid'], FALSE, FALSE); |
| 316 |
|
$this->assertTrue($reason_retrieved->enabled, t('Reason enabled')); |
| 317 |
|
|
| 318 |
|
// Update reason and check |
| 319 |
|
$reason_original['title'] = 'New title'; |
| 320 |
|
$reason_original['description'] = 'New description'; |
| 321 |
|
$update_rid = hidden_reason_update($reason_original['title'], $reason_original['description'], $reason_original['enabled'], $reason_original['rid']); |
| 322 |
|
$this->assertEqual($reason_original['rid'], $update_rid, t('Reason updated')); |
| 323 |
|
$reason_retrieved = hidden_reason_get($reason_original['rid'], FALSE, FALSE); |
| 324 |
|
foreach ($reason_original as $key => $value) { |
| 325 |
|
$this->assertEqual($value, $reason_retrieved->$key, t('Correct updated %key retrieved', array('%key' => $key))); |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
// Check next non-existing reason isn't reported as existing |
| 329 |
|
$update_rid++; |
| 330 |
|
$this->assertFalse(hidden_reason_check($update_rid), t('Non existing reason not found')); |
| 331 |
|
$this->assertFalse(hidden_reason_get($update_rid, FALSE, FALSE), t('Non exisitng reason not retrieved')); |
| 332 |
|
} |
| 333 |
|
|
| 334 |
|
/** |
| 335 |
|
* Test retrieving multiple reasons. |
| 336 |
|
*/ |
| 337 |
|
function testHiddenReasonMultiple() { |
| 338 |
|
// Adds a set or reasons |
| 339 |
|
$reasons_original = array(); |
| 340 |
|
for ($i = 0; $i < 11; $i++) { |
| 341 |
|
$reason = $this->hiddenCreateReason(); |
| 342 |
|
$reasons_original[$reason['rid']] = $reason; |
| 343 |
|
} |
| 344 |
|
|
| 345 |
|
// Retrieve all and ensure all new reasons saved |
| 346 |
|
// (there is also the previous test ones, and the default...) |
| 347 |
|
$reasons_retrieved = hidden_reason_get_all(FALSE, FALSE); |
| 348 |
|
$equal = TRUE; |
| 349 |
|
foreach ($reasons_original as $rid => $reason) { |
| 350 |
|
foreach ($reason as $key => $value) { |
| 351 |
|
if ($reasons_retrieved[$rid]->$key != $value) { |
| 352 |
|
$equal = FALSE; |
| 353 |
|
} |
| 354 |
|
} |
| 355 |
|
} |
| 356 |
|
$this->assertTrue($equal, t('All reasons retrieved as originals')); |
| 357 |
|
|
| 358 |
|
// disable one of the reasons |
| 359 |
|
reset($reasons_original); |
| 360 |
|
$reason = next($reasons_original); |
| 361 |
|
// and check not returned when only want enabled ones |
| 362 |
|
hidden_reason_disable($reason['rid']); |
| 363 |
|
$reasons_retrieved = hidden_reason_get_all(TRUE, FALSE); |
| 364 |
|
$this->assertFalse(isset($reasons_retrieved[$reason['rid']]), t('Disabled reason not retrieved')); |
| 365 |
|
$this->assertTrue(isset($reasons_retrieved[++$reason['rid']]), t('Enabled reason retrieved')); |
| 366 |
|
} |
| 367 |
|
|
| 368 |
|
/** |
| 369 |
|
* Test saving and loading filters. |
| 370 |
|
*/ |
| 371 |
|
function testHiddenFilterSave() { |
| 372 |
|
$original_preg = $sent_preg = (object) $this->preg_filter; |
| 373 |
|
$original_text = $sent_text = (object) $this->text_filter; |
| 374 |
|
|
| 375 |
|
$this->assertEqual(hidden_filter_save($sent_text), SAVED_NEW, t('New filter reported saved')); |
| 376 |
|
$retrieved_text = hidden_filter_load($sent_text->hfid); |
| 377 |
|
$equal = TRUE; |
| 378 |
|
foreach ($original_text as $var => $value) { |
| 379 |
|
if ($retrieved_text->$var != $value) { |
| 380 |
|
$equal = FALSE; |
| 381 |
|
} |
| 382 |
|
} |
| 383 |
|
$this->assertTrue($equal, t('Saved and retrieved filters equal')); |
| 384 |
|
|
| 385 |
|
$this->assertEqual(hidden_filter_save($sent_preg), SAVED_NEW, t('New filter reported saved')); |
| 386 |
|
$retrieved_preg = hidden_filter_load($sent_preg->hfid); |
| 387 |
|
$equal = TRUE; |
| 388 |
|
foreach ($original_preg as $var => $value) { |
| 389 |
|
if ($retrieved_preg->$var != $value) { |
| 390 |
|
$equal = FALSE; |
| 391 |
|
} |
| 392 |
|
} |
| 393 |
|
$this->assertTrue($equal, t('Saved and retrieved filters equal')); |
| 394 |
|
|
| 395 |
|
// Disable and enable a filter using function |
| 396 |
|
hidden_filter_enable($sent_preg->hfid, FALSE); |
| 397 |
|
$retrieved_preg = hidden_filter_load($sent_preg->hfid); |
| 398 |
|
$this->assertFalse($retrieved_preg->enabled, t('Filter successfully disabled')); |
| 399 |
|
hidden_filter_enable($sent_preg->hfid); |
| 400 |
|
$retrieved_preg = hidden_filter_load($sent_preg->hfid); |
| 401 |
|
$this->assertTrue($retrieved_preg->enabled, t('Filter successfully enabled')); |
| 402 |
|
|
| 403 |
|
// Change and add some values |
| 404 |
|
$sent_preg->title = 'updated preg filter title'; |
| 405 |
|
$sent_preg->rid = 0; |
| 406 |
|
$sent_preg->privatenote = 'New filter hidden note'; |
| 407 |
|
hidden_filter_save($sent_preg); |
| 408 |
|
$retrieved_preg = hidden_filter_load($sent_preg->hfid); |
| 409 |
|
$equal = TRUE; |
| 410 |
|
foreach ($sent_preg as $var => $value) { |
| 411 |
|
if ($retrieved_preg->$var != $value) { |
| 412 |
|
$equal = FALSE; |
| 413 |
|
} |
| 414 |
|
} |
| 415 |
|
$this->assertTrue($equal, t('Edited and retrieved filters equal')); |
| 416 |
|
|
| 417 |
|
$this->assertTrue(hidden_filter_delete($sent_preg->hfid), t('Filter reported deleted')); |
| 418 |
|
$this->assertTrue(hidden_filter_delete($sent_text->hfid), t('Filter reported deleted')); |
| 419 |
|
$this->assertFalse(hidden_filter_load($sent_preg->hfid), t('Deleted filter not retrieved')); |
| 420 |
|
$this->assertFalse(hidden_filter_load($sent_text->hfid), t('Deleted filter not retrieved')); |
| 421 |
|
} |
| 422 |
|
|
| 423 |
|
/** |
| 424 |
|
* Test running filters against content |
| 425 |
|
*/ |
| 426 |
|
function testHiddenFilterContentTest() { |
| 427 |
|
$no_match = 'This is text that should not match with any filter. With'; |
| 428 |
|
$first_match = 'This is some text to filter that should match With both of the filters.'; |
| 429 |
|
$preg_match = 'This should match only With the preg filter.'; |
| 430 |
|
$text_match = 'This text to filter should only match the text filter.'; |
| 431 |
|
$text_filter = (object) $this->text_filter; |
| 432 |
|
$preg_filter = (object) $this->preg_filter; |
| 433 |
|
|
| 434 |
|
hidden_filter_save($text_filter); |
| 435 |
|
hidden_filter_save($preg_filter); |
| 436 |
|
|
| 437 |
|
$result = _hidden_filter_content_test($no_match); |
| 438 |
|
$this->assertFalse($result, t('Filter did not no_match text correctly')); |
| 439 |
|
$result = _hidden_filter_content_test($first_match); |
| 440 |
|
$this->assertTrue($result != FALSE, t('Filter matched first_match correctly')); |
| 441 |
|
$this->assertEqual($preg_filter->hfid, $result->hfid, t('Preg filter correctly matched first by weight')); |
| 442 |
|
$result = _hidden_filter_content_test($preg_match); |
| 443 |
|
$this->assertTrue($result != FALSE, t('Filter matched preg_match correctly')); |
| 444 |
|
$this->assertEqual($preg_filter->hfid, $result->hfid, t('Preg filter correctly matched')); |
| 445 |
|
$result = _hidden_filter_content_test($text_match); |
| 446 |
|
$this->assertTrue($result != FALSE, t('Filter matched text_match correctly')); |
| 447 |
|
$this->assertEqual($text_filter->hfid, $result->hfid, t('Text filter correctly matched')); |
| 448 |
|
} |
| 449 |
|
|
| 450 |
|
/** |
| 451 |
|
* Test hiding by filters |
| 452 |
|
*/ |
| 453 |
|
function testHiddenFilterContent() { |
| 454 |
|
$text_filter = (object) $this->text_filter; |
| 455 |
|
$preg_filter = (object) $this->preg_filter; |
| 456 |
|
hidden_filter_save($text_filter); |
| 457 |
|
hidden_filter_save($preg_filter); |
| 458 |
|
|
| 459 |
|
$text_node = $this->drupalCreateNode(array('body' => "A first simpler text to filter that should get hidden automatically when passed through the filter function")); |
| 460 |
|
$preg_node = $this->drupalCreateNode(array('body' => "Another set of text some of which will match the preg test.\nWith this we can check to see if the node is unpublished and has the correct hidden information attached to it and also if the gets set correctly.")); |
| 461 |
|
|
| 462 |
|
// Text node first |
| 463 |
|
$this->assertTrue(hidden_filter_content($text_node->body, 'node', $text_node->nid), t('Node reported as hidden')); |
| 464 |
|
$hidden = _hidden_hidden_get('node', $text_node->nid); |
| 465 |
|
$this->assertEqual($hidden->rid, $text_filter->rid, t('Text filter reason recorded')); |
| 466 |
|
$this->assertEqual($hidden->publicnote, $text_filter->publicnote, t('Text filter publicnote recorded')); |
| 467 |
|
$this->assertEqual($hidden->privatenote, $text_filter->privatenote, t('Text filter privatenote recorded')); |
| 468 |
|
$this->assertEqual($hidden->uid, $text_filter->uid, t('Text filter user recorded')); |
| 469 |
|
$text_node = node_load($text_node->nid, NULL, TRUE); |
| 470 |
|
$this->assertEqual($text_node->status, 0, t('Node unpublished')); |
| 471 |
|
|
| 472 |
|
// Then the preg text |
| 473 |
|
$this->assertTrue(hidden_filter_content($preg_node->body, 'node', $preg_node->nid), t('Node reported as hidden')); |
| 474 |
|
$hidden = _hidden_hidden_get('node', $preg_node->nid); |
| 475 |
|
$this->assertEqual($hidden->rid, $preg_filter->rid, t('Preg filter reason recorded')); |
| 476 |
|
$this->assertEqual($hidden->publicnote, '', t('Preg filter lack of public note recorded')); |
| 477 |
|
$this->assertTrue($hidden->delay > time(), t('Hide delay time set')); |
| 478 |
|
$preg_node = node_load($preg_node->nid, NULL, TRUE); |
| 479 |
|
$this->assertEqual($preg_node->status, 1, t('Node not yet unpublished')); |
| 480 |
|
} |
| 481 |
} |
} |
| 482 |
|
|
| 483 |
/** |
/** |
| 484 |
* Functional test: hiding nodes and comments. |
* Functional test: hiding nodes and comments. |
| 485 |
|
* |
| 486 |
|
* Also tests the hide_user view of the hidden item page, may move to Pages class |
| 487 |
|
* if further seperation of actions and ui is wanted. |
| 488 |
*/ |
*/ |
| 489 |
class HiddenHideTestCase extends HiddenHelperCase { |
class HiddenHideTestCase extends HiddenHelperCase { |
| 490 |
/** |
/** |
| 519 |
$this->assertResponse(403, t('View user cannot access node hide page')); |
$this->assertResponse(403, t('View user cannot access node hide page')); |
| 520 |
$this->drupalGet(hidden_path('node', $node->nid, 'report')); |
$this->drupalGet(hidden_path('node', $node->nid, 'report')); |
| 521 |
$this->assertResponse(403, t('View user cannot access node report page')); |
$this->assertResponse(403, t('View user cannot access node report page')); |
| 522 |
|
$this->drupalGet(hidden_path('node', $node->nid, 'view')); |
| 523 |
|
$this->assertResponse(404, t('View user cannot view unhidden node on hidden view page')); |
| 524 |
$this->drupalLogout(); |
$this->drupalLogout(); |
| 525 |
|
|
| 526 |
$this->drupalLogin($this->report_user); |
$this->drupalLogin($this->report_user); |
| 565 |
$this->assertText($hide['publictext'], t('Public text posted')); |
$this->assertText($hide['publictext'], t('Public text posted')); |
| 566 |
$this->assertText($hide['privatetext'], t('Private text posted')); |
$this->assertText($hide['privatetext'], t('Private text posted')); |
| 567 |
// @todo check reason is displayed in words |
// @todo check reason is displayed in words |
| 568 |
|
// note view_user check is HiddenUserPagesTestCase::testHiddenViewPage() |
| 569 |
|
|
| 570 |
// Click the unhide link |
// Click the unhide link |
| 571 |
$this->clickLink(t('unhide')); |
$this->clickLink(t('unhide')); |
| 574 |
$this->assertText($node->title, t('On page with node title %title visible', array('%title' => $node->title))); |
$this->assertText($node->title, t('On page with node title %title visible', array('%title' => $node->title))); |
| 575 |
|
|
| 576 |
// make comment to hide |
// make comment to hide |
| 577 |
$comment = $this->hiddenCreateComment(array('type' => 'comment')); |
$comment = $this->hiddenCreateComment(); |
| 578 |
$hide = array( |
$hide = array( |
| 579 |
'reason' => 1, |
'reason' => 1, |
| 580 |
'publictext' => $this->randomName(82), |
'publictext' => $this->randomName(82), |
| 606 |
// @todo hide_user (?) to check the report |
// @todo hide_user (?) to check the report |
| 607 |
} |
} |
| 608 |
} |
} |
| 609 |
|
|
| 610 |
|
/** |
| 611 |
|
* Functional test: User pages |
| 612 |
|
*/ |
| 613 |
|
class HiddenUserPagesTestCase extends HiddenHelperCase { |
| 614 |
|
/** |
| 615 |
|
* Implementation of getInfo(). |
| 616 |
|
*/ |
| 617 |
|
function getInfo() { |
| 618 |
|
return array( |
| 619 |
|
'name' => t('View hidden node and comments user pages'), |
| 620 |
|
'description' => t('View hidden nodes and comments on user pages.'), |
| 621 |
|
'group' => t('Hidden'), |
| 622 |
|
); |
| 623 |
|
} |
| 624 |
|
|
| 625 |
|
function testPageView() { |
| 626 |
|
$node = $this->drupalCreateNode(); |
| 627 |
|
$this->assertTrue(node_load($node->nid), t('Node created.')); |
| 628 |
|
$hidden = $this->hiddenCreateHidden(); |
| 629 |
|
|
| 630 |
|
$this->drupalLogin($this->web_user); |
| 631 |
|
$this->drupalGet('hidden'); |
| 632 |
|
$this->assertResponse(403, t('Unprivileged user cannot access hidden node index')); |
| 633 |
|
$this->drupalGet('hidden/node'); |
| 634 |
|
$this->assertResponse(403, t('Unprivileged user cannot access hidden node index')); |
| 635 |
|
$this->drupalGet('hidden/comment'); |
| 636 |
|
$this->assertResponse(403, t('Unprivileged user cannot access hidden comment index')); |
| 637 |
|
|
| 638 |
|
$this->drupalLogin($this->view_user); |
| 639 |
|
$this->drupalGet('hidden'); |
| 640 |
|
$this->assertResponse(200, t('View user can access hidden node index')); |
| 641 |
|
$this->drupalGet('hidden/node'); |
| 642 |
|
$this->assertResponse(200, t('View user can access hidden node index')); |
| 643 |
|
$this->drupalGet('hidden/comment'); |
| 644 |
|
$this->assertResponse(200, t('View user can access hidden node index')); |
| 645 |
|
} |
| 646 |
|
|
| 647 |
|
function testHiddenViewPage() { |
| 648 |
|
/* // Just one |
| 649 |
|
$hidden = $this->hiddenCreateHidden(); |
| 650 |
|
$this->drupalLogin($this->view_user); |
| 651 |
|
$this->drupalGet('hidden'); |
| 652 |
|
$node = node_load($hidden->id, NULL, TRUE); |
| 653 |
|
$this->assertText($node->title); |
| 654 |
|
$this->drupalGet(hidden_path('node', $hidden->id, 'view')); |
| 655 |
|
$this->assertText($node->title); |
| 656 |
|
$this->drupalLogout(); */ |
| 657 |
|
|
| 658 |
|
$hiddens = array(); |
| 659 |
|
// @todo what about testing page two |
| 660 |
|
for ($i = 0; $i < 9; $i++) { |
| 661 |
|
$hiddens[$i] = $this->hiddenCreateHidden(); |
| 662 |
|
$nothiddens[$i] = $this->drupalCreateNode(); |
| 663 |
|
} |
| 664 |
|
|
| 665 |
|
// using theme('username', ) this cuts long usernames and changes on permissions so: |
| 666 |
|
$view_user = $this->drupalCreateUser(array('access hidden', 'access user profiles')); |
| 667 |
|
$this->drupalLogin($view_user); |
| 668 |
|
// and check lots of hidden pages as well |
| 669 |
|
foreach ($hiddens as $hidden) { |
| 670 |
|
$this->drupalGet('hidden'); |
| 671 |
|
// @todo is there a simpletest way of bundling up these asserts? |
| 672 |
|
$node = node_load($hidden->id, NULL, TRUE); |
| 673 |
|
$this->assertText($node->title); |
| 674 |
|
$user = user_load(array('uid' => $node->uid)); |
| 675 |
|
$this->assertRaw(theme('username', $user)); |
| 676 |
|
// @todo reasons again |
| 677 |
|
$this->clickLink($node->title); // don't really need to run this everytime |
| 678 |
|
$this->assertText($node->title, t('Node title visible on node hidden page')); |
| 679 |
|
$this->assertText($hidden->publicnote, t('Public text posted')); |
| 680 |
|
$this->assertNoText($hidden->privatenote, t('Private text not visible to view only user')); |
| 681 |
|
$this->assertNoText(t('Unhide'), t('No unhide link visible to view only user')); |
| 682 |
|
} |
| 683 |
|
foreach ($nothiddens as $nothidden) { |
| 684 |
|
// @todo is there a simpletest way of bundling up these asserts? |
| 685 |
|
$node = node_load($nothidden->nid, NULL, TRUE); |
| 686 |
|
$this->assertNoText($node->title); |
| 687 |
|
$user = user_load(array('uid' => $node->uid)); |
| 688 |
|
$this->assertNoRaw(theme('username', $user)); |
| 689 |
|
} |
| 690 |
|
$this->drupalLogout(); |
| 691 |
|
|
| 692 |
|
$hiddens = array(); |
| 693 |
|
// @todo what about testing page two |
| 694 |
|
for ($i = 0; $i < 9; $i++) { |
| 695 |
|
$hiddens[$i] = $this->hiddenCreateHidden(array('type' => 'comment')); |
| 696 |
|
} |
| 697 |
|
|
| 698 |
|
$this->drupalLogin($view_user); |
| 699 |
|
foreach ($hiddens as $hidden) { |
| 700 |
|
$this->drupalGet('hidden/comment'); |
| 701 |
|
// @todo is there a simpletest way of bundling up these asserts? |
| 702 |
|
$comment = _comment_load($hidden->id); |
| 703 |
|
$this->assertText($comment->subject); |
| 704 |
|
$user = user_load(array('uid' => $comment->uid)); |
| 705 |
|
$this->assertRaw(theme('username', $user)); |
| 706 |
|
// @todo reasons again |
| 707 |
|
$this->clickLink($comment->subject); // don't really need to run this everytime |
| 708 |
|
$this->assertText($comment->subject, t('Node title visible on node hidden page')); |
| 709 |
|
$this->assertText($hidden->publicnote, t('Public text posted')); |
| 710 |
|
$this->assertNoText($hidden->privatenote, t('Private text not visible to view only user')); |
| 711 |
|
$this->assertNoText(t('Unhide'), t('No unhide link visible to view only user')); |
| 712 |
|
} |
| 713 |
|
$this->drupalLogout(); |
| 714 |
|
} |
| 715 |
|
} |
| 716 |
|
|
| 717 |
|
/** |
| 718 |
|
* Function test: Admin pages |
| 719 |
|
*/ |
| 720 |
|
class HiddenAdminPagesTestCase extends HiddenHelperCase { |
| 721 |
|
/** |
| 722 |
|
* Implementation of getInfo(). |
| 723 |
|
*/ |
| 724 |
|
function getInfo() { |
| 725 |
|
return array( |
| 726 |
|
'name' => t('View and update module settings'), |
| 727 |
|
'description' => t('View and change basic settings, reasons and filters on admin pages'), |
| 728 |
|
'group' => t('Hidden'), |
| 729 |
|
); |
| 730 |
|
} |
| 731 |
|
|
| 732 |
|
/** |
| 733 |
|
* Test if correct users can view pages. |
| 734 |
|
*/ |
| 735 |
|
function testPageView() { |
| 736 |
|
$this->drupalLogin($this->hide_user); |
| 737 |
|
// trivial but a quick run down |
| 738 |
|
$this->drupalGet('admin/content/hidden'); |
| 739 |
|
$this->assertResponse(403); |
| 740 |
|
// there should always be a reason 1, and by default it is enabled |
| 741 |
|
$this->drupalGet('admin/content/hidden/reasons/edit/1'); |
| 742 |
|
$this->assertResponse(403); |
| 743 |
|
$this->drupalGet('admin/content/hidden/reasons/disable/1'); |
| 744 |
|
$this->assertResponse(403); |
| 745 |
|
$this->drupalGet('admin/content/hidden/reasons/enable/1'); |
| 746 |
|
$this->assertResponse(403); |
| 747 |
|
$this->drupalGet('admin/content/hidden/filters'); |
| 748 |
|
$this->assertResponse(403); |
| 749 |
|
$this->drupalLogout(); |
| 750 |
|
|
| 751 |
|
$this->drupalLogin($this->admin_user); |
| 752 |
|
$this->drupalGet('admin/content/hidden'); |
| 753 |
|
$this->assertResponse(200); |
| 754 |
|
$this->drupalGet('admin/content/hidden/reasons/edit/1'); |
| 755 |
|
$this->assertResponse(200); |
| 756 |
|
$this->drupalGet('admin/content/hidden/reasons/disable/1'); |
| 757 |
|
$this->assertResponse(200, t('Admin can disable reason')); |
| 758 |
|
$this->drupalGet('admin/content/hidden/reasons/enable/1'); |
| 759 |
|
$this->assertResponse(200, t('Admin can enable reason')); |
| 760 |
|
$this->drupalGet('admin/content/hidden/filters'); |
| 761 |
|
$this->drupalLogout(); |
| 762 |
|
} |
| 763 |
|
|
| 764 |
|
function testReasonViewPage() { |
| 765 |
|
$this->drupalLogin($this->admin_user); |
| 766 |
|
$this->drupalGet('admin/content/hidden'); |
| 767 |
|
$this->assertText(t('Policy Violation'), t('Default reason visible')); |
| 768 |
|
// only default reason created so far, so there should be no other reasons |
| 769 |
|
// so can easily just click enable disable links to check and test |
| 770 |
|
$enable = '<a href="'. url('admin/content/hidden/reasons/enable/1') .'">'; |
| 771 |
|
$disable = '<a href="'. url('admin/content/hidden/reasons/disable/1') .'">'; |
| 772 |
|
$this->assertRaw($disable, t('Disable link visible')); |
| 773 |
|
$this->assertNoRaw($enable, t('No enable link visible')); |
| 774 |
|
$this->clickLink(t('disable')); |
| 775 |
|
$this->assertText(t('Reason disabled'), t('Reason reported disabled')); |
| 776 |
|
$this->assertRaw($enable, t('Enable link visible')); |
| 777 |
|
$this->assertNoRaw($disable, t('No disable link visible')); |
| 778 |
|
$this->clickLink(t('enable')); |
| 779 |
|
$this->assertText(t('Reason enabled'), t('Reason reported enabled')); |
| 780 |
|
$this->assertNoRaw($enable, t('No enable link visible')); |
| 781 |
|
$this->assertRaw($disable, t('Disable link visible')); |
| 782 |
|
|
| 783 |
|
$reasons = array(); |
| 784 |
|
// edit the default reason |
| 785 |
|
$this->clickLink(t('edit')); |
| 786 |
|
$edit = array( |
| 787 |
|
'title' => $this->randomName(12), |
| 788 |
|
'description' => $this->randomName(63), |
| 789 |
|
'enabled' => 0, |
| 790 |
|
); |
| 791 |
|
$this->drupalPost(NULL, $edit, t('Submit')); |
| 792 |
|
$this->assertRaw(t('%title has been updated.', array('%title' => $edit['title'])), t('Reason reported updated')); |
| 793 |
|
// save reason for later |
| 794 |
|
$reasons[] = $edit; |
| 795 |
|
|
| 796 |
|
// add some more reasons and check if all can be seen |
| 797 |
|
for ($i = 1; $i < 4; $i++) { |
| 798 |
|
// create a new reason |
| 799 |
|
$this->clickLink(t('Add new reason')); |
| 800 |
|
$edit = array( |
| 801 |
|
'title' => $this->randomName(21), |
| 802 |
|
'description' => $this->randomName(57), |
| 803 |
|
); |
| 804 |
|
$this->drupalPost(NULL, $edit, t('Submit')); |
| 805 |
|
$this->assertRaw(t('%title has been added.', array('%title' => $edit['title'])), t('Reason reported added')); |
| 806 |
|
$reasons[$i] = $edit; |
| 807 |
|
} |
| 808 |
|
$this->drupalGet('admin/content/hidden'); |
| 809 |
|
foreach ($reasons as $reason) { |
| 810 |
|
$this->assertText($reason['title'], t('%title listed', array('%title' => $reason['title']))); |
| 811 |
|
} |
| 812 |
|
} |
| 813 |
|
|
| 814 |
|
function testHiddenFiltersViewPage() { |
| 815 |
|
$this->drupalLogin($this->admin_user); |
| 816 |
|
|
| 817 |
|
$this->drupalGet('admin/content/hidden/filters'); |
| 818 |
|
$this->clickLink(t('Add new filter')); |
| 819 |
|
|
| 820 |
|
$text_filter = $this->text_filter; |
| 821 |
|
$user = user_load($text_filter['uid']); |
| 822 |
|
$text_filter['user'] = $user->name; |
| 823 |
|
unset($text_filter['uid']); |
| 824 |
|
$text_filter['reason'] = $text_filter['rid']; |
| 825 |
|
unset($text_filter['rid']); |
| 826 |
|
$text_filter['publictext'] = $text_filter['publicnote']; |
| 827 |
|
unset($text_filter['publicnote']); |
| 828 |
|
$text_filter['privatetext'] = $text_filter['privatenote']; |
| 829 |
|
unset($text_filter['privatenote']); |
| 830 |
|
|
| 831 |
|
$this->drupalPost(NULL, $text_filter, t('Submit')); |
| 832 |
|
|
| 833 |
|
$this->assertText($text_filter['title']); |
| 834 |
|
// not certain of hfid but there is only one |
| 835 |
|
$enable = '<a href="'. url('admin/content/hidden/filters/enable/') .'\d+">'; |
| 836 |
|
$disable = '<a href="'. url('admin/content/hidden/filters/disable/') .'\d+">'; |
| 837 |
|
$edit = '<a href="'. url('admin/content/hidden/filters/edit/'). '\d+">'; |
| 838 |
|
// check links as enabling and disabling sole filter |
| 839 |
|
$this->assertPattern($disable, t('Disable link visible')); |
| 840 |
|
$this->assertPattern($edit, t('Edit link visible')); |
| 841 |
|
$this->assertNoPattern($enable, t('No enable link visible')); |
| 842 |
|
$this->clickLink(t('disable')); |
| 843 |
|
$this->assertPattern($enable, t('Enable link visible')); |
| 844 |
|
$this->assertNoPattern($disable, t('No disable link visible')); |
| 845 |
|
$this->assertPattern($edit, t('Edit link visible')); |
| 846 |
|
$this->clickLink(t('enable')); |
| 847 |
|
$this->assertNoPattern($enable, t('No enable link visible')); |
| 848 |
|
$this->clickLink(t('edit')); |
| 849 |
|
// change title |
| 850 |
|
$text_filter['title'] = $this->randomName(17); |
| 851 |
|
$this->drupalPost(NULL, array('title' => $text_filter['title']), t('Submit')); |
| 852 |
|
$this->assertText($text_filter['title']); |
| 853 |
|
// @todo weights |
| 854 |
|
} |
| 855 |
|
} |