コード例 #1
0
 private function makeEditConflict(ModerationTestsuite $t)
 {
     $t->loginAs($t->automoderated);
     $t->doTestEdit($this->page, $this->text0, "Create an article. Some lines here are boring.");
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit($this->page, $this->text1, "Improve one of the boring lines");
     $t->loginAs($t->automoderated);
     $t->doTestEdit($this->page, $this->text2, "Delete all boring lines");
 }
コード例 #2
0
 public function testPostEditRedirect()
 {
     $t = new ModerationTestsuite();
     $t->loginAs($t->unprivilegedUser);
     $req = $t->doTestEdit();
     $t->fetchSpecial();
     $this->assertTrue($req->status->isOK());
     $this->assertTrue($req->isRedirect(), "testPostEditRedirect(): User hasn't been redirected after the edit");
     # Check the redirect URL
     $url = $req->getResponseHeader("Location");
     $params = wfCgiToArray(preg_replace('/^.*?\\?/', '', $url));
     $this->assertArrayHasKey('title', $params);
     $this->assertArrayHasKey('modqueued', $params);
     $this->assertCount(2, $params, "testPostEditRedirect(): redirect URL has parameters other than 'title' and 'modqueued'");
     $this->assertEquals($t->lastEdit['Title'], preg_replace('/_/', ' ', $params['title']), "testPostEditRedirect(): Title in the redirect URL doesn't match the title of page we edited");
     $this->assertEquals(1, $params['modqueued'], "testPostEditRedirect(): parameter modqueued=1 not found in the redirect URL");
     # Check the page where the user is being redirected to
     $list = $t->html->getLoaderModulesList($url);
     $this->assertContains('ext.moderation.notify', $list, "testPostEditRedirect(): Module ext.moderation.notify wasn't loaded");
     # Usual checks on whether the edit not via API was intercepted.
     $this->assertCount(1, $t->new_entries, "testPostEditRedirect(): One edit was queued for moderation, but number of added entries in Pending folder isn't 1");
     $this->assertCount(0, $t->deleted_entries, "testPostEditRedirect(): Something was deleted from Pending folder during the queueing");
     $this->assertEquals($t->lastEdit['User'], $t->new_entries[0]->user);
     $this->assertEquals($t->lastEdit['Title'], $t->new_entries[0]->title);
 }
コード例 #3
0
 public function testShow()
 {
     $t = new ModerationTestsuite();
     $page = 'Test page 1';
     $text1 = "First string\nSecond string\nThird string\n";
     $text2 = "First string\nAnother second string\nThird string\n";
     $t->loginAs($t->automoderated);
     $t->doTestEdit($page, $text1);
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit($page, $text2);
     $t->fetchSpecial();
     $url = $t->new_entries[0]->showLink;
     $this->assertNotNull($url, "testShow(): Show link not found");
     $this->assertNotRegExp('/token=/', $url, "testShow(): Token was found in the read-only Show link");
     $title = $t->html->getTitle($url);
     $this->assertRegExp('/\\(difference-title: ' . preg_quote($page) . '\\)/', $title, "testShow(): Difference page has a wrong HTML title");
     $added_lines = array();
     $deleted_lines = array();
     $context_lines = array();
     $table_cells = $t->html->getElementsByTagName('td');
     foreach ($table_cells as $td) {
         $class = $td->getAttribute('class');
         $text = $td->textContent;
         if ($class == 'diff-addedline') {
             $added_lines[] = $text;
         } else {
             if ($class == 'diff-deletedline') {
                 $deleted_lines[] = $text;
             } else {
                 if ($class == 'diff-context') {
                     $context_lines[] = $text;
                 }
             }
         }
     }
     # Each context line is shown twice: in Before and After columns
     $this->assertCount(4, $context_lines, "testShow(): Two lines were unchanged, but number of context lines on the difference page is not 4");
     $this->assertEquals('First string', $context_lines[0]);
     $this->assertEquals('First string', $context_lines[1]);
     $this->assertEquals('Third string', $context_lines[2]);
     $this->assertEquals('Third string', $context_lines[3]);
     $this->assertCount(1, $added_lines, "testShow(): One line was modified, but number of added lines on the difference page is not 1");
     $this->assertCount(1, $deleted_lines, "testShow(): One line was modified, but number of deleted lines on the difference page is not 1");
     $this->assertEquals('Another second string', $added_lines[0]);
     $this->assertEquals('Second string', $deleted_lines[0]);
 }
