7 class UploadStashTest
extends MediaWikiTestCase
{
9 * @var Array of UploadStashTestUser
13 protected function setUp() {
16 // Setup a file for bug 29408
17 $this->bug29408File
= __DIR__
. '/bug29408';
18 file_put_contents( $this->bug29408File
, "\x00" );
21 'sysop' => new TestUser(
22 'Uploadstashtestsysop',
23 'Upload Stash Test Sysop',
24 'upload_stash_test_sysop@example.com',
27 'uploader' => new TestUser(
28 'Uploadstashtestuser',
29 'Upload Stash Test User',
30 'upload_stash_test_user@example.com',
36 protected function tearDown() {
37 if ( file_exists( $this->bug29408File
. "." ) ) {
38 unlink( $this->bug29408File
. "." );
41 if ( file_exists( $this->bug29408File
) ) {
42 unlink( $this->bug29408File
);
48 public function testBug29408() {
49 $this->setMwGlobals( 'wgUser', self
::$users['uploader']->user
);
51 $repo = RepoGroup
::singleton()->getLocalRepo();
52 $stash = new UploadStash( $repo );
54 // Throws exception caught by PHPUnit on failure
55 $file = $stash->stashFile( $this->bug29408File
);
56 // We'll never reach this point if we hit bug 29408
57 $this->assertTrue( true, 'Unrecognized file without extension' );
59 $stash->removeFile( $file->getFileKey() );
62 public function testValidRequest() {
63 $request = new FauxRequest( array( 'wpFileKey' => 'foo' ) );
64 $this->assertFalse( UploadFromStash
::isValidRequest( $request ), 'Check failure on bad wpFileKey' );
66 $request = new FauxRequest( array( 'wpSessionKey' => 'foo' ) );
67 $this->assertFalse( UploadFromStash
::isValidRequest( $request ), 'Check failure on bad wpSessionKey' );
69 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
70 $this->assertTrue( UploadFromStash
::isValidRequest( $request ), 'Check good wpFileKey' );
72 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
73 $this->assertTrue( UploadFromStash
::isValidRequest( $request ), 'Check good wpSessionKey' );
75 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo' ) );
76 $this->assertTrue( UploadFromStash
::isValidRequest( $request ), 'Check key precedence' );