public function testApproveAll()
 {
     $t = new ModerationTestsuite();
     # We edit with two users:
     #	$t->unprivilegedUser (A)
     #	and $t->unprivilegedUser2 (B)
     # We're applying approveall to one of the edits by A.
     # Expected result is:
     # 1) All edits by A were approved,
     # 2) No edits by B were touched during approveall.
     $t->doNTestEditsWith($t->unprivilegedUser, $t->unprivilegedUser2);
     $t->fetchSpecial();
     # Find edits by user A (they will be approved)
     $entries = ModerationTestsuiteEntry::findByUser($t->new_entries, $t->unprivilegedUser);
     $this->assertNotNull($entries[0]->approveAllLink, "testApproveAll(): ApproveAll link not found");
     $t->html->loadFromURL($entries[0]->approveAllLink);
     $this->assertRegExp('/\\(moderation-approved-ok: ' . $t->TEST_EDITS_COUNT . '\\)/', $t->html->getMainText(), "testApproveAll(): Result page doesn't contain (moderation-approved-ok: N)");
     $t->fetchSpecial();
     $this->assertCount(0, $t->new_entries, "testApproveAll(): Something was added into Pending folder during modaction=approveall");
     $this->assertCount($t->TEST_EDITS_COUNT, $t->deleted_entries, "testApproveAll(): Several edits were approved, but number of deleted entries in Pending folder doesn't match");
     foreach ($entries as $entry) {
         $rev = $t->getLastRevision($entry->title);
         $this->assertEquals($t->unprivilegedUser->getName(), $rev['user']);
     }
     # Check the log entries: there should be
     # - one 'approveall' log entry
     # - TEST_EDITS_COUNT 'approve' log entries.
     $events = $t->apiLogEntries();
     $this->assertCount(1 + $t->TEST_EDITS_COUNT, $events, "testApproveAll(): Number of log entries doesn't match the number of approved edits PLUS ONE (log entry for ApproveAll itself).");
     # Per design, 'approveall' entry MUST be the most recent.
     $le = array_shift($events);
     $this->assertEquals('approveall', $le['action'], "testApproveAll(): Most recent log entry is not 'approveall'");
     $this->assertEquals($t->moderator->getName(), $le['user']);
     $this->assertEquals($t->unprivilegedUser->getUserPage(), $le['title']);
     foreach ($events as $le) {
         $this->assertEquals('approve', $le['action']);
         $this->assertEquals($t->moderator->getName(), $le['user']);
     }
     # Only the formatting of 'approveall' line needs to be checked,
     # formatting of 'approve' lines already tested in testApprove()
     $events = $t->nonApiLogEntries(1);
     $this->assertEquals('approveall', $events[0]['type']);
     $this->assertEquals($t->moderator->getName(), $events[0]['params'][1]);
     $this->assertEquals($t->unprivilegedUser->getUserPage()->getText(), $events[0]['params'][2]);
     $this->assertEquals($t->TEST_EDITS_COUNT, $events[0]['params'][3]);
 }
 public function testBlock()
 {
     $t = new ModerationTestsuite();
     $entry = $t->getSampleEntry('Test page 1');
     $this->assertNotNull($entry->blockLink, "testBlock(): Block link not found for non-blocked user");
     $this->assertNull($entry->unblockLink, "testBlock(): Unblock link found for non-blocked user");
     $t->html->loadFromURL($entry->blockLink);
     $this->assertRegExp('/\\(moderation-block-ok: ' . preg_quote($entry->user) . '\\)/', $t->html->getMainText(), "testBlock(): Result page doesn't contain (moderation-block-ok)");
     # Now that the user is blocked, try to edit
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit('Test page 2');
     $t->fetchSpecial();
     $this->assertCount(0, $t->new_entries, "testBlock(): Something was added into Pending folder when queueing an edit from spammer");
     $this->assertCount(0, $t->deleted_entries, "testBlock(): Something was deleted from Pending folder when queueing an edit from spammer");
     $t->fetchSpecial('spam');
     $this->assertCount(1, $t->new_entries, "testBlock(): One edit from spammer was queued for moderation, but number of added entries in Spam folder isn't 1");
     $this->assertCount(0, $t->deleted_entries, "testBlock(): Something was deleted from Spam folder during the queueing");
     $entry = $t->new_entries[0];
     $this->assertEquals($t->lastEdit['User'], $entry->user);
     $this->assertEquals($t->lastEdit['Title'], $entry->title);
     $this->assertFalse($entry->rejected_batch, "testBlock(): Edit rejected automatically has rejected_batch flag ON");
     $this->assertTrue($entry->rejected_auto, "testBlock(): Edit rejected automatically edit has rejected_auto flag OFF");
     $this->assertNull($entry->blockLink, "testBlock(): Block link found for blocked user");
     $this->assertNotNull($entry->unblockLink, "testBlock(): Unblock link not found for blocked user");
     $this->assertNull($entry->rejectLink, "testBlock(): Reject link found for already rejected edit");
     $this->assertNull($entry->rejectAllLink, "testBlock(): RejectAll link found for already rejected edit");
     $this->assertNull($entry->approveAllLink, "testBlock(): ApproveAll link found for already rejected edit");
     # Check 'block' log entry
     $events = $t->apiLogEntries();
     $this->assertCount(1, $events, "testBlock(): Wrong number of log entries after modaction=block.");
     $le = $events[0];
     $this->assertEquals('block', $le['action'], "testBlock(): Most recent log entry is not 'block'");
     $this->assertEquals($t->moderator->getName(), $le['user']);
     $this->assertEquals($t->unprivilegedUser->getUserPage(), $le['title']);
     $events = $t->nonApiLogEntries(1);
     $this->assertEquals('block', $events[0]['type']);
     $this->assertEquals($t->moderator->getName(), $events[0]['params'][1]);
     $this->assertEquals($t->unprivilegedUser->getUserPage()->getText(), $events[0]['params'][2]);
     # Unblock the user
     $t->html->loadFromURL($entry->unblockLink);
     $this->assertRegExp('/\\(moderation-unblock-ok: ' . preg_quote($entry->user) . '\\)/', $t->html->getMainText(), "testBlock(): Result page doesn't contain (moderation-unblock-ok)");
     # Check that the user is no longer considered a spammer...
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit('Test page 3');
     $t->fetchSpecial('spam');
     $this->assertCount(0, $t->new_entries, "testBlock(): Something was added into Spam folder when queueing an edit from non-spammer");
     $this->assertCount(0, $t->deleted_entries, "testBlock(): Something was deleted from Spam folder when queueing an edit from non-spammer");
     $t->fetchSpecial();
     $this->assertCount(1, $t->new_entries, "testBlock(): One edit from non-spammer was queued for moderation, but number of added entries in Pending folder isn't 1");
     $this->assertCount(0, $t->deleted_entries, "testBlock(): Something was deleted from Pending folder when queueing an edit from non-spammer");
     $entry = $t->new_entries[0];
     $this->assertEquals($t->lastEdit['User'], $entry->user);
     $this->assertEquals($t->lastEdit['Title'], $entry->title);
     $this->assertNotNull($entry->blockLink, "testBlock(): Block link not found for no-longer-blocked user");
     $this->assertNull($entry->unblockLink, "testBlock(): Unblock link found for no-longer-blocked user");
     # Check 'unblock' log entry
     $events = $t->apiLogEntries();
     $this->assertCount(2, $events, "testBlock(): Wrong number of log entries after modaction=unblock.");
     $le = $events[0];
     $this->assertEquals('unblock', $le['action'], "testBlock(): Most recent log entry is not 'unblock'");
     $this->assertEquals($t->moderator->getName(), $le['user']);
     $this->assertEquals($t->unprivilegedUser->getUserPage(), $le['title']);
     $events = $t->nonApiLogEntries(1);
     $this->assertEquals('unblock', $events[0]['type']);
     $this->assertEquals($t->moderator->getName(), $events[0]['params'][1]);
     $this->assertEquals($t->unprivilegedUser->getUserPage()->getText(), $events[0]['params'][2]);
 }
 public function testRejectAll()
 {
     $t = new ModerationTestsuite();
     # We edit with two users:
     #	$t->unprivilegedUser (A)
     #	and $t->unprivilegedUser2 (B)
     # We're applying rejectall to one of the edits by A.
     # Expected result is:
     # 1) All edits by A were rejected,
     # 2) No edits by B were touched during rejectall.
     $t->doNTestEditsWith($t->unprivilegedUser, $t->unprivilegedUser2);
     $t->fetchSpecial();
     # Find edits by user A (they will be rejected)
     $entries = ModerationTestsuiteEntry::findByUser($t->new_entries, $t->unprivilegedUser);
     $this->assertNotNull($entries[0]->rejectAllLink, "testRejectAll(): RejectAll link not found");
     $t->html->loadFromURL($entries[0]->rejectAllLink);
     $this->assertRegExp('/\\(moderation-rejected-ok: ' . $t->TEST_EDITS_COUNT . '\\)/', $t->html->getMainText(), "testRejectAll(): Result page doesn't contain (moderation-rejected-ok: N)");
     $t->fetchSpecial();
     $this->assertCount(0, $t->new_entries, "testRejectAll(): Something was added into Pending folder during modaction=rejectall");
     $this->assertCount($t->TEST_EDITS_COUNT, $t->deleted_entries, "testRejectAll(): Several edits were rejected, but number of deleted entries in Pending folder doesn't match");
     foreach ($entries as $entry) {
         $de = ModerationTestsuiteEntry::findById($t->deleted_entries, $entry->id);
         $this->assertNotNull($de);
         $this->assertEquals($entry->user, $de->user);
         $this->assertEquals($entry->title, $de->title);
     }
     $t->fetchSpecial('rejected');
     $this->assertCount($t->TEST_EDITS_COUNT, $t->new_entries, "testRejectAll(): Several edits were rejected, but number of new entries in Rejected folder doesn't match");
     $this->assertCount(0, $t->deleted_entries, "testRejectAll(): Something was deleted from Rejected folder during modaction=rejectall");
     foreach ($entries as $entry) {
         $de = ModerationTestsuiteEntry::findById($t->new_entries, $entry->id);
         $this->assertNotNull($de);
         $this->assertEquals($entry->user, $de->user);
         $this->assertEquals($entry->title, $de->title);
         $this->assertEquals($t->moderator->getName(), $de->rejected_by_user);
         $this->assertTrue($de->rejected_batch, "testRejectAll(): Edit rejected via modaction=rejectall has rejected_batch flag OFF");
         $this->assertFalse($de->rejected_auto, "testRejectAll(): Manually rejected edit has rejected_auto flag ON");
         $this->assertNull($de->rejectLink, "testRejectAll(): Reject link found for already rejected edit");
         $this->assertNull($de->rejectAllLink, "testRejectAll(): RejectAll link found for already rejected edit");
         $this->assertNull($de->approveAllLink, "testRejectAll(): ApproveAll link found for already rejected edit");
     }
     # Check the log entry: there should be only one 'rejectall'.
     $events = $t->apiLogEntries();
     $this->assertCount(1, $events, "testRejectAll(): Number of log entries isn't 1.");
     $le = $events[0];
     $this->assertEquals('rejectall', $le['action'], "testRejectAll(): Most recent log entry is not 'rejectall'");
     $this->assertEquals($t->moderator->getName(), $le['user']);
     $this->assertEquals($t->unprivilegedUser->getUserPage(), $le['title']);
     $this->assertEquals($t->TEST_EDITS_COUNT, $le['count']);
     $events = $t->nonApiLogEntries(1);
     $this->assertEquals('rejectall', $events[0]['type']);
     $this->assertEquals($t->moderator->getName(), $events[0]['params'][1]);
     $this->assertEquals($t->unprivilegedUser->getUserPage()->getText(), $events[0]['params'][2]);
     $this->assertEquals($t->TEST_EDITS_COUNT, $events[0]['params'][3]);
 }