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