コード例 #4
0
 public function testAutomoderated()
 {
     $t = new ModerationTestsuite();
     $t->loginAs($t->automoderated);
     $t->editViaAPI = true;
     $ret = $t->doTestEdit();
     $t->fetchSpecial();
     $this->assertArrayHasKey('edit', $ret);
     $this->assertEquals('Success', $ret['edit']['result']);
     $this->assertCount(0, $t->new_entries, "testAutomoderated(): Something was added into Pending folder");
 }
コード例 #5
0
 public function testPreloadSummary()
 {
     $t = new ModerationTestsuite();
     # Summaries are only preloaded for existing pages, so we need
     # to create the page first. (see KNOWN_LIMITATIONS for details)
     $page = "Test page 1";
     $summary = "The quick brown fox jumps over the lazy dog";
     $t->loginAs($t->automoderated);
     $t->doTestEdit($page, "Text 1");
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit($page, "Another text", $summary);
     $this->assertEquals($t->lastEdit['Text'], $t->html->getPreloadedText($t->lastEdit['Title']), "testPreloadSummary(): Preloaded text differs from what the user saved before");
     $elem = $t->html->getElementById('wpSummary');
     $this->assertTrue($elem->hasAttribute('value'), "testPreloadSummary(): #wpSummary doesn't have a 'value' attribute");
     $this->assertEquals($summary, $elem->getAttribute('value'), "testPreloadSummary(): Preloaded summary doesn't match");
     $this->assertContains('ext.moderation.edit', $t->html->getLoaderModulesList(), "testPreloadSummary(): Module ext.moderation.edit wasn't loaded");
     $elem = $t->html->getElementById('mw-editing-your-version');
     $this->assertNotNull($elem, "testPreloadSummary(): #mw-editing-your-version not found");
     $this->assertEquals('(moderation-editing-your-version)', $elem->textContent, "testPreloadSummary(): #mw-editing-your-version doesn't contain (moderation-editing-your-version) message");
 }
