MediaWiki  REL1_24
UploadStashTest.php
Go to the documentation of this file.
00001 <?php
00002 
00008 class UploadStashTest extends MediaWikiTestCase {
00012     public static $users;
00013 
00017     private $bug29408File;
00018 
00019     protected function setUp() {
00020         parent::setUp();
00021 
00022         // Setup a file for bug 29408
00023         $this->bug29408File = __DIR__ . '/bug29408';
00024         file_put_contents( $this->bug29408File, "\x00" );
00025 
00026         self::$users = array(
00027             'sysop' => new TestUser(
00028                 'Uploadstashtestsysop',
00029                 'Upload Stash Test Sysop',
00030                 '[email protected]',
00031                 array( 'sysop' )
00032             ),
00033             'uploader' => new TestUser(
00034                 'Uploadstashtestuser',
00035                 'Upload Stash Test User',
00036                 '[email protected]',
00037                 array()
00038             )
00039         );
00040     }
00041 
00042     protected function tearDown() {
00043         if ( file_exists( $this->bug29408File . "." ) ) {
00044             unlink( $this->bug29408File . "." );
00045         }
00046 
00047         if ( file_exists( $this->bug29408File ) ) {
00048             unlink( $this->bug29408File );
00049         }
00050 
00051         parent::tearDown();
00052     }
00053 
00057     public function testBug29408() {
00058         $this->setMwGlobals( 'wgUser', self::$users['uploader']->user );
00059 
00060         $repo = RepoGroup::singleton()->getLocalRepo();
00061         $stash = new UploadStash( $repo );
00062 
00063         // Throws exception caught by PHPUnit on failure
00064         $file = $stash->stashFile( $this->bug29408File );
00065         // We'll never reach this point if we hit bug 29408
00066         $this->assertTrue( true, 'Unrecognized file without extension' );
00067 
00068         $stash->removeFile( $file->getFileKey() );
00069     }
00070 
00071     public static function provideInvalidRequests() {
00072         return array(
00073             'Check failure on bad wpFileKey' =>
00074                 array( new FauxRequest( array( 'wpFileKey' => 'foo' ) ) ),
00075             'Check failure on bad wpSessionKey' =>
00076                 array( new FauxRequest( array( 'wpSessionKey' => 'foo' ) ) ),
00077         );
00078     }
00079 
00083     public function testValidRequestWithInvalidRequests( $request ) {
00084         $this->assertFalse( UploadFromStash::isValidRequest( $request ) );
00085     }
00086 
00087     public static function provideValidRequests() {
00088         return array(
00089             'Check good wpFileKey' =>
00090                 array( new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ) ),
00091             'Check good wpSessionKey' =>
00092                 array( new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ) ),
00093             'Check key precedence' =>
00094                 array( new FauxRequest( array(
00095                     'wpFileKey' => 'testkey-test.test',
00096                     'wpSessionKey' => 'foo'
00097                 ) ) ),
00098         );
00099     }
00103     public function testValidRequestWithValidRequests( $request ) {
00104         $this->assertTrue( UploadFromStash::isValidRequest( $request ) );
00105     }
00106 
00107 }