Code Duplication    Length = 41-41 lines in 3 locations

tests/CommentsTest.php 3 locations

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