| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: hidden.test,v 1.1 2008/12/12 19:23:35 ekes Exp $ |
| 3 |
|
|
| 4 |
// @todo same but with comments |
/** |
| 5 |
|
* @file |
| 6 |
|
* Tests for hidden module. |
| 7 |
|
* |
| 8 |
|
* @todo same but with comments |
| 9 |
|
* @todo ... |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
|
/** |
| 13 |
|
* Hidden test case. |
| 14 |
|
*/ |
| 15 |
class HiddenHelperCase extends DrupalWebTestCase { |
class HiddenHelperCase extends DrupalWebTestCase { |
| 16 |
|
protected $web_user; |
| 17 |
|
protected $view_user; |
| 18 |
|
protected $report_user; |
| 19 |
|
protected $hide_user; |
| 20 |
|
protected $admin_user; |
| 21 |
|
|
| 22 |
function setUp() { |
function setUp() { |
| 23 |
parent::setUp('hidden'); |
parent::setUp('hidden', 'comment'); |
| 24 |
|
// @todo enabling comment is causing simpletest to fail |
| 25 |
|
|
| 26 |
|
$this->web_user = $this->drupalCreateUser(); |
| 27 |
|
$this->view_user = $this->drupalCreateUser(array('access hidden')); |
| 28 |
|
$this->report_user = $this->drupalCreateUser(array('report for hiding')); |
| 29 |
|
// Yes untested edge case able to hide but not see hidden. Make sense? |
| 30 |
|
$this->hide_user = $this->drupalCreateUser(array('mark as hidden', 'access hidden')); |
| 31 |
|
$this->admin_user = $this->drupalCreateUser(array('administer hidden')); |
| 32 |
} |
} |
| 33 |
|
|
| 34 |
/** |
/** |
| 35 |
* Hide a node or comment. |
* Hide a node or comment. |
| 36 |
* |
* |
| 37 |
* Frequently required, the functions are tested in class HiddenHideUnitCase |
* Frequently required |
| 38 |
|
* @see HiddenHideUnitCase::testHiddenHiddenHide() for the first testing. |
| 39 |
* |
* |
| 40 |
* @return object |
* @return object |
| 41 |
* object without delay, only id (not nid|cid), or reason title. |
* object without delay, only id (not nid|cid), or reason title. |
| 49 |
'filter' => FALSE, |
'filter' => FALSE, |
| 50 |
); |
); |
| 51 |
if (empty($settings['id'])) { |
if (empty($settings['id'])) { |
| 52 |
// put into $this-> ? |
if (isset($settings['type']) && $settings['type'] == 'comment') { |
| 53 |
$node = $this->drupalCreateNode(); |
$comment = $this->hiddenCreateComment(); |
| 54 |
$defaults['id'] = $node->nid; |
$defaults['id'] = $comment->cid; |
| 55 |
|
} |
| 56 |
|
else { |
| 57 |
|
$node = $this->drupalCreateNode(); |
| 58 |
|
$defaults['id'] = $node->nid; |
| 59 |
|
} |
| 60 |
} |
} |
| 61 |
if (empty($settings['uid'])) { |
if (empty($settings['uid'])) { |
| 62 |
global $user; |
global $user; |
| 67 |
$this->assertTrue($result, t('Hidden %type record created.', array('%type' => $hide['type']))); |
$this->assertTrue($result, t('Hidden %type record created.', array('%type' => $hide['type']))); |
| 68 |
return (object) $hide; |
return (object) $hide; |
| 69 |
} |
} |
| 70 |
|
|
| 71 |
|
/** |
| 72 |
|
* Report a node or comment. |
| 73 |
|
* |
| 74 |
|
* @see HiddenHideUnitCase::testHiddenReportedHide() for first testing. |
| 75 |
|
* |
| 76 |
|
* @return object |
| 77 |
|
*/ |
| 78 |
|
function hiddenCreateReported($settings = array()) { |
| 79 |
|
$defaults = array( |
| 80 |
|
'type' => 'node', |
| 81 |
|
'rid' => 1, |
| 82 |
|
'publicnote' => $this->randomName(73), |
| 83 |
|
); |
| 84 |
|
if (empty($settings['id'])) { |
| 85 |
|
$node = $this->drupalCreateNode(); |
| 86 |
|
$defaults['id'] = $node->nid; |
| 87 |
|
} |
| 88 |
|
if (empty($settings['uid'])) { |
| 89 |
|
global $user; |
| 90 |
|
$defaults['uid'] = $user->uid; |
| 91 |
|
} |
| 92 |
|
$reported = ($settings + $defaults); |
| 93 |
|
$result = _hidden_reported_hide($reported['type'], $reported['id'], $reported['uid'], $reported['rid'], $reported['publicnote']); |
| 94 |
|
$this->assertTrue($result, t('Report for %type created.', array('%type' => $reported['type']))); |
| 95 |
|
return (object) $reported; |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
/** |
| 99 |
|
* Create a comment. |
| 100 |
|
* |
| 101 |
|
* A first attempt at creating drupalCreateNode() like programatic comment creation. |
| 102 |
|
* - comment_save() does user access checks |
| 103 |
|
* |
| 104 |
|
* @param $settings |
| 105 |
|
* array all optional ('subject', 'comment', 'nid', 'cid', 'pid', 'format', 'status', 'uid', 'name' |
| 106 |
|
* 'homepage', 'mail', 'timestamp') |
| 107 |
|
*/ |
| 108 |
|
function hiddenCreateComment($settings = array()) { |
| 109 |
|
$defaults = array( |
| 110 |
|
'cid' => 0, |
| 111 |
|
'subject' => $this->randomName(12), |
| 112 |
|
'comment' => $this->randomName(53), |
| 113 |
|
'pid' => 0, |
| 114 |
|
'format' => FILTER_FORMAT_DEFAULT, |
| 115 |
|
'status' => COMMENT_PUBLISHED, |
| 116 |
|
); |
| 117 |
|
if (empty($settings['uid'])) { |
| 118 |
|
global $user; |
| 119 |
|
$defaults['uid'] = $user->uid; |
| 120 |
|
} |
| 121 |
|
if (empty($settings['nid'])) { |
| 122 |
|
$node = $this->drupalCreateNode(array('type' => 'article', 'comment' => COMMENT_NODE_READ_WRITE)); |
| 123 |
|
$defaults['nid'] = $node->nid; |
| 124 |
|
} |
| 125 |
|
$settings += $defaults; |
| 126 |
|
$cid = comment_save($settings); |
| 127 |
|
$comment = _comment_load($cid); |
| 128 |
|
$this->assertEqual($comment->cid, $cid, t('Comment created')); |
| 129 |
|
return $comment; |
| 130 |
|
} |
| 131 |
} |
} |
| 132 |
|
|
| 133 |
/** |
/** |
| 150 |
*/ |
*/ |
| 151 |
function testHiddenHiddenHideUnpublish() { |
function testHiddenHiddenHideUnpublish() { |
| 152 |
$node = $this->drupalCreateNode(); |
$node = $this->drupalCreateNode(); |
| 153 |
$this->assertTrue(node_load($node->nid), t('Node created.'.$node->nid)); |
$this->assertTrue(node_load($node->nid), t('Node created.')); |
| 154 |
|
|
| 155 |
|
// node - unpublish |
| 156 |
$result = _hidden_hidden_hide_unpublish('node', $node->nid); |
$result = _hidden_hidden_hide_unpublish('node', $node->nid); |
| 157 |
$this->assertTrue($result, 'No error unpublishing'); |
$this->assertTrue($result, t('No error unpublishing')); |
| 158 |
$node = node_load($node->nid, NULL, TRUE); |
$node = node_load($node->nid, NULL, TRUE); |
| 159 |
$this->assertEqual($node->status, 0, 'Node unpublished'); |
$this->assertEqual($node->status, 0, t('Node unpublished')); |
| 160 |
$this->assertEqual($node->comment, 1, 'Node commenting switched off'); |
$this->assertEqual($node->comment, 1, t('Node commenting switched off')); |
| 161 |
|
// node - republish |
| 162 |
$result = _hidden_hidden_publish('node', $node->nid); |
$result = _hidden_hidden_publish('node', $node->nid); |
| 163 |
$this->assertTrue($result, 'No error publishing'); |
$this->assertTrue($result, t('No error publishing')); |
| 164 |
$node = node_load($node->nid, NULL, TRUE); |
$node = node_load($node->nid, NULL, TRUE); |
| 165 |
$this->assertEqual($node->status, 1, 'Node published'); |
$this->assertEqual($node->status, 1, t('Node published')); |
| 166 |
// @todo comment settings may change see code |
// @todo comment settings may change see code |
| 167 |
$this->assertEqual($node->comment, 2, 'Node commenting switched on'); |
$this->assertEqual($node->comment, 2, t('Node commenting switched on')); |
| 168 |
|
|
| 169 |
|
// comment - unpublish |
| 170 |
|
$comment = $this->hiddenCreateComment(); |
| 171 |
|
$result = _hidden_hidden_hide_unpublish('comment', $comment->cid); |
| 172 |
|
$this->assertTrue($result, 'No error unpublishing'); |
| 173 |
|
$comment = _comment_load($comment->cid); |
| 174 |
|
$this->assertEqual($comment->status, COMMENT_NOT_PUBLISHED, t('Comment unpublished')); |
| 175 |
|
// comment - republish |
| 176 |
|
$result = _hidden_hidden_publish('comment', $comment->cid); |
| 177 |
|
$this->assertTrue($result, t('No error publishing')); |
| 178 |
|
$comment = _comment_load($comment->cid); |
| 179 |
|
$this->assertEqual($comment->status, COMMENT_PUBLISHED, t('Comment published')); |
| 180 |
} |
} |
| 181 |
|
|
| 182 |
/** |
/** |
| 183 |
* Test hiding and retrieving of hidden comments and nodes. |
* Test hiding and retrieving of hidden comments and nodes. |
| 184 |
*/ |
*/ |
| 185 |
function testHiddenHiddenHide() { |
function testHiddenHiddenHide() { |
| 186 |
|
// node - hide |
| 187 |
$hidden_original = $this->hiddenCreateHidden(); |
$hidden_original = $this->hiddenCreateHidden(); |
| 188 |
$node = node_load($hidden_original->id, NULL, TRUE); |
$node = node_load($hidden_original->id, NULL, TRUE); |
| 189 |
$hidden_retrieved = _hidden_hidden_get('node', $node->nid); |
$hidden_retrieved = _hidden_hidden_get('node', $node->nid); |
| 194 |
$this->assertEqual($hidden_original->rid, $hidden_retrieved->rid, t('Correct reason recorded')); |
$this->assertEqual($hidden_original->rid, $hidden_retrieved->rid, t('Correct reason recorded')); |
| 195 |
$this->assertEqual($hidden_original->publicnote, $hidden_retrieved->publicnote, t('Correct public note recorded')); |
$this->assertEqual($hidden_original->publicnote, $hidden_retrieved->publicnote, t('Correct public note recorded')); |
| 196 |
$this->assertEqual($hidden_original->privatenote, $hidden_retrieved->privatenote, t('Correct private note recorded')); |
$this->assertEqual($hidden_original->privatenote, $hidden_retrieved->privatenote, t('Correct private note recorded')); |
| 197 |
// and then unhide |
// node - unhide |
| 198 |
_hidden_hidden_unhide('node', $hidden_retrieved->id); |
_hidden_hidden_unhide('node', $hidden_retrieved->id); |
|
$node = node_load($hidden_retrieved->id, NULL, TRUE); |
|
| 199 |
$this->assertFalse(_hidden_hidden_get('node', $hidden_retrieved->id), t('Node removed from hidden table')); |
$this->assertFalse(_hidden_hidden_get('node', $hidden_retrieved->id), t('Node removed from hidden table')); |
| 200 |
|
|
| 201 |
|
// comment - hide, different rid checked too (it's the only non changing) |
| 202 |
|
$hidden_original = $this->hiddenCreateHidden(array('type' => 'comment', 'rid' => 18)); |
| 203 |
|
$comment = _comment_load($hidden_original->id); |
| 204 |
|
$hidden_retrieved = _hidden_hidden_get('comment', $comment->cid); |
| 205 |
|
$this->assertTrue(is_object($hidden_retrieved), t('Hidden node record retrieved.')); |
| 206 |
|
$this->assertEqual($hidden_retrieved->type, 'comment', t('Correct type recorded.')); |
| 207 |
|
$this->assertEqual($hidden_original->id, $hidden_retrieved->cid, t('Correct cid recorded')); |
| 208 |
|
$this->assertEqual($hidden_retrieved->id, $comment->cid, t('Correct id reported')); |
| 209 |
|
$this->assertEqual($hidden_original->rid, $hidden_retrieved->rid, t('Correct reason recorded')); |
| 210 |
|
$this->assertEqual($hidden_original->publicnote, $hidden_retrieved->publicnote, t('Correct public note recorded')); |
| 211 |
|
$this->assertEqual($hidden_original->privatenote, $hidden_retrieved->privatenote, t('Correct private note recorded')); |
| 212 |
|
// comment - unhide |
| 213 |
|
_hidden_hidden_unhide('comment', $hidden_retrieved->id); |
| 214 |
|
$this->assertFalse(_hidden_hidden_get('comment', $hidden_retrieved->id), t('Comment removed from hidden table')); |
| 215 |
|
|
| 216 |
// @todo variations - already hidden, timelapsed, |
// @todo variations - already hidden, timelapsed, |
| 217 |
} |
} |
| 218 |
|
|
| 219 |
|
/** |
| 220 |
|
* Test reporting and retrieving of reports of comments and nodes. |
| 221 |
|
*/ |
| 222 |
|
function testHiddenReportedHide() { |
| 223 |
|
$reported_orginal = $this->hiddenCreateReported(); |
| 224 |
|
// @todo when there is an individual inteface for editing/viewing reported or query it |
| 225 |
|
} |
| 226 |
} |
} |
| 227 |
|
|
| 228 |
/** |
/** |
| 243 |
function testPageView() { |
function testPageView() { |
| 244 |
$node = $this->drupalCreateNode(); |
$node = $this->drupalCreateNode(); |
| 245 |
$this->assertTrue(node_load($node->nid), t('Node created.')); |
$this->assertTrue(node_load($node->nid), t('Node created.')); |
| 246 |
|
$hidden = $this->hiddenCreateHidden(); |
| 247 |
|
|
| 248 |
$hide_user = $this->drupalCreateUser(array('mark as hidden')); |
$this->drupalLogin($this->web_user); |
| 249 |
$this->drupalLogin($hide_user); |
$this->drupalGet(hidden_path('node', $hidden->id, 'view')); |
| 250 |
|
$this->assertResponse(403, t('Unprivileged user cannot access hidden view page')); |
| 251 |
$this->drupalGet('hidden/node/'. $node->nid .'/hide'); |
$this->drupalGet(hidden_path('node', $node->nid, 'hide')); |
| 252 |
$this->assertResponse(200); |
$this->assertResponse(403, t('Unprivileged user cannot access node hide page')); |
| 253 |
|
$this->drupalGet(hidden_path('node', $node->nid, 'report')); |
| 254 |
|
$this->assertResponse(403, t('Unprivileged user cannot access node report page')); |
| 255 |
|
$this->drupalLogout(); |
| 256 |
|
|
| 257 |
|
$this->drupalLogin($this->view_user); |
| 258 |
|
$this->drupalGet(hidden_path('node', $hidden->id, 'view')); |
| 259 |
|
$this->assertResponse(200, t('View user can access hidden view page')); |
| 260 |
|
$this->drupalGet(hidden_path('node', $node->nid, 'hide')); |
| 261 |
|
$this->assertResponse(403, t('View user cannot access node hide page')); |
| 262 |
|
$this->drupalGet(hidden_path('node', $node->nid, 'report')); |
| 263 |
|
$this->assertResponse(403, t('View user cannot access node report page')); |
| 264 |
|
$this->drupalLogout(); |
| 265 |
|
|
| 266 |
|
$this->drupalLogin($this->report_user); |
| 267 |
|
$this->drupalGet(hidden_path('node', $hidden->id, 'view')); |
| 268 |
|
$this->assertResponse(403, t('Report user cannot access hidden view page')); |
| 269 |
|
$this->drupalGet(hidden_path('node', $node->nid, 'hide')); |
| 270 |
|
$this->assertResponse(403, t('Report user cannot access node hide page')); |
| 271 |
|
$this->drupalGet(hidden_path('node', $node->nid, 'report')); |
| 272 |
|
$this->assertResponse(200, t('Report user can access node report page')); |
| 273 |
|
$this->drupalGet(hidden_path('node', $hidden->id, 'report')); |
| 274 |
|
$this->assertText(t('Item is already hidden.'), t('Already hidden message displayed')); |
| 275 |
|
$this->drupalLogout(); |
| 276 |
|
|
| 277 |
|
$this->drupalLogin($this->hide_user); |
| 278 |
|
$this->drupalGet(hidden_path('node', $node->nid, 'hide')); |
| 279 |
|
$this->assertResponse(200, t('User can access hide page')); |
| 280 |
|
$this->drupalGet(hidden_path('node', $hidden->id, 'hide')); |
| 281 |
|
$this->assertText(t('Item is already hidden.'), t('Already hidden message displayed')); |
| 282 |
|
$this->drupalGet('node/'. $hidden->id); |
| 283 |
|
$this->assertResponse(403, t('Hidden cannot be accessed at original url')); |
| 284 |
|
$this->drupalLogout(); |
| 285 |
} |
} |
| 286 |
|
|
| 287 |
|
|
| 288 |
function testHiddenHide() { |
function testHiddenHide() { |
| 289 |
// Create user to hide content. |
// Create user to hide content. |
| 290 |
$hide_user = $this->drupalCreateUser(array('mark as hidden', 'access hidden')); |
$this->drupalLogin($this->hide_user); |
|
$this->drupalLogin($hide_user); |
|
| 291 |
|
|
| 292 |
// make node to hide |
// make node to hide |
| 293 |
$node = $this->drupalCreateNode(array('type' => 'article')); |
$node = $this->drupalCreateNode(array('type' => 'article')); |
|
$this->assertTrue(node_load($node->nid), t('Node created.')); |
|
| 294 |
|
|
| 295 |
// Submit hide form |
// Submit hide form |
| 296 |
$hide = array( |
$hide = array( |
| 297 |
// 'user' => $hide_user->name, // @todo test administer hidden where it can be set |
// 'user' => $hide_user->name, // @todo test administer hidden where it can be set |
| 298 |
'reason' => 1, |
'reason' => 1, |
| 299 |
'publictext' => $this->randomName(25), |
// @todo length restriction 128 - correct or not |
| 300 |
|
'publictext' => $this->randomName(108), |
| 301 |
'privatetext' => $this->randomName(33), |
'privatetext' => $this->randomName(33), |
| 302 |
); |
); |
| 303 |
$this->drupalPost('hidden/node/'. $node->nid .'/hide', $hide, t('Hide')); |
$this->drupalPost(hidden_path('node', $node->nid, 'hide'), $hide, t('Hide')); |
| 304 |
$this->assertText(t('Hidden node'), 'Node reported hidden'); |
$this->assertText(t('Hidden node'), t('Node reported hidden')); |
| 305 |
$this->assertText($hide['publictext'], 'Public text posted'); |
$this->assertText($hide['publictext'], t('Public text posted')); |
| 306 |
$this->assertText($hide['privatetext'], 'Private text posted'); |
$this->assertText($hide['privatetext'], t('Private text posted')); |
| 307 |
// @todo and reason |
// @todo check reason is displayed in words |
| 308 |
|
|
| 309 |
// Click the unhide link |
// Click the unhide link |
| 310 |
$this->clickLink(t('unhide')); |
$this->clickLink(t('unhide')); |
| 311 |
$this->assertText(t('Hidden node unhidden')); |
$this->assertText(t('Hidden node unhidden')); |
| 312 |
$this->assertNoText($hide['publictext'], t('Hidden text not shown')); |
$this->assertNoText($hide['publictext'], t('Hidden text not shown')); |
| 313 |
$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))); |
| 314 |
} |
|
| 315 |
|
// make comment to hide |
| 316 |
|
$comment = $this->hiddenCreateComment(array('type' => 'comment')); |
| 317 |
|
$hide = array( |
| 318 |
|
'reason' => 1, |
| 319 |
|
'publictext' => $this->randomName(82), |
| 320 |
|
'privatetext' => $this->randomName(12), |
| 321 |
|
); |
| 322 |
|
$this->drupalPost(hidden_path('comment', $comment->cid, 'hide'), $hide, t('Hide')); |
| 323 |
|
$this->assertText(t('Hidden comment.'), t('Comment reported hidden')); |
| 324 |
|
$this->assertText($hide['publictext'], t('Public text posted')); |
| 325 |
|
$this->assertText($hide['privatetext'], t('Private text posted')); |
| 326 |
|
|
| 327 |
|
$this->clickLink(t('unhide')); |
| 328 |
|
$this->assertText(t('Hidden comment unhidden')); |
| 329 |
|
$this->assertNoText($hide['publictext'], t('Hidden text not shown')); |
| 330 |
|
$this->asserttext($comment->subject, t('On page with comment title %title visible', array('%title' => $comment->subject))); |
| 331 |
|
} |
| 332 |
|
|
| 333 |
|
function testHiddenReport() { |
| 334 |
|
$this->drupalLogin($this->report_user); |
| 335 |
|
$node = $this->drupalCreateNode(array('type' => 'article')); |
| 336 |
|
|
| 337 |
|
// Submit report form |
| 338 |
|
$report = array( |
| 339 |
|
'reason' => 1, |
| 340 |
|
'publictext' => $this->randomName(23), |
| 341 |
|
); |
| 342 |
|
$this->drupalPost(hidden_path('node', $node->nid, 'report'), $report, t('Report')); |
| 343 |
|
$this->assertText(t('Reported node'), t('Node reported as reported')); |
| 344 |
|
|
| 345 |
|
// @todo hide_user (?) to check the report |
| 346 |
|
} |
| 347 |
} |
} |