From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- .../phpunit/includes/upload/UploadFromUrlTest.php | 19 +++-- tests/phpunit/includes/upload/UploadStashTest.php | 53 +++++++++---- tests/phpunit/includes/upload/UploadTest.php | 87 +++++++++++----------- 3 files changed, 90 insertions(+), 69 deletions(-) (limited to 'tests/phpunit/includes/upload') diff --git a/tests/phpunit/includes/upload/UploadFromUrlTest.php b/tests/phpunit/includes/upload/UploadFromUrlTest.php index 4722d408..d56cce31 100644 --- a/tests/phpunit/includes/upload/UploadFromUrlTest.php +++ b/tests/phpunit/includes/upload/UploadFromUrlTest.php @@ -20,7 +20,7 @@ class UploadFromUrlTest extends ApiTestCase { } } - protected function doApiRequest( $params, $unused = null, $appendModule = false ) { + protected function doApiRequest( $params, $unused = null, $appendModule = false, $user = null ) { $sessionId = session_id(); session_write_close(); @@ -36,7 +36,10 @@ class UploadFromUrlTest extends ApiTestCase { * Ensure that the job queue is empty before continuing */ public function testClearQueue() { - while ( $job = Job::pop() ) { } + $job = Job::pop(); + while ( $job ) { + $job = Job::pop(); + } $this->assertFalse( $job ); } @@ -73,7 +76,7 @@ class UploadFromUrlTest extends ApiTestCase { * @depends testClearQueue */ public function testSetupUrlDownload( $data ) { - $token = $this->user->editToken(); + $token = $this->user->getEditToken(); $exception = false; try { @@ -147,7 +150,7 @@ class UploadFromUrlTest extends ApiTestCase { * @depends testClearQueue */ public function testAsyncUpload( $data ) { - $token = $this->user->editToken(); + $token = $this->user->getEditToken(); $this->user->addGroup( 'users' ); @@ -166,7 +169,7 @@ class UploadFromUrlTest extends ApiTestCase { * @depends testClearQueue */ public function testAsyncUploadWarning( $data ) { - $token = $this->user->editToken(); + $token = $this->user->getEditToken(); $this->user->addGroup( 'users' ); @@ -197,7 +200,7 @@ class UploadFromUrlTest extends ApiTestCase { * @depends testClearQueue */ public function testSyncDownload( $data ) { - $token = $this->user->editToken(); + $token = $this->user->getEditToken(); $job = Job::pop(); $this->assertFalse( $job, 'Starting with an empty jobqueue' ); @@ -221,7 +224,7 @@ class UploadFromUrlTest extends ApiTestCase { } public function testLeaveMessage() { - $token = $this->user->user->editToken(); + $token = $this->user->user->getEditToken(); $talk = $this->user->user->getTalkPage(); if ( $talk->exists() ) { @@ -274,7 +277,7 @@ class UploadFromUrlTest extends ApiTestCase { return; - /** + /* // Broken until using leavemessage with ignorewarnings is supported $job->run(); diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php index e644a259..c9dbb138 100644 --- a/tests/phpunit/includes/upload/UploadStashTest.php +++ b/tests/phpunit/includes/upload/UploadStashTest.php @@ -1,5 +1,7 @@ bug29408File = dirname( __FILE__ ) . '/bug29408'; - file_put_contents( $this->bug29408File, "\x00" ); - + file_put_contents( $this->bug29408File, "\x00" ); + self::$users = array( 'sysop' => new ApiTestUser( 'Uploadstashtestsysop', 'Upload Stash Test Sysop', - 'upload_stash_test_sysop@sample.com', + 'upload_stash_test_sysop@example.com', array( 'sysop' ) ), 'uploader' => new ApiTestUser( 'Uploadstashtestuser', 'Upload Stash Test User', - 'upload_stash_test_user@sample.com', + 'upload_stash_test_user@example.com', array() ) ); } - /** - * @group Database - */ public function testBug29408() { global $wgUser; $wgUser = self::$users['uploader']->user; - + $repo = RepoGroup::singleton()->getLocalRepo(); $stash = new UploadStash( $repo ); - + // Throws exception caught by PHPUnit on failure $file = $stash->stashFile( $this->bug29408File ); // We'll never reach this point if we hit bug 29408 $this->assertTrue( true, 'Unrecognized file without extension' ); - + $stash->removeFile( $file->getFileKey() ); } - + + public function testValidRequest() { + $request = new FauxRequest( array( 'wpFileKey' => 'foo') ); + $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpFileKey' ); + + $request = new FauxRequest( array( 'wpSessionKey' => 'foo') ); + $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpSessionKey' ); + + $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') ); + $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpFileKey' ); + + $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') ); + $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpSessionKey' ); + + $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo') ); + $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check key precedence' ); + } + public function tearDown() { parent::tearDown(); - - unlink( $this->bug29408File . "." ); - + + if( file_exists( $this->bug29408File . "." ) ) { + unlink( $this->bug29408File . "." ); + } + + if( file_exists( $this->bug29408File ) ) { + unlink( $this->bug29408File ); + } } } diff --git a/tests/phpunit/includes/upload/UploadTest.php b/tests/phpunit/includes/upload/UploadTest.php index 69c29032..4293d23b 100644 --- a/tests/phpunit/includes/upload/UploadTest.php +++ b/tests/phpunit/includes/upload/UploadTest.php @@ -20,53 +20,14 @@ class UploadTest extends MediaWikiTestCase { $wgHooks = $this->hooks; } - /** - * Test various forms of valid and invalid titles that can be supplied. - */ - public function testTitleValidation() { - - - /* Test a valid title */ - $this->assertUploadTitleAndCode( 'ValidTitle.jpg', - 'ValidTitle.jpg', UploadBase::OK, - 'upload valid title' ); - - /* A title with a slash */ - $this->assertUploadTitleAndCode( 'A/B.jpg', - 'B.jpg', UploadBase::OK, - 'upload title with slash' ); - - /* A title with illegal char */ - $this->assertUploadTitleAndCode( 'A:B.jpg', - 'A-B.jpg', UploadBase::OK, - 'upload title with colon' ); - - /* Stripping leading File: prefix */ - $this->assertUploadTitleAndCode( 'File:C.jpg', - 'C.jpg', UploadBase::OK, - 'upload title with File prefix' ); - /* Test illegal suggested title (r94601) */ - $this->assertUploadTitleAndCode( '%281%29.JPG', - null, UploadBase::ILLEGAL_FILENAME, - 'illegal title for upload' ); - - /* A title without extension */ - $this->assertUploadTitleAndCode( 'A', - null, UploadBase::FILETYPE_MISSING, - 'upload title without extension' ); - - /* A title with no basename */ - $this->assertUploadTitleAndCode( '.jpg', - null, UploadBase::MIN_LENGTH_PARTNAME, - 'upload title without basename' ); - - } /** - * Helper function for testTitleValidation. First checks the return code - * of UploadBase::getTitle() and then the actual returned titl + * First checks the return code + * of UploadBase::getTitle() and then the actual returned title + * + * @dataProvider dataTestTitleValidation */ - private function assertUploadTitleAndCode( $srcFilename, $dstFilename, $code, $msg ) { + public function testTitleValidation( $srcFilename, $dstFilename, $code, $msg ) { /* Check the result code */ $this->assertEquals( $code, $this->upload->testTitleValidation( $srcFilename ), @@ -79,6 +40,41 @@ class UploadTest extends MediaWikiTestCase { "$msg text" ); } } + + /** + * Test various forms of valid and invalid titles that can be supplied. + */ + public function dataTestTitleValidation() { + return array( + /* Test a valid title */ + array( 'ValidTitle.jpg', 'ValidTitle.jpg', UploadBase::OK, + 'upload valid title' ), + /* A title with a slash */ + array( 'A/B.jpg', 'B.jpg', UploadBase::OK, + 'upload title with slash' ), + /* A title with illegal char */ + array( 'A:B.jpg', 'A-B.jpg', UploadBase::OK, + 'upload title with colon' ), + /* Stripping leading File: prefix */ + array( 'File:C.jpg', 'C.jpg', UploadBase::OK, + 'upload title with File prefix' ), + /* Test illegal suggested title (r94601) */ + array( '%281%29.JPG', null, UploadBase::ILLEGAL_FILENAME, + 'illegal title for upload' ), + /* A title without extension */ + array( 'A', null, UploadBase::FILETYPE_MISSING, + 'upload title without extension' ), + /* A title with no basename */ + array( '.jpg', null, UploadBase::MIN_LENGTH_PARTNAME, + 'upload title without basename' ), + /* A title that is longer than 255 bytes */ + array( str_repeat( 'a', 255 ) . '.jpg', null, UploadBase::FILENAME_TOO_LONG, + 'upload title longer than 255 bytes' ), + /* A title that is longer than 240 bytes */ + array( str_repeat( 'a', 240 ) . '.jpg', null, UploadBase::FILENAME_TOO_LONG, + 'upload title longer than 240 bytes' ), + ); + } /** * Test the upload verification functions @@ -104,7 +100,7 @@ class UploadTest extends MediaWikiTestCase { } /** - * test uploading a 100 bytes file with wgMaxUploadSize = 100 + * test uploading a 100 bytes file with $wgMaxUploadSize = 100 * * This method should be abstracted so we can test different settings. */ @@ -134,6 +130,7 @@ class UploadTestHandler extends UploadBase { public function testTitleValidation( $name ) { $this->mTitle = false; $this->mDesiredDestName = $name; + $this->mTitleError = UploadBase::OK; $this->getTitle(); return $this->mTitleError; } -- cgit v1.2.2