r70162 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70161‎ | r70162 | r70163 >
Date:18:39, 29 July 2010
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
Fix UploadFromUrl test cases, UploadFromUrlJob::run return value, and disable broken features in UploadFromUrlJob
* Use a more specific filename in UploadFromUrlTest and fix some assertions.
* Return boolean from UploadFromUrlJob::run
* Force ignorewarnings and leavemessage in UploadFromUrlJob
Modified paths:
  • /trunk/phase3/includes/job/UploadFromUrlJob.php (modified) (history)
  • /trunk/phase3/maintenance/tests/UploadFromUrlTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/UploadFromUrlTest.php
@@ -112,7 +112,7 @@
113113 $this->doApiRequest( array(
114114 'action' => 'upload',
115115 'url' => 'http://www.example.com/test.png',
116 - 'filename' => 'Test.png',
 116+ 'filename' => 'UploadFromUrlTest.png',
117117 'token' => $token,
118118 ), $data );
119119 } catch ( UsageException $e ) {
@@ -128,18 +128,14 @@
129129 'action' => 'upload',
130130 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
131131 'asyncdownload' => 1,
132 - 'filename' => 'Test.png',
 132+ 'filename' => 'UploadFromUrlTest.png',
133133 'token' => $token,
134134 ), $data );
135135
136 - $this->assertTrue( $data[0]['upload']['queued'], 'Job added' );
137 -
 136+ $this->assertEquals( $data[0]['upload']['result'], 'Queued', 'Queued upload' );
 137+
138138 $job = Job::pop();
139 - $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ),
140 - "Got Job Object" );
141 -
142 - $job = Job::pop_type( 'upload' );
143 - $this->assertFalse( $job );
 139+ $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), 'Queued upload inserted' );
144140 }
145141
146142 /**
@@ -153,7 +149,7 @@
154150 $wgUser->addGroup( 'users' );
155151 $data = $this->doApiRequest( array(
156152 'action' => 'upload',
157 - 'filename' => 'Test.png',
 153+ 'filename' => 'UploadFromUrlTest.png',
158154 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
159155 'asyncdownload' => 1,
160156 'token' => $token,
@@ -164,7 +160,7 @@
165161
166162 $status = $job->run();
167163
168 - $this->assertTrue( $status->isOk() );
 164+ $this->assertTrue( $status );
169165
170166 return $data;
171167 }
@@ -178,14 +174,14 @@
179175 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX;
180176
181177 $job = Job::pop();
182 - $this->assertFalse( $job );
 178+ $this->assertFalse( $job, 'Starting with an empty jobqueue' );
183179
184 - $this->deleteFile( 'Test.png' );
 180+ //$this->deleteFile( 'UploadFromUrlTest.png' );
185181
186182 $wgUser->addGroup( 'users' );
187183 $data = $this->doApiRequest( array(
188184 'action' => 'upload',
189 - 'filename' => 'Test.png',
 185+ 'filename' => 'UploadFromUrlTest.png',
190186 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
191187 'ignorewarnings' => true,
192188 'token' => $token,
@@ -203,18 +199,17 @@
204200 * @depends testDoDownload
205201 */
206202 function testVerifyDownload( $data ) {
207 - $t = Title::newFromText( "Test.png", NS_FILE );
 203+ $t = Title::newFromText( "UploadFromUrlTest.png", NS_FILE );
208204
209205 $this->assertTrue( $t->exists() );
210206
211 - $this->deleteFile( 'Test.png' );
 207+ $this->deleteFile( 'UploadFromUrlTest.png' );
212208 }
213209
214210 /**
215211 *
216212 */
217213 function deleteFile( $name ) {
218 -
219214 $t = Title::newFromText( $name, NS_FILE );
220215 $this->assertTrue($t->exists(), "File '$name' exists");
221216
Index: trunk/phase3/includes/job/UploadFromUrlJob.php
@@ -18,6 +18,14 @@
1919 }
2020
2121 public function run() {
 22+ # Until we find a way to store data in sessions, set leaveMessage to
 23+ # true unconditionally
 24+ $this->params['leaveMessage'] = true;
 25+ # Similar for ignorewarnings. This is not really a good fallback, but
 26+ # there is no easy way to get a wikitext formatted warning message to
 27+ # show to the user
 28+ $this->params['ignoreWarnings'] = true;
 29+
2230 # Initialize this object and the upload object
2331 $this->upload = new UploadFromUrl();
2432 $this->upload->initialize(
@@ -31,7 +39,7 @@
3240 $status = $this->upload->fetchFile();
3341 if ( !$status->isOk() ) {
3442 $this->leaveMessage( $status );
35 - return;
 43+ return true;
3644 }
3745
3846 # Verify upload
@@ -39,13 +47,13 @@
4048 if ( $result['status'] != UploadBase::OK ) {
4149 $status = $this->upload->convertVerifyErrorToStatus( $result );
4250 $this->leaveMessage( $status );
43 - return;
 51+ return true;
4452 }
4553
4654 # Check warnings
4755 if ( !$this->params['ignoreWarnings'] ) {
4856 $warnings = $this->upload->checkWarnings();
49 - if ( $warnings ) {
 57+ if ( $warnings ) {
5058 if ( $this->params['leaveMessage'] ) {
5159 $this->user->leaveUserMessage(
5260 wfMsg( 'upload-warning-subj' ),
@@ -59,7 +67,7 @@
6068 }
6169
6270 // FIXME: stash in session
63 - return;
 71+ return true;
6472 }
6573 }
6674
@@ -71,6 +79,8 @@
7280 $this->user
7381 );
7482 $this->leaveMessage( $status );
 83+ return true;
 84+
7585 }
7686
7787 /**

Comments

#Comment by MarkAHershberger (talk | contribs)   01:22, 13 January 2011

The bit that starts with this comment:

+		# Until we find a way to store data in sessions, set leaveMessage to
+		# true unconditionally

is handled in r72475.

This looks good overall.

Status & tagging log