MediaWiki  REL1_22
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         $this->setMwGlobals( 'wgUser', self::$users['uploader']->user );
00048 
00049         $repo = RepoGroup::singleton()->getLocalRepo();
00050         $stash = new UploadStash( $repo );
00051 
00052         // Throws exception caught by PHPUnit on failure
00053         $file = $stash->stashFile( $this->bug29408File );
00054         // We'll never reach this point if we hit bug 29408
00055         $this->assertTrue( true, 'Unrecognized file without extension' );
00056 
00057         $stash->removeFile( $file->getFileKey() );
00058     }
00059 
00060     public function testValidRequest() {
00061         $request = new FauxRequest( array( 'wpFileKey' => 'foo' ) );
00062         $this->assertFalse( UploadFromStash::isValidRequest( $request ), 'Check failure on bad wpFileKey' );
00063 
00064         $request = new FauxRequest( array( 'wpSessionKey' => 'foo' ) );
00065         $this->assertFalse( UploadFromStash::isValidRequest( $request ), 'Check failure on bad wpSessionKey' );
00066 
00067         $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
00068         $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpFileKey' );
00069 
00070         $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
00071         $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpSessionKey' );
00072 
00073         $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo' ) );
00074         $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check key precedence' );
00075     }
00076 }