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