コード例 #1
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.");
 }
コード例 #2
0
 /**
 	@covers ModerationApproveHook
 */
 public function testReupload()
 {
     $t = new ModerationTestsuite();
     $title = "Test image 1.png";
     # Upload the image first
     $t->loginAs($t->automoderated);
     $t->doTestUpload($title, __DIR__ . "/../resources/image640x50.png", "Text 1");
     # Now queue reupload for moderation
     $t->loginAs($t->unprivilegedUser);
     $error = $t->doTestUpload($title, __DIR__ . "/../resources/image100x100.png", "Text 2");
     $t->fetchSpecial();
     # Was the reupload queued for moderation?
     $this->assertEquals('(moderation-image-queued)', $error);
     # Is the data on Special:Moderation correct?
     $entry = $t->new_entries[0];
     $this->assertCount(1, $t->new_entries, "testReupload(): One upload was queued for moderation, but number of added entries in Pending folder isn't 1");
     $this->assertCount(0, $t->deleted_entries, "testReupload(): Something was deleted from Pending folder during the queueing");
     $this->assertEquals($t->lastEdit['User'], $entry->user);
     $this->assertEquals($t->lastEdit['Title'], $entry->title);
     # Does modaction=show display (moderation-diff-reupload) message?
     $this->assertRegExp('/\\(moderation-diff-reupload\\)/', $t->html->getMainText($entry->showLink), "testReupload(): (moderation-diff-reupload) not found in the output of modaction=show");
     # Can we approve this reupload?
     $this->assertNotNull($entry->approveLink, "testReupload(): Approve link not found");
     $t->html->loadFromURL($entry->approveLink);
     $this->assertRegExp('/\\(moderation-approved-ok: 1\\)/', $t->html->getMainText(), "testReupload(): Result page doesn't contain (moderation-approved-ok: 1)");
     # Has the file been reuploaded after the approval?
     $ret = $t->query(array('action' => 'query', 'prop' => 'imageinfo', 'iilimit' => 1, 'iiprop' => 'user|timestamp|comment|size|url|sha1', 'titles' => $entry->title));
     $ret_page = array_shift($ret['query']['pages']);
     $ii = $ret_page['imageinfo'][0];
     $this->assertEquals($t->lastEdit['User'], $ii['user']);
     $this->assertEquals($t->lastEdit['Text'], $ii['comment']);
     $this->assertEquals($t->lastEdit['SHA1'], $ii['sha1']);
     # Check image page history: performUpload(... $user) mistakenly
     # tags image reuploads as made by moderator (and not $user).
     # Was that fixed? (via ModerationApproveHook class)
     $ret = $t->query(array('action' => 'query', 'prop' => 'revisions', 'rvlimit' => 2, 'rvprop' => 'user|timestamp|comment|content|ids', 'titles' => $entry->title));
     # Because API orders entries by timestamp (up to seconds), and
     # it's likely that two uploads we just made will have the same
     # timestamp, they may be ordered incorrectly ([0] not being the
     # most recent). So find the entry with 'parentid' referring to
     # the other entry.
     $ret_page = array_shift($ret['query']['pages']);
     $rev1 = $ret_page['revisions'][0];
     $rev2 = $ret_page['revisions'][1];
     # Make $rev1 the most recent edit
     if ($rev2['parentid'] == $rev1['revid']) {
         $tmp = $rev1;
         $rev1 = $rev2;
         $rev2 = $tmp;
     }
     $this->assertEquals($rev2['revid'], $rev1['parentid'], "testReupload(): parentid of new revision doesn't match revid of the previous revision");
     $this->assertNotEquals($t->moderator->getName(), $rev1['user'], "testReupload(): Image reupload was attributed to the moderator who approved it (instead of the user who made the reupload)");
     $this->assertEquals($t->lastEdit['User'], $rev1['user'], "testReupload(): Image reupload wasn't attributed to the user who made it");
 }