77fd099004e55604e5ff8fce18918ab24e0377e7
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;
18 $wgEnableUploads = true;
20 $wgLocalFileRepo = array(
21 'class' => 'LocalRepo',
23 'directory' => 'test-repo',
24 'url' => 'http://example.com/images',
26 'transformVia404' => false,
29 ini_set( 'log_errors', 1 );
30 ini_set( 'error_reporting', 1 );
31 ini_set( 'display_errors', 1 );
34 function doApiRequest( $params, $data = null ) {
35 $session = isset( $data[2] ) ?
$data[2] : array();
38 $req = new FauxRequest( $params, true, $session );
39 $module = new ApiMain( $req, true );
42 return array( $module->getResultData(), $req, $_SESSION );
45 function testClearQueue() {
46 while ( $job = Job
::pop() ) {}
47 $this->assertFalse($job);
50 function testLogin() {
51 $data = $this->doApiRequest( array(
53 'lgname' => self
::$userName,
54 'lgpassword' => self
::$passWord ) );
55 $this->assertArrayHasKey( "login", $data[0] );
56 $this->assertArrayHasKey( "result", $data[0]['login'] );
57 $this->assertEquals( "NeedToken", $data[0]['login']['result'] );
58 $token = $data[0]['login']['token'];
60 $data = $this->doApiRequest( array(
63 "lgname" => self
::$userName,
64 "lgpassword" => self
::$passWord ) );
66 $this->assertArrayHasKey( "login", $data[0] );
67 $this->assertArrayHasKey( "result", $data[0]['login'] );
68 $this->assertEquals( "Success", $data[0]['login']['result'] );
69 $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] );
77 function testSetupUrlDownload( $data ) {
79 $wgUser = User
::newFromName( self
::$userName );
81 $data[2]['wsEditToken'] = $data[2]['wsToken'];
82 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX
;
86 $this->doApiRequest( array(
89 } catch ( UsageException
$e ) {
91 $this->assertEquals( "The token parameter must be set", $e->getMessage() );
93 $this->assertTrue( $exception, "Got exception" );
97 $this->doApiRequest( array(
101 } catch ( UsageException
$e ) {
103 $this->assertEquals( "One of the parameters sessionkey, file, url is required",
106 $this->assertTrue( $exception, "Got exception" );
110 $this->doApiRequest( array(
111 'action' => 'upload',
112 'url' => 'http://www.example.com/test.png',
115 } catch ( UsageException
$e ) {
117 $this->assertEquals( "The filename parameter must be set", $e->getMessage() );
119 $this->assertTrue( $exception, "Got exception" );
121 $wgUser->removeGroup('sysop');
124 $this->doApiRequest( array(
125 'action' => 'upload',
126 'url' => 'http://www.example.com/test.png',
127 'filename' => 'Test.png',
130 } catch ( UsageException
$e ) {
132 $this->assertEquals( "Permission denied", $e->getMessage() );
134 $this->assertTrue( $exception, "Got exception" );
136 $wgUser->addGroup('*');
137 $wgUser->addGroup('sysop');
139 $data = $this->doApiRequest( array(
140 'action' => 'upload',
141 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
142 'filename' => 'Test.png',
146 $this->assertThat( $data[0]['upload'], $this->isInstanceOf( 'Status' ),
147 "Got Status Object" );
148 $this->assertTrue( $data[0]['upload']->isOk(), 'Job added');
151 $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ),
154 $job = Job
::pop_type( 'upload' );
155 $this->assertFalse( $job );
161 function testDoDownload( $data ) {
163 $data[2]['wsEditToken'] = $data[2]['wsToken'];
164 $token = md5( $data[2]['wsToken'] ) . EDIT_TOKEN_SUFFIX
;
166 $wgUser->addGroup('users');
167 $data = $this->doApiRequest( array(
168 'action' => 'upload',
169 'filename' => 'Test.png',
170 'url' => 'http://bits.wikimedia.org/skins-1.5/common/images/poweredby_mediawiki_88x31.png',
175 $this->assertEquals( 'UploadFromUrlJob', get_class($job) );
177 $status = $job->run();
178 $this->assertTrue( $status->isOk() );
184 * @depends testDoDownload
186 function testVerifyDownload( $data ) {
187 $t = Title
::newFromText("Test.png", NS_FILE
);
189 $this->assertTrue($t->exists());