Merge "Rm unused 'remembermypassword' message, doc another"
[lhc/web/wiklou.git] / tests / phpunit / includes / upload / UploadStashTest.php
1 <?php
2
3 /**
4 * @group Database
5 *
6 * @covers UploadStash
7 */
8 class UploadStashTest extends MediaWikiTestCase {
9 /**
10 * @var TestUser[] Array of UploadStashTestUser
11 */
12 public static $users;
13
14 /**
15 * @var string
16 */
17 private $bug29408File;
18
19 protected function setUp() {
20 parent::setUp();
21
22 // Setup a file for bug 29408
23 $this->bug29408File = wfTempDir() . '/bug29408';
24 file_put_contents( $this->bug29408File, "\x00" );
25
26 self::$users = [
27 'sysop' => new TestUser(
28 'Uploadstashtestsysop',
29 'Upload Stash Test Sysop',
30 'upload_stash_test_sysop@example.com',
31 [ 'sysop' ]
32 ),
33 'uploader' => new TestUser(
34 'Uploadstashtestuser',
35 'Upload Stash Test User',
36 'upload_stash_test_user@example.com',
37 []
38 )
39 ];
40 }
41
42 protected function tearDown() {
43 if ( file_exists( $this->bug29408File . "." ) ) {
44 unlink( $this->bug29408File . "." );
45 }
46
47 if ( file_exists( $this->bug29408File ) ) {
48 unlink( $this->bug29408File );
49 }
50
51 parent::tearDown();
52 }
53
54 /**
55 * @todo give this test a real name explaining what is being tested here
56 */
57 public function testBug29408() {
58 $repo = RepoGroup::singleton()->getLocalRepo();
59 $stash = new UploadStash( $repo, self::$users['uploader']->getUser() );
60
61 // Throws exception caught by PHPUnit on failure
62 $file = $stash->stashFile( $this->bug29408File );
63 // We'll never reach this point if we hit bug 29408
64 $this->assertTrue( true, 'Unrecognized file without extension' );
65
66 $stash->removeFile( $file->getFileKey() );
67 }
68
69 public static function provideInvalidRequests() {
70 return [
71 'Check failure on bad wpFileKey' =>
72 [ new FauxRequest( [ 'wpFileKey' => 'foo' ] ) ],
73 'Check failure on bad wpSessionKey' =>
74 [ new FauxRequest( [ 'wpSessionKey' => 'foo' ] ) ],
75 ];
76 }
77
78 /**
79 * @dataProvider provideInvalidRequests
80 */
81 public function testValidRequestWithInvalidRequests( $request ) {
82 $this->assertFalse( UploadFromStash::isValidRequest( $request ) );
83 }
84
85 public static function provideValidRequests() {
86 return [
87 'Check good wpFileKey' =>
88 [ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ],
89 'Check good wpSessionKey' =>
90 [ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ],
91 'Check key precedence' =>
92 [ new FauxRequest( [
93 'wpFileKey' => 'testkey-test.test',
94 'wpSessionKey' => 'foo'
95 ] ) ],
96 ];
97 }
98 /**
99 * @dataProvider provideValidRequests
100 */
101 public function testValidRequestWithValidRequests( $request ) {
102 $this->assertTrue( UploadFromStash::isValidRequest( $request ) );
103 }
104
105 }