MediaWiki  REL1_19
UploadStashTest.php
Go to the documentation of this file.
00001 <?php
00005 class UploadStashTest extends MediaWikiTestCase {
00009         public static $users;
00010 
00011         public function setUp() {
00012                 parent::setUp();
00013 
00014                 // Setup a file for bug 29408
00015                 $this->bug29408File = dirname( __FILE__ ) . '/bug29408';
00016                 file_put_contents( $this->bug29408File, "\x00" );
00017 
00018                 self::$users = array(
00019                         'sysop' => new ApiTestUser(
00020                                 'Uploadstashtestsysop',
00021                                 'Upload Stash Test Sysop',
00022                                 '[email protected]',
00023                                 array( 'sysop' )
00024                         ),
00025                         'uploader' => new ApiTestUser(
00026                                 'Uploadstashtestuser',
00027                                 'Upload Stash Test User',
00028                                 '[email protected]',
00029                                 array()
00030                         )
00031                 );
00032         }
00033 
00034         public function testBug29408() {
00035                 global $wgUser;
00036                 $wgUser = self::$users['uploader']->user;
00037 
00038                 $repo = RepoGroup::singleton()->getLocalRepo();
00039                 $stash = new UploadStash( $repo );
00040 
00041                 // Throws exception caught by PHPUnit on failure
00042                 $file = $stash->stashFile( $this->bug29408File );
00043                 // We'll never reach this point if we hit bug 29408
00044                 $this->assertTrue( true, 'Unrecognized file without extension' );
00045 
00046                 $stash->removeFile( $file->getFileKey() );
00047         }
00048 
00049         public function testValidRequest() {
00050                 $request = new FauxRequest( array( 'wpFileKey' => 'foo') );
00051                 $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpFileKey' );
00052 
00053                 $request = new FauxRequest( array( 'wpSessionKey' => 'foo') );
00054                 $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpSessionKey' );
00055 
00056                 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') );
00057                 $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpFileKey' );
00058 
00059                 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') );
00060                 $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpSessionKey' );
00061 
00062                 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo') );
00063                 $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check key precedence' );
00064         }
00065 
00066         public function tearDown() {
00067                 parent::tearDown();
00068 
00069                 if( file_exists( $this->bug29408File . "." ) ) {
00070                         unlink( $this->bug29408File . "." );
00071                 }
00072 
00073                 if( file_exists( $this->bug29408File ) ) {
00074                         unlink( $this->bug29408File );
00075                 }
00076         }
00077 }