コード例 #6
0
 public function testReject()
 {
     $t = new ModerationTestsuite();
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit();
     $t->fetchSpecial();
     $entry = $t->new_entries[0];
     $this->assertNotNull($entry->rejectLink, "testReject(): Reject link not found");
     $t->html->loadFromURL($entry->rejectLink);
     $this->assertRegExp('/\\(moderation-rejected-ok: 1\\)/', $t->html->getMainText(), "testReject(): Result page doesn't contain (moderation-rejected-ok: 1)");
     $t->fetchSpecial();
     $this->assertCount(0, $t->new_entries, "testReject(): Something was added into Pending folder during modaction=reject");
     $this->assertCount(1, $t->deleted_entries, "testReject(): One edit was rejected, but number of deleted entries in Pending folder isn't 1");
     $this->assertEquals($entry->id, $t->deleted_entries[0]->id);
     $this->assertEquals($t->lastEdit['User'], $t->deleted_entries[0]->user);
     $this->assertEquals($t->lastEdit['Title'], $t->deleted_entries[0]->title);
     $t->fetchSpecial('rejected');
     $this->assertCount(1, $t->new_entries, "testReject(): One edit was rejected, but number of new entries in Rejected folder isn't 1");
     $this->assertCount(0, $t->deleted_entries, "testReject(): Something was deleted from Rejected folder during modaction=reject");
     $this->assertEquals($entry->id, $t->new_entries[0]->id);
     $this->assertEquals($t->lastEdit['User'], $t->new_entries[0]->user);
     $this->assertEquals($t->lastEdit['Title'], $t->new_entries[0]->title);
     $this->assertEquals($t->moderator->getName(), $t->new_entries[0]->rejected_by_user);
     $this->assertFalse($t->new_entries[0]->rejected_batch, "testReject(): Edit rejected via modaction=reject has rejected_batch flag ON");
     $this->assertFalse($t->new_entries[0]->rejected_auto, "testReject(): Manually rejected edit has rejected_auto flag ON");
     $this->assertNull($t->new_entries[0]->rejectLink, "testReject(): Reject link found for already rejected edit");
     $this->assertNull($t->new_entries[0]->rejectAllLink, "testReject(): RejectAll link found for already rejected edit");
     $this->assertNull($t->new_entries[0]->approveAllLink, "testReject(): ApproveAll link found for already rejected edit");
     # Check the log entry
     $events = $t->apiLogEntries();
     $this->assertCount(1, $events, "testReject(): Number of log entries isn't 1.");
     $le = $events[0];
     $this->assertEquals('reject', $le['action'], "testReject(): Most recent log entry is not 'reject'");
     $this->assertEquals($t->lastEdit['Title'], $le['title']);
     $this->assertEquals($t->moderator->getName(), $le['user']);
     $this->assertEquals($t->unprivilegedUser->getName(), $le['user_text']);
     $this->assertEquals($entry->id, $le['modid']);
     $events = $t->nonApiLogEntries(1);
     $this->assertEquals('reject', $events[0]['type']);
     $this->assertEquals($t->moderator->getName(), $events[0]['params'][1]);
     $this->assertEquals($t->lastEdit['Title'], $events[0]['params'][2]);
     $this->assertEquals('(moderation-log-change: ' . $entry->id . ')', $events[0]['params'][3]);
     $this->assertEquals($t->unprivilegedUser->getUserPage()->getText(), $events[0]['params'][4]);
 }
コード例 #7
0
 public function testEditSections()
 {
     $t = new ModerationTestsuite();
     # Note: we must do more than one edit here,
     # because sections-related code in ModerationEditHooks is only
     # used when user makes more than one edit to the same page.
     #
     # On the first edit, mod_text doesn't exist and therefore
     # doesn't need to be corrected.
     $sections = array("Text in zero section\n\n", "== First section ==\nText in first section\n\n", "== Second section ==\nText in second section\n\n", "== Third section ==\nText in third section\n\n");
     $title = 'Test page 1';
     $text = join('', $sections);
     $t->loginAs($t->automoderated);
     $t->doTestEdit($title, $text);
     $t->loginAs($t->unprivilegedUser);
     # Do several edits in the different sections of the text.
     $query = array('action' => 'edit', 'title' => $title, 'token' => null);
     $query['section'] = 0;
     $query['text'] = $sections[0] = "New text in zero section\n\n";
     $t->query($query);
     $query['section'] = 2;
     $query['text'] = $sections[2] = "== Second section (#2) ==\nText in second section\n\n";
     $t->query($query);
     $query['section'] = 'new';
     $query['text'] = $sections[] = "== New section ==\nText in the new section";
     $t->query($query);
     $t->fetchSpecial();
     $dbw = wfGetDB(DB_MASTER);
     $row = $dbw->selectRow('moderation', array('mod_text AS text'), array('mod_id' => $t->new_entries[0]->id), __METHOD__);
     $expected_text = join('', $sections);
     $this->assertEquals($expected_text, $row->text, "testEditSections(): Resulting text doesn't match expected");
     # Does PreSaveTransform work when editing sections?
     $t->loginAs($t->unprivilegedUser);
     $query['section'] = 2;
     $query['text'] = "== New section 2 ==\n~~~\n\n";
     $ret = $t->query($query);
     $row = $dbw->selectRow('moderation', array('mod_text AS text'), array('mod_id' => $t->new_entries[0]->id), __METHOD__);
     $this->assertNotRegExp('/~~~/', $row->text, "testEditSections(): Signature (~~~~) hasn't been properly substituted.");
 }
