|
@@ 274-314 (lines=41) @@
|
| 271 |
|
$this->assertFalse($check && $check->exists()); |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
public function testSpamComment() |
| 275 |
|
{ |
| 276 |
|
// Test anonymous user |
| 277 |
|
if ($member = Member::currentUser()) { |
| 278 |
|
$member->logOut(); |
| 279 |
|
} |
| 280 |
|
$comment = $this->objFromFixture('Comment', 'firstComA'); |
| 281 |
|
$commentID = $comment->ID; |
| 282 |
|
$this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link'); |
| 283 |
|
$spam = $this->get('CommentingController/spam/'.$comment->ID.'?ajax=1'); |
| 284 |
|
$this->assertEquals(403, $spam->getStatusCode()); |
| 285 |
|
$check = DataObject::get_by_id('Comment', $commentID); |
| 286 |
|
$this->assertEquals(0, $check->IsSpam, 'No permission to mark as spam'); |
| 287 |
|
|
| 288 |
|
// Test non-authenticated user |
| 289 |
|
$this->logInAs('visitor'); |
| 290 |
|
$this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link'); |
| 291 |
|
|
| 292 |
|
// Test authenticated user |
| 293 |
|
$this->logInAs('commentadmin'); |
| 294 |
|
$comment = $this->objFromFixture('Comment', 'firstComA'); |
| 295 |
|
$commentID = $comment->ID; |
| 296 |
|
$adminComment1Link = $comment->SpamLink(); |
| 297 |
|
$this->assertContains('CommentingController/spam/'.$commentID.'?t=', $adminComment1Link); |
| 298 |
|
|
| 299 |
|
// Test that this link can't be shared / XSS exploited |
| 300 |
|
$this->logInAs('commentadmin2'); |
| 301 |
|
$spam = $this->get($adminComment1Link); |
| 302 |
|
$this->assertEquals(400, $spam->getStatusCode()); |
| 303 |
|
$check = DataObject::get_by_id('Comment', $comment->ID); |
| 304 |
|
$this->assertEquals(0, $check->IsSpam, 'No permission to mark as spam'); |
| 305 |
|
|
| 306 |
|
// Test that this other admin can spam the comment with their own link |
| 307 |
|
$adminComment2Link = $comment->SpamLink(); |
| 308 |
|
$this->assertNotEquals($adminComment2Link, $adminComment1Link); |
| 309 |
|
$this->autoFollowRedirection = false; |
| 310 |
|
$spam = $this->get($adminComment2Link); |
| 311 |
|
$this->assertEquals(302, $spam->getStatusCode()); |
| 312 |
|
$check = DataObject::get_by_id('Comment', $commentID); |
| 313 |
|
$this->assertEquals(1, $check->IsSpam); |
| 314 |
|
|
| 315 |
|
// Cannot re-spam spammed comment |
| 316 |
|
$this->assertNull($check->SpamLink()); |
| 317 |
|
} |
|
@@ 319-359 (lines=41) @@
|
| 316 |
|
$this->assertNull($check->SpamLink()); |
| 317 |
|
} |
| 318 |
|
|
| 319 |
|
public function testHamComment() |
| 320 |
|
{ |
| 321 |
|
// Test anonymous user |
| 322 |
|
if ($member = Member::currentUser()) { |
| 323 |
|
$member->logOut(); |
| 324 |
|
} |
| 325 |
|
$comment = $this->objFromFixture('Comment', 'secondComC'); |
| 326 |
|
$commentID = $comment->ID; |
| 327 |
|
$this->assertNull($comment->HamLink(), 'No permission to see mark as ham link'); |
| 328 |
|
$ham = $this->get('CommentingController/ham/'.$comment->ID.'?ajax=1'); |
| 329 |
|
$this->assertEquals(403, $ham->getStatusCode()); |
| 330 |
|
$check = DataObject::get_by_id('Comment', $commentID); |
| 331 |
|
$this->assertEquals(1, $check->IsSpam, 'No permission to mark as ham'); |
| 332 |
|
|
| 333 |
|
// Test non-authenticated user |
| 334 |
|
$this->logInAs('visitor'); |
| 335 |
|
$this->assertNull($comment->HamLink(), 'No permission to see mark as ham link'); |
| 336 |
|
|
| 337 |
|
// Test authenticated user |
| 338 |
|
$this->logInAs('commentadmin'); |
| 339 |
|
$comment = $this->objFromFixture('Comment', 'secondComC'); |
| 340 |
|
$commentID = $comment->ID; |
| 341 |
|
$adminComment1Link = $comment->HamLink(); |
| 342 |
|
$this->assertContains('CommentingController/ham/'.$commentID.'?t=', $adminComment1Link); |
| 343 |
|
|
| 344 |
|
// Test that this link can't be shared / XSS exploited |
| 345 |
|
$this->logInAs('commentadmin2'); |
| 346 |
|
$ham = $this->get($adminComment1Link); |
| 347 |
|
$this->assertEquals(400, $ham->getStatusCode()); |
| 348 |
|
$check = DataObject::get_by_id('Comment', $comment->ID); |
| 349 |
|
$this->assertEquals(1, $check->IsSpam, 'No permission to mark as ham'); |
| 350 |
|
|
| 351 |
|
// Test that this other admin can ham the comment with their own link |
| 352 |
|
$adminComment2Link = $comment->HamLink(); |
| 353 |
|
$this->assertNotEquals($adminComment2Link, $adminComment1Link); |
| 354 |
|
$this->autoFollowRedirection = false; |
| 355 |
|
$ham = $this->get($adminComment2Link); |
| 356 |
|
$this->assertEquals(302, $ham->getStatusCode()); |
| 357 |
|
$check = DataObject::get_by_id('Comment', $commentID); |
| 358 |
|
$this->assertEquals(0, $check->IsSpam); |
| 359 |
|
|
| 360 |
|
// Cannot re-ham hammed comment |
| 361 |
|
$this->assertNull($check->HamLink()); |
| 362 |
|
} |
|
@@ 364-404 (lines=41) @@
|
| 361 |
|
$this->assertNull($check->HamLink()); |
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
public function testApproveComment() |
| 365 |
|
{ |
| 366 |
|
// Test anonymous user |
| 367 |
|
if ($member = Member::currentUser()) { |
| 368 |
|
$member->logOut(); |
| 369 |
|
} |
| 370 |
|
$comment = $this->objFromFixture('Comment', 'secondComB'); |
| 371 |
|
$commentID = $comment->ID; |
| 372 |
|
$this->assertNull($comment->ApproveLink(), 'No permission to see approve link'); |
| 373 |
|
$approve = $this->get('CommentingController/approve/'.$comment->ID.'?ajax=1'); |
| 374 |
|
$this->assertEquals(403, $approve->getStatusCode()); |
| 375 |
|
$check = DataObject::get_by_id('Comment', $commentID); |
| 376 |
|
$this->assertEquals(0, $check->Moderated, 'No permission to approve'); |
| 377 |
|
|
| 378 |
|
// Test non-authenticated user |
| 379 |
|
$this->logInAs('visitor'); |
| 380 |
|
$this->assertNull($comment->ApproveLink(), 'No permission to see approve link'); |
| 381 |
|
|
| 382 |
|
// Test authenticated user |
| 383 |
|
$this->logInAs('commentadmin'); |
| 384 |
|
$comment = $this->objFromFixture('Comment', 'secondComB'); |
| 385 |
|
$commentID = $comment->ID; |
| 386 |
|
$adminComment1Link = $comment->ApproveLink(); |
| 387 |
|
$this->assertContains('CommentingController/approve/'.$commentID.'?t=', $adminComment1Link); |
| 388 |
|
|
| 389 |
|
// Test that this link can't be shared / XSS exploited |
| 390 |
|
$this->logInAs('commentadmin2'); |
| 391 |
|
$approve = $this->get($adminComment1Link); |
| 392 |
|
$this->assertEquals(400, $approve->getStatusCode()); |
| 393 |
|
$check = DataObject::get_by_id('Comment', $comment->ID); |
| 394 |
|
$this->assertEquals(0, $check->Moderated, 'No permission to approve'); |
| 395 |
|
|
| 396 |
|
// Test that this other admin can approve the comment with their own link |
| 397 |
|
$adminComment2Link = $comment->ApproveLink(); |
| 398 |
|
$this->assertNotEquals($adminComment2Link, $adminComment1Link); |
| 399 |
|
$this->autoFollowRedirection = false; |
| 400 |
|
$approve = $this->get($adminComment2Link); |
| 401 |
|
$this->assertEquals(302, $approve->getStatusCode()); |
| 402 |
|
$check = DataObject::get_by_id('Comment', $commentID); |
| 403 |
|
$this->assertEquals(1, $check->Moderated); |
| 404 |
|
|
| 405 |
|
// Cannot re-approve approved comment |
| 406 |
|
$this->assertNull($check->ApproveLink()); |
| 407 |
|
} |