Compress images
[mediawiki.git] / tests / phpunit / includes / upload / UploadStashTest.php
blobc9dbb1388e61f836ca977ab83a973423aec5c68f
1 <?php
2 /**
3 * @group Database
4 */
5 class UploadStashTest extends MediaWikiTestCase {
6 /**
7 * @var Array of UploadStashTestUser
8 */
9 public static $users;
11 public function setUp() {
12 parent::setUp();
14 // Setup a file for bug 29408
15 $this->bug29408File = dirname( __FILE__ ) . '/bug29408';
16 file_put_contents( $this->bug29408File, "\x00" );
18 self::$users = array(
19 'sysop' => new ApiTestUser(
20 'Uploadstashtestsysop',
21 'Upload Stash Test Sysop',
22 'upload_stash_test_sysop@example.com',
23 array( 'sysop' )
25 'uploader' => new ApiTestUser(
26 'Uploadstashtestuser',
27 'Upload Stash Test User',
28 'upload_stash_test_user@example.com',
29 array()
34 public function testBug29408() {
35 global $wgUser;
36 $wgUser = self::$users['uploader']->user;
38 $repo = RepoGroup::singleton()->getLocalRepo();
39 $stash = new UploadStash( $repo );
41 // Throws exception caught by PHPUnit on failure
42 $file = $stash->stashFile( $this->bug29408File );
43 // We'll never reach this point if we hit bug 29408
44 $this->assertTrue( true, 'Unrecognized file without extension' );
46 $stash->removeFile( $file->getFileKey() );
49 public function testValidRequest() {
50 $request = new FauxRequest( array( 'wpFileKey' => 'foo') );
51 $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpFileKey' );
53 $request = new FauxRequest( array( 'wpSessionKey' => 'foo') );
54 $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpSessionKey' );
56 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') );
57 $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpFileKey' );
59 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') );
60 $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpSessionKey' );
62 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo') );
63 $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check key precedence' );
66 public function tearDown() {
67 parent::tearDown();
69 if( file_exists( $this->bug29408File . "." ) ) {
70 unlink( $this->bug29408File . "." );
73 if( file_exists( $this->bug29408File ) ) {
74 unlink( $this->bug29408File );