5 class UploadStashTest
extends MediaWikiTestCase
{
7 * @var Array of UploadStashTestUser
11 protected function setUp() {
14 // Setup a file for bug 29408
15 $this->bug29408File
= __DIR__
. '/bug29408';
16 file_put_contents( $this->bug29408File
, "\x00" );
19 'sysop' => new TestUser(
20 'Uploadstashtestsysop',
21 'Upload Stash Test Sysop',
22 'upload_stash_test_sysop@example.com',
25 'uploader' => new TestUser(
26 'Uploadstashtestuser',
27 'Upload Stash Test User',
28 'upload_stash_test_user@example.com',
34 protected function tearDown() {
35 if ( file_exists( $this->bug29408File
. "." ) ) {
36 unlink( $this->bug29408File
. "." );
39 if ( file_exists( $this->bug29408File
) ) {
40 unlink( $this->bug29408File
);
46 public function testBug29408() {
48 $wgUser = self
::$users['uploader']->user
;
50 $repo = RepoGroup
::singleton()->getLocalRepo();
51 $stash = new UploadStash( $repo );
53 // Throws exception caught by PHPUnit on failure
54 $file = $stash->stashFile( $this->bug29408File
);
55 // We'll never reach this point if we hit bug 29408
56 $this->assertTrue( true, 'Unrecognized file without extension' );
58 $stash->removeFile( $file->getFileKey() );
61 public function testValidRequest() {
62 $request = new FauxRequest( array( 'wpFileKey' => 'foo' ) );
63 $this->assertFalse( UploadFromStash
::isValidRequest( $request ), 'Check failure on bad wpFileKey' );
65 $request = new FauxRequest( array( 'wpSessionKey' => 'foo' ) );
66 $this->assertFalse( UploadFromStash
::isValidRequest( $request ), 'Check failure on bad wpSessionKey' );
68 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
69 $this->assertTrue( UploadFromStash
::isValidRequest( $request ), 'Check good wpFileKey' );
71 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
72 $this->assertTrue( UploadFromStash
::isValidRequest( $request ), 'Check good wpSessionKey' );
74 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo' ) );
75 $this->assertTrue( UploadFromStash
::isValidRequest( $request ), 'Check key precedence' );