4 public function handleOutput() { }
5 public function purgeRedundantText() { }
8 class UploadFromUrlTest
extends ApiTestSetup
{
11 global $wgEnableUploads, $wgAllowCopyUploads;
13 $wgEnableUploads = true;
14 $wgAllowCopyUploads = true;
17 ini_set( 'log_errors', 1 );
18 ini_set( 'error_reporting', 1 );
19 ini_set( 'display_errors', 1 );
22 function doApiRequest( $params, $data = null ) {
23 $session = isset( $data[2] ) ?
$data[2] : array();
26 $req = new FauxRequest( $params, true, $session );
27 $module = new ApiMain( $req, true );
30 return array( $module->getResultData(), $req, $_SESSION );
33 function testClearQueue() {
34 while ( $job = Job
::pop() ) { }
35 $this->assertFalse( $job );
38 function testLogin() {
39 $data = $this->doApiRequest( array(
41 'lgname' => self
::$userName,
42 'lgpassword' => self
::$passWord ) );
43 $this->assertArrayHasKey( "login", $data[0] );
44 $this->assertArrayHasKey( "result", $data[0]['login'] );
45 $this->assertEquals( "NeedToken", $data[0]['login']['result'] );
46 $token = $data[0]['login']['token'];
48 $data = $this->doApiRequest( array(
51 "lgname" => self
::$userName,
52 "lgpassword" => self
::$passWord ) );
54 $this->assertArrayHasKey( "login", $data[0] );
55 $this->assertArrayHasKey( "result", $data[0]['login'] );
56 $this->assertEquals( "Success", $data[0]['login']['result'] );
57 $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] );
65 function testSetupUrlDownload( $data ) {
67 $wgUser = User
::newFromName( self
::$userName );
69 $data[2]['wsEditToken'] = $data[2]['wsToken'];
70 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX
;
74 $this->doApiRequest( array(
77 } catch ( UsageException
$e ) {
79 $this->assertEquals( "The token parameter must be set", $e->getMessage() );
81 $this->assertTrue( $exception, "Got exception" );
85 $this->doApiRequest( array(
89 } catch ( UsageException
$e ) {
91 $this->assertEquals( "One of the parameters sessionkey, file, url is required",
94 $this->assertTrue( $exception, "Got exception" );
98 $this->doApiRequest( array(
100 'url' => 'http://www.example.com/test.png',
103 } catch ( UsageException
$e ) {
105 $this->assertEquals( "The filename parameter must be set", $e->getMessage() );
107 $this->assertTrue( $exception, "Got exception" );
109 $wgUser->removeGroup( 'sysop' );
112 $this->doApiRequest( array(
113 'action' => 'upload',
114 'url' => 'http://www.example.com/test.png',
115 'filename' => 'Test.png',
118 } catch ( UsageException
$e ) {
120 $this->assertEquals( "Permission denied", $e->getMessage() );
122 $this->assertTrue( $exception, "Got exception" );
124 $wgUser->addGroup( '*' );
125 $wgUser->addGroup( 'sysop' );
127 $data = $this->doApiRequest( array(
128 'action' => 'upload',
129 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
130 'asyncdownload' => 1,
131 'filename' => 'Test.png',
135 $this->assertTrue( $data[0]['upload']['queued'], 'Job added' );
138 $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ),
141 $job = Job
::pop_type( 'upload' );
142 $this->assertFalse( $job );
148 function testDoDownload( $data ) {
150 $data[2]['wsEditToken'] = $data[2]['wsToken'];
151 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX
;
153 $wgUser->addGroup( 'users' );
154 $data = $this->doApiRequest( array(
155 'action' => 'upload',
156 'filename' => 'Test.png',
157 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
158 'asyncdownload' => 1,
163 $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
165 $status = $job->run();
167 $this->assertTrue( $status->isOk() );
175 function testSyncDownload( $data ) {
177 $data[2]['wsEditToken'] = $data[2]['wsToken'];
178 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX
;
181 $this->assertFalse( $job );
183 $this->deleteFile( 'Test.png' );
185 $wgUser->addGroup( 'users' );
186 $data = $this->doApiRequest( array(
187 'action' => 'upload',
188 'filename' => 'Test.png',
189 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
190 'ignorewarnings' => true,
195 $this->assertFalse( $job );
197 $this->assertEquals( 'Success', $data[0]['upload']['result'] );
203 * @depends testDoDownload
205 function testVerifyDownload( $data ) {
206 $t = Title
::newFromText( "Test.png", NS_FILE
);
208 $this->assertTrue( $t->exists() );
210 $this->deleteFile( 'Test.png' );
216 function deleteFile( $name ) {
218 $t = Title
::newFromText( $name, NS_FILE
);
219 $this->assertTrue($t->exists(), "File '$name' exists");
221 if ( $t->exists() ) {
222 $file = wfFindFile( $name, array( 'ignoreRedirect' => true ) );
224 $status = FileDeleteForm
::doDelete( $t, $file, $empty, "none", true );
225 $a = new Article ( $t );
226 $a->doDeleteArticle( "testing" );
228 $t = Title
::newFromText( $name, NS_FILE
);
230 $this->assertFalse($t->exists(), "File '$name' was deleted");