コード例 #8
0
 public function testTokens()
 {
     $t = new ModerationTestsuite();
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit();
     $t->fetchSpecial();
     $entry = $t->new_entries[0];
     $entry->fakeBlockLink();
     # Non-readonly actions require a correct token
     $links = array($entry->approveLink, $entry->approveAllLink, $entry->rejectLink, $entry->rejectAllLink, $entry->blockLink, $entry->unblockLink);
     foreach ($links as $url) {
         $this->assertRegExp('/\\(sessionfailure-title\\)/', $t->noTokenTitle($url));
         /* Double-check that nothing happened */
         $t->fetchSpecial();
         $this->assertCount(0, $t->new_entries);
         $this->assertCount(0, $t->deleted_entries);
         # Would the wrong token work?
         $this->assertRegExp('/\\(sessionfailure-title\\)/', $t->badTokenTitle($url));
         /* Double-check that nothing happened */
         $t->fetchSpecial();
         $this->assertCount(0, $t->new_entries);
         $this->assertCount(0, $t->deleted_entries);
     }
 }
コード例 #9
0
 public function testEditNoChange()
 {
     $t = new ModerationTestsuite();
     $page = 'Test page 1';
     $text = 'This is some ext';
     $t->loginAs($t->automoderated);
     $t->doTestEdit($page, $text);
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit($page, $text);
     # Make zero edit
     $t->fetchSpecial();
     $entry = $t->new_entries[0];
     $error = $t->html->getModerationError($entry->approveLink);
     $this->assertEquals('(edit-no-change)', $error);
 }
コード例 #10
0
 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]);
 }
コード例 #11
0
 /**
 	@covers ModerationActionApprove::prepareApproveHooks()
 	@brief This test verifies that moderator can be NOT automoderated.
 
 	There is no real use for such setup other than debugging,
 	and that's why we don't want to test this manually.
 */
 public function testModeratorNotAutomoderated()
 {
     $t = new ModerationTestsuite();
     $t->loginAs($t->moderatorButNotAutomoderated);
     $t->editViaAPI = true;
     $ret = $t->doTestEdit();
     $t->fetchSpecial();
     /* Edit must be intercepted (this user is not automoderated) */
     $this->assertArrayHasKey('error', $ret);
     $this->assertEquals('edit-hook-aborted', $ret['error']['code']);
     $entry = $t->new_entries[0];
     $this->assertCount(1, $t->new_entries, "testModeratorNotAutomoderated(): One edit was queued for moderation, but number of added entries in Pending folder isn't 1");
     $this->assertCount(0, $t->deleted_entries, "testModeratorNotAutomoderated(): Something was deleted from Pending folder during the queueing");
     $this->assertEquals($t->lastEdit['User'], $entry->user);
     $this->assertEquals($t->lastEdit['Title'], $entry->title);
     /* Must be able to approve the edit (this user is moderator) */
     $t->loginAs($t->moderatorButNotAutomoderated);
     $this->tryToApprove($t, $entry);
     /* ApproveAll must also work */
     $t->doNTestEditsWith($t->moderatorButNotAutomoderated);
     $t->fetchSpecial();
     $t->loginAs($t->moderatorButNotAutomoderated);
     $t->httpGet($t->new_entries[0]->approveAllLink);
     $t->fetchSpecial();
     $this->assertCount(0, $t->new_entries, "testModeratorNotAutomoderated(): Something was added into Pending folder during modaction=approveall");
     $this->assertCount($t->TEST_EDITS_COUNT, $t->deleted_entries, "testModeratorNotAutomoderated(): Several edits were approved, but number of deleted entries in Pending folder doesn't match");
 }