public function testNothingToAll() { $t = new ModerationTestsuite(); $entry = $t->getSampleEntry(); $t->httpGet($entry->rejectLink); $error = $t->html->getModerationError($entry->rejectAllLink); $this->assertEquals('(moderation-nothing-to-rejectall)', $error); $error = $t->html->getModerationError($entry->approveAllLink); $this->assertEquals('(moderation-nothing-to-approveall)', $error); }
/** @covers ModerationCheckUserHook */ public function testPreverveUserAgent() { global $wgSpecialPages; $t = new ModerationTestsuite(); $dbw = wfGetDB(DB_MASTER); if (!array_key_exists('CheckUser', $wgSpecialPages) || !$dbw->tableExists('cu_changes')) { $this->markTestIncomplete('Test skipped: CheckUser extension must be installed to run it.'); } $moderatorUA = 'UserAgent of Moderator/1.0'; $userUA = 'UserAgent of UnprivilegedUser/1.0'; # When the edit is approved, cu_changes.cuc_agent field should # contain UserAgent of user who made the edit, # not UserAgent or the moderator who approved it. $t->setUserAgent($userUA); $entry = $t->getSampleEntry(); $t->setUserAgent($moderatorUA); $t->httpGet($entry->approveLink); $row = $dbw->selectRow('cu_changes', array('cuc_agent AS agent'), array('1'), __METHOD__, array('ORDER BY' => 'cuc_id DESC', 'LIMIT' => 1)); $this->assertNotEquals($moderatorUA, $row->agent, "testPreverveUserAgent(): UserAgent in checkuser tables matches moderator's UserAgent"); $this->assertEquals($userUA, $row->agent, "testPreverveUserAgent(): UserAgent in checkuser tables doesn't match UserAgent of user who made the edit"); }
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 testApproveTimestamp() { $t = new ModerationTestsuite(); $entry = $t->getSampleEntry(); $TEST_TIME_CHANGE = '6 hours'; $ACCEPTABLE_DIFFERENCE = 300; # in seconds $ts = new MWTimestamp(time()); $ts->timestamp->modify('-' . $TEST_TIME_CHANGE); $dbw = wfGetDB(DB_MASTER); $dbw->update('moderation', array('mod_timestamp' => $ts->getTimestamp(TS_MW)), array('mod_id' => $entry->id), __METHOD__); $rev = $this->tryToApprove($t, $entry); # Page history should mention the time when edit was made, # not when it was approved. $expected = $ts->getTimestamp(TS_ISO_8601); $this->assertEquals($expected, $rev['timestamp'], "testApproveTimestamp(): approved edit has incorrect timestamp in the page history"); # RecentChanges should mention the time when the edit was # approved, so that it won't "appear in the past", confusing # those who read RecentChanges. $ret = $t->query(array('action' => 'query', 'list' => 'recentchanges', 'rcprop' => 'timestamp', 'rclimit' => 1, 'rcuser' => $t->lastEdit['User'])); $rc_timestamp = $ret['query']['recentchanges'][0]['timestamp']; $this->assertNotEquals($expected, $rc_timestamp, "testApproveTimestamp(): approved edit has \"appeared in the past\" in the RecentChanges"); # Does the time in RecentChanges match the time of approval? # # NOTE: we don't know the time of approval to the second, so # string comparison can't be used. Difference can be seconds # or even minutes (if system time is off). $ts->timestamp->modify('+' . $TEST_TIME_CHANGE); $expected = $ts->getTimestamp(TS_UNIX); $ts_actual = new MWTimestamp($rc_timestamp); $actual = $ts_actual->getTimestamp(TS_UNIX); $this->assertLessThan($ACCEPTABLE_DIFFERENCE, abs($expected - $actual), "testApproveTimestamp(): timestamp of approved edit in RecentChanges is too different from the time of approval"); }