2011-06-18 14:56:14 +00:00
|
|
|
<?php
|
2011-07-26 23:39:48 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2011-06-18 14:56:14 +00:00
|
|
|
class UploadStashTest extends MediaWikiTestCase {
|
2011-07-12 21:11:43 +00:00
|
|
|
/**
|
|
|
|
|
* @var Array of UploadStashTestUser
|
|
|
|
|
*/
|
|
|
|
|
public static $users;
|
|
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
public function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
// Setup a file for bug 29408
|
|
|
|
|
$this->bug29408File = dirname( __FILE__ ) . '/bug29408';
|
2011-06-21 15:06:59 +00:00
|
|
|
file_put_contents( $this->bug29408File, "\x00" );
|
2011-07-12 21:11:43 +00:00
|
|
|
|
|
|
|
|
self::$users = array(
|
|
|
|
|
'sysop' => new ApiTestUser(
|
|
|
|
|
'Uploadstashtestsysop',
|
|
|
|
|
'Upload Stash Test Sysop',
|
2011-12-21 22:22:01 +00:00
|
|
|
'upload_stash_test_sysop@example.com',
|
2011-07-12 21:11:43 +00:00
|
|
|
array( 'sysop' )
|
|
|
|
|
),
|
|
|
|
|
'uploader' => new ApiTestUser(
|
|
|
|
|
'Uploadstashtestuser',
|
|
|
|
|
'Upload Stash Test User',
|
2011-12-21 22:22:01 +00:00
|
|
|
'upload_stash_test_user@example.com',
|
2011-07-12 21:11:43 +00:00
|
|
|
array()
|
|
|
|
|
)
|
|
|
|
|
);
|
2011-06-18 14:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testBug29408() {
|
2011-07-12 21:11:43 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$wgUser = self::$users['uploader']->user;
|
|
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
$repo = RepoGroup::singleton()->getLocalRepo();
|
|
|
|
|
$stash = new UploadStash( $repo );
|
2012-01-07 01:33:23 +00:00
|
|
|
|
|
|
|
|
$this->markTestIncomplete( 'Broken' );
|
|
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
// 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' );
|
|
|
|
|
|
2011-07-12 21:11:43 +00:00
|
|
|
$stash->removeFile( $file->getFileKey() );
|
2011-06-18 14:56:14 +00:00
|
|
|
}
|
2011-08-15 18:10:10 +00:00
|
|
|
|
|
|
|
|
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' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
|
parent::tearDown();
|
2011-06-21 15:06:59 +00:00
|
|
|
|
2011-08-15 18:10:10 +00:00
|
|
|
if( file_exists( $this->bug29408File . "." ) ) {
|
|
|
|
|
unlink( $this->bug29408File . "." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( file_exists( $this->bug29408File ) ) {
|
|
|
|
|
unlink( $this->bug29408File );
|
|
|
|
|
}
|
2011-06-18 14:56:14 +00:00
|
|
|
}
|
2011-06-21 15:06:59 +00:00
|
|
|
}
|