1e181543a8029e4ef0e0ccfcb468e863b0f379bb
4 require_once( "ApiSetup.php" );
5 require_once( dirname( dirname( __FILE__
) ) . "/deleteArchivedFiles.inc" );
6 require_once( dirname( dirname( __FILE__
) ) . "/deleteArchivedRevisions.inc" );
9 public function handleOutput() { }
10 public function purgeRedundantText() { }
13 class UploadFromUrlTest
extends ApiSetup
{
16 global $wgEnableUploads, $wgLocalFileRepo, $wgAllowCopyUploads;
18 $wgEnableUploads = true;
19 $wgAllowCopyUploads = true;
22 ini_set( 'log_errors', 1 );
23 ini_set( 'error_reporting', 1 );
24 ini_set( 'display_errors', 1 );
27 function doApiRequest( $params, $data = null ) {
28 $session = isset( $data[2] ) ?
$data[2] : array();
31 $req = new FauxRequest( $params, true, $session );
32 $module = new ApiMain( $req, true );
35 return array( $module->getResultData(), $req, $_SESSION );
38 function testClearQueue() {
39 while ( $job = Job
::pop() ) { }
40 $this->assertFalse( $job );
43 function testLogin() {
44 $data = $this->doApiRequest( array(
46 'lgname' => self
::$userName,
47 'lgpassword' => self
::$passWord ) );
48 $this->assertArrayHasKey( "login", $data[0] );
49 $this->assertArrayHasKey( "result", $data[0]['login'] );
50 $this->assertEquals( "NeedToken", $data[0]['login']['result'] );
51 $token = $data[0]['login']['token'];
53 $data = $this->doApiRequest( array(
56 "lgname" => self
::$userName,
57 "lgpassword" => self
::$passWord ) );
59 $this->assertArrayHasKey( "login", $data[0] );
60 $this->assertArrayHasKey( "result", $data[0]['login'] );
61 $this->assertEquals( "Success", $data[0]['login']['result'] );
62 $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] );
70 function testSetupUrlDownload( $data ) {
72 $wgUser = User
::newFromName( self
::$userName );
74 $data[2]['wsEditToken'] = $data[2]['wsToken'];
75 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX
;
79 $this->doApiRequest( array(
82 } catch ( UsageException
$e ) {
84 $this->assertEquals( "The token parameter must be set", $e->getMessage() );
86 $this->assertTrue( $exception, "Got exception" );
90 $this->doApiRequest( array(
94 } catch ( UsageException
$e ) {
96 $this->assertEquals( "One of the parameters sessionkey, file, url is required",
99 $this->assertTrue( $exception, "Got exception" );
103 $this->doApiRequest( array(
104 'action' => 'upload',
105 'url' => 'http://www.example.com/test.png',
108 } catch ( UsageException
$e ) {
110 $this->assertEquals( "The filename parameter must be set", $e->getMessage() );
112 $this->assertTrue( $exception, "Got exception" );
114 $wgUser->removeGroup( 'sysop' );
117 $this->doApiRequest( array(
118 'action' => 'upload',
119 'url' => 'http://www.example.com/test.png',
120 'filename' => 'Test.png',
123 } catch ( UsageException
$e ) {
125 $this->assertEquals( "Permission denied", $e->getMessage() );
127 $this->assertTrue( $exception, "Got exception" );
129 $wgUser->addGroup( '*' );
130 $wgUser->addGroup( 'sysop' );
132 $data = $this->doApiRequest( array(
133 'action' => 'upload',
134 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
135 'asyncdownload' => 1,
136 'filename' => 'Test.png',
140 $this->assertTrue( $data[0]['upload']['queued'], 'Job added' );
143 $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ),
146 $job = Job
::pop_type( 'upload' );
147 $this->assertFalse( $job );
153 function testDoDownload( $data ) {
155 $data[2]['wsEditToken'] = $data[2]['wsToken'];
156 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX
;
158 $wgUser->addGroup( 'users' );
159 $data = $this->doApiRequest( array(
160 'action' => 'upload',
161 'filename' => 'Test.png',
162 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
163 'asyncdownload' => 1,
168 $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
170 $status = $job->run();
172 $this->assertTrue( $status->isOk() );
180 function testSyncDownload( $data ) {
182 $data[2]['wsEditToken'] = $data[2]['wsToken'];
183 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX
;
186 $this->assertFalse( $job );
188 self
::deleteFile( 'Test.png' );
190 $wgUser->addGroup( 'users' );
191 $data = $this->doApiRequest( array(
192 'action' => 'upload',
193 'filename' => 'Test.png',
194 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
195 'ignorewarnings' => true,
200 $this->assertFalse( $job );
202 $this->assertEquals( 'Success', $data[0]['upload']['result'] );
208 * @depends testDoDownload
210 function testVerifyDownload( $data ) {
211 $t = Title
::newFromText( "Test.png", NS_FILE
);
213 $this->assertTrue( $t->exists() );
215 self
::deleteFile( 'Test.png' );
221 function deleteFile( $name ) {
223 $t = Title
::newFromText( $name, NS_FILE
);
224 $this->assertTrue($t->exists(), "File '$name' exists");
226 if ( $t->exists() ) {
227 $file = wfFindFile( $name, array( 'ignoreRedirect' => true ) );
229 $status = FileDeleteForm
::doDelete( $t, $file, $empty, "none", true );
230 $a = new Article ( $t );
231 $a->doDeleteArticle( "testing" );
233 $t = Title
::newFromText( $name, NS_FILE
);
235 $this->assertFalse($t->exists(), "File '$name' was deleted");