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");
 }
 /**
 	@covers ModerationActionShowImage
 	@requires extension curl
 	@note Only cURL version of MWHttpRequest supports uploads.
 */
 public function testShowUpload()
 {
     $t = new ModerationTestsuite();
     /*
     	When testing thumbnails, we check two images -
     	one smaller than thumbnail's width, one larger,
     	because they are handled differently.
     
     	First test is on image640x50.png (large image),
     	second on image100x100.png (smaller image).
     */
     $t->loginAs($t->unprivilegedUser);
     $error = $t->doTestUpload("Test image 1.png", __DIR__ . "/../resources/image640x50.png", "");
     $t->fetchSpecial();
     $entry = $t->new_entries[0];
     $url = $entry->showLink;
     $this->assertNotNull($url, "testShowUpload(): Show link not found");
     $title = $t->html->getTitle($url);
     $this->assertRegExp('/\\(difference-title: ' . $t->lastEdit['Title'] . '\\)/', $title, "testShowUpload(): Difference page has a wrong HTML title");
     $this->assertRegExp('/\\(moderation-diff-upload-notext\\)/', $t->html->getMainText(), "testShowUpload(): File was uploaded without description, but (moderation-diff-upload-notext) is not shown");
     # Is the image thumbnail displayed on the difference page?
     $images = $t->html->getElementsByTagName('img');
     $thumb = null;
     $src = null;
     foreach ($images as $img) {
         $src = $img->getAttribute('src');
         if (strpos($src, 'modaction=showimg') !== false) {
             $thumb = $img;
             break;
         }
     }
     $this->assertNotNull($thumb, "testShowUpload(): Thumbnail image not found");
     $this->assertRegExp('/thumb=1/', $src, "testShowUpload(): Thumbnail image URL doesn't contain thumb=1");
     # Is the image thumbnail inside the link to the full image?
     $link = $thumb->parentNode;
     $this->assertEquals('a', $link->nodeName, "testShowUpload(): Thumbnail image isn't encased in <a> tag");
     $href = $link->getAttribute('href');
     $this->assertEquals($entry->expectedShowImgLink(), $href, "testShowUpload(): Full image URL doesn't match expected URL");
     $nonthumb_src = str_replace('&thumb=1', '', $src);
     $this->assertEquals($nonthumb_src, $href, "testShowUpload(): Full image URL doesn't match thumbnail image URL without '&thumb=1'");
     $this->assertNotRegExp('/token=/', $href, "testShowUpload(): Token was found in the read-only ShowImage link");
     # Check the full image
     $req = $t->httpGet($href);
     $this->assertEquals('image/png', $req->getResponseHeader('Content-Type'), "testShowUpload(): Wrong Content-Type header from modaction=showimg");
     $this->assertEquals($t->lastEdit['SHA1'], sha1($req->getContent()), "testShowUpload(): Checksum of image downloaded via modaction=showimg doesn't match the checksum of original image");
     $this->assertEquals("inline;filename*=UTF-8''Test%20image%201.png", $req->getResponseHeader('Content-Disposition'), "testShowUpload(640x50): Wrong Content-Disposition header from modaction=showimg");
     # Check the thumbnail
     $req = $t->httpGet($src);
     # Content-type check will catch HTML errors from StreamFile
     $this->assertRegExp('/^image\\//', $req->getResponseHeader('Content-Type'), "testShowUpload(640x50): Wrong Content-Type header from modaction=showimg&thumb=1");
     $this->assertEquals("inline;filename*=UTF-8''" . ModerationActionShowImage::THUMB_WIDTH . "px-Test%20image%201.png", $req->getResponseHeader('Content-Disposition'), "testShowUpload(640x50): Wrong Content-Disposition header from modaction=showimg&thumb=1");
     list($original_width, $original_height) = getimagesize($t->lastEdit['Source']);
     list($width, $height) = getImageSizeFromString($req->getContent());
     $orig_ratio = round($original_width / $original_height, 2);
     $ratio = round($width / $height, 2);
     # As this image is larger than THUMB_WIDTH,
     # its thumbnail must be exactly THUMB_WIDTH wide.
     $this->assertEquals(ModerationActionShowImage::THUMB_WIDTH, $width, "testShowUpload(): Thumbnail's width doesn't match expected");
     $this->assertEquals($orig_ratio, $ratio, "testShowUpload(): Thumbnail's ratio doesn't match original");
     # Check the thumbnail of image smaller than THUMB_WIDTH.
     # Its thumbnail must be exactly the same size as original image.
     $t->loginAs($t->unprivilegedUser);
     $t->doTestUpload("Test image 2.png", __DIR__ . "/../resources/image100x100.png", "Non-empty image description");
     $t->fetchSpecial();
     $req = $t->httpGet($t->new_entries[0]->expectedShowImgLink());
     list($original_width, $original_height) = getimagesize($t->lastEdit['Source']);
     list($width, $height) = getImageSizeFromString($req->getContent());
     $this->assertRegExp('/^image\\//', $req->getResponseHeader('Content-Type'), "testShowUpload(100x100): Wrong Content-Type header from modaction=showimg&thumb=1");
     # No "px-" in the filename, because this thumbnail isn't different from the original file
     $this->assertEquals("inline;filename*=UTF-8''Test%20image%202.png", $req->getResponseHeader('Content-Disposition'), "testShowUpload(100x100): Wrong Content-Disposition header from modaction=showimg&thumb=1");
     $this->assertEquals($original_width, $width, "testShowUpload(): Original image is smaller than THUMB_WIDTH, but thumbnail width doesn't match the original width");
     $this->assertEquals($original_height, $height, "testShowUpload(): Original image is smaller than THUMB_WIDTH, but thumbnail height doesn't match the original height");
     # Ensure absence of (moderation-diff-upload-notext)
     $this->assertNotRegExp('/\\(moderation-diff-upload-notext\\)/', $t->html->getMainText($t->new_entries[0]->showLink), "testShowUpload(): File was uploaded with description, but (moderation-diff-upload-notext) is shown");
 }
 public function testApproveNotExpiredRejected()
 {
     global $wgModerationTimeToOverrideRejection;
     $t = new ModerationTestsuite();
     # Rejected edits can only be approved if they are no older
     # than $wgModerationTimeToOverrideRejection.
     $t->loginAs($t->unprivilegedUser);
     $t->doTestEdit();
     $t->fetchSpecial();
     $id = $t->new_entries[0]->id;
     $t->httpGet($t->new_entries[0]->rejectLink);
     /* Modify mod_timestamp to make this edit 1 hour older than
     			allowed by $wgModerationTimeToOverrideRejection. */
     $ts = new MWTimestamp(time());
     $ts->timestamp->modify('-' . intval($wgModerationTimeToOverrideRejection) . ' seconds');
     $ts->timestamp->modify('-1 hour');
     /* Should NOT be approvable */
     $dbw = wfGetDB(DB_MASTER);
     $dbw->update('moderation', array('mod_timestamp' => $ts->getTimestamp(TS_MW)), array('mod_id' => $id), __METHOD__);
     $t->fetchSpecial('rejected');
     $entry = $t->new_entries[0];
     $this->assertNull($entry->approveLink, "testApproveNotExpiredRejected(): Approve link found for edit that was rejected more than {$wgModerationTimeToOverrideRejection} seconds ago");
     # Ensure that usual approve URL doesn't work:
     $error = $t->html->getModerationError($entry->expectedActionLink('approve'));
     $this->assertEquals('(moderation-rejected-long-ago)', $error, "testApproveNotExpiredRejected(): No expected error from modaction=approve");
     /* Make the edit less ancient
     			than $wgModerationTimeToOverrideRejection ago */
     $ts->timestamp->modify('+2 hour');
     /* Should be approvable */
     $dbw = wfGetDB(DB_MASTER);
     $dbw->update('moderation', array('mod_timestamp' => $ts->getTimestamp(TS_MW)), array('mod_id' => $id), __METHOD__);
     $t->assumeFolderIsEmpty('rejected');
     $t->fetchSpecial('rejected');
     $entry = $t->new_entries[0];
     $this->assertNotNull($entry->approveLink, "testApproveNotExpiredRejected(): Approve link is missing for edit that was rejected less than {$wgModerationTimeToOverrideRejection} seconds ago");
     $this->tryToApprove($t, $entry);
 }