Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / upload / UploadStashTest.php
blob9b25505c689169285fb3049f118f6d283feb181e
1 <?php
3 /**
4 * @group Database
6 * @covers UploadStash
7 */
8 class UploadStashTest extends MediaWikiTestCase {
9 /**
10 * @var TestUser[] Array of UploadStashTestUser
12 public static $users;
14 /**
15 * @var string
17 private $bug29408File;
19 protected function setUp() {
20 parent::setUp();
22 // Setup a file for bug 29408
23 $this->bug29408File = wfTempDir() . '/bug29408';
24 file_put_contents( $this->bug29408File, "\x00" );
26 self::$users = [
27 'sysop' => new TestUser(
28 'Uploadstashtestsysop',
29 'Upload Stash Test Sysop',
30 'upload_stash_test_sysop@example.com',
31 [ 'sysop' ]
33 'uploader' => new TestUser(
34 'Uploadstashtestuser',
35 'Upload Stash Test User',
36 'upload_stash_test_user@example.com',
42 protected function tearDown() {
43 if ( file_exists( $this->bug29408File . "." ) ) {
44 unlink( $this->bug29408File . "." );
47 if ( file_exists( $this->bug29408File ) ) {
48 unlink( $this->bug29408File );
51 parent::tearDown();
54 /**
55 * @todo give this test a real name explaining what is being tested here
57 public function testBug29408() {
58 $this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() );
60 $repo = RepoGroup::singleton()->getLocalRepo();
61 $stash = new UploadStash( $repo );
63 // Throws exception caught by PHPUnit on failure
64 $file = $stash->stashFile( $this->bug29408File );
65 // We'll never reach this point if we hit bug 29408
66 $this->assertTrue( true, 'Unrecognized file without extension' );
68 $stash->removeFile( $file->getFileKey() );
71 public static function provideInvalidRequests() {
72 return [
73 'Check failure on bad wpFileKey' =>
74 [ new FauxRequest( [ 'wpFileKey' => 'foo' ] ) ],
75 'Check failure on bad wpSessionKey' =>
76 [ new FauxRequest( [ 'wpSessionKey' => 'foo' ] ) ],
80 /**
81 * @dataProvider provideInvalidRequests
83 public function testValidRequestWithInvalidRequests( $request ) {
84 $this->assertFalse( UploadFromStash::isValidRequest( $request ) );
87 public static function provideValidRequests() {
88 return [
89 'Check good wpFileKey' =>
90 [ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ],
91 'Check good wpSessionKey' =>
92 [ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ],
93 'Check key precedence' =>
94 [ new FauxRequest( [
95 'wpFileKey' => 'testkey-test.test',
96 'wpSessionKey' => 'foo'
97 ] ) ],
101 * @dataProvider provideValidRequests
103 public function testValidRequestWithValidRequests( $request ) {
104 $this->assertTrue( UploadFromStash::isValidRequest( $request ) );