Merge "Installer: Check if /extensions is readable and a directory"
[lhc/web/wiklou.git] / tests / phpunit / includes / upload / UploadStashTest.php
1 <?php
2 /**
3 * @group Database
4 */
5 class UploadStashTest extends MediaWikiTestCase {
6 /**
7 * @var Array of UploadStashTestUser
8 */
9 public static $users;
10
11 protected function setUp() {
12 parent::setUp();
13
14 // Setup a file for bug 29408
15 $this->bug29408File = __DIR__ . '/bug29408';
16 file_put_contents( $this->bug29408File, "\x00" );
17
18 self::$users = array(
19 'sysop' => new TestUser(
20 'Uploadstashtestsysop',
21 'Upload Stash Test Sysop',
22 'upload_stash_test_sysop@example.com',
23 array( 'sysop' )
24 ),
25 'uploader' => new TestUser(
26 'Uploadstashtestuser',
27 'Upload Stash Test User',
28 'upload_stash_test_user@example.com',
29 array()
30 )
31 );
32 }
33
34 protected function tearDown() {
35 if ( file_exists( $this->bug29408File . "." ) ) {
36 unlink( $this->bug29408File . "." );
37 }
38
39 if ( file_exists( $this->bug29408File ) ) {
40 unlink( $this->bug29408File );
41 }
42
43 parent::tearDown();
44 }
45
46 public function testBug29408() {
47 $this->setMwGlobals( 'wgUser', self::$users['uploader']->user );
48
49 $repo = RepoGroup::singleton()->getLocalRepo();
50 $stash = new UploadStash( $repo );
51
52 // Throws exception caught by PHPUnit on failure
53 $file = $stash->stashFile( $this->bug29408File );
54 // We'll never reach this point if we hit bug 29408
55 $this->assertTrue( true, 'Unrecognized file without extension' );
56
57 $stash->removeFile( $file->getFileKey() );
58 }
59
60 public function testValidRequest() {
61 $request = new FauxRequest( array( 'wpFileKey' => 'foo' ) );
62 $this->assertFalse( UploadFromStash::isValidRequest( $request ), 'Check failure on bad wpFileKey' );
63
64 $request = new FauxRequest( array( 'wpSessionKey' => 'foo' ) );
65 $this->assertFalse( UploadFromStash::isValidRequest( $request ), 'Check failure on bad wpSessionKey' );
66
67 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
68 $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpFileKey' );
69
70 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
71 $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpSessionKey' );
72
73 $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo' ) );
74 $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check key precedence' );
75 }
76 }