MediaWiki REL1_31
UploadStashTest.php
Go to the documentation of this file.
1<?php
2
12 public static $users;
13
17 private $tmpFile;
18
19 protected function setUp() {
20 parent::setUp();
21
22 $this->tmpFile = $this->getNewTempFile();
23 file_put_contents( $this->tmpFile, "\x00" );
24
25 self::$users = [
26 'sysop' => new TestUser(
27 'Uploadstashtestsysop',
28 'Upload Stash Test Sysop',
29 'upload_stash_test_sysop@example.com',
30 [ 'sysop' ]
31 ),
32 'uploader' => new TestUser(
33 'Uploadstashtestuser',
34 'Upload Stash Test User',
35 'upload_stash_test_user@example.com',
36 []
37 )
38 ];
39 }
40
44 public function testBug29408() {
45 $this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() );
46
47 $repo = RepoGroup::singleton()->getLocalRepo();
48 $stash = new UploadStash( $repo );
49
50 // Throws exception caught by PHPUnit on failure
51 $file = $stash->stashFile( $this->tmpFile );
52 // We'll never reach this point if we hit T31408
53 $this->assertTrue( true, 'Unrecognized file without extension' );
54
55 $stash->removeFile( $file->getFileKey() );
56 }
57
58 public static function provideInvalidRequests() {
59 return [
60 'Check failure on bad wpFileKey' =>
61 [ new FauxRequest( [ 'wpFileKey' => 'foo' ] ) ],
62 'Check failure on bad wpSessionKey' =>
63 [ new FauxRequest( [ 'wpSessionKey' => 'foo' ] ) ],
64 ];
65 }
66
71 $this->assertFalse( UploadFromStash::isValidRequest( $request ) );
72 }
73
74 public static function provideValidRequests() {
75 return [
76 'Check good wpFileKey' =>
77 [ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ],
78 'Check good wpSessionKey' =>
79 [ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ],
80 'Check key precedence' =>
81 [ new FauxRequest( [
82 'wpFileKey' => 'testkey-test.test',
83 'wpSessionKey' => 'foo'
84 ] ) ],
85 ];
86 }
91 $this->assertTrue( UploadFromStash::isValidRequest( $request ) );
92 }
93
95 $mockRepoStoreStatusResult = Status::newFatal( 'TEST_ERROR' );
96 $mockRepo = $this->getMockBuilder( FileRepo::class )
97 ->disableOriginalConstructor()
98 ->getMock();
99 $mockRepo->expects( $this->once() )
100 ->method( 'storeTemp' )
101 ->willReturn( $mockRepoStoreStatusResult );
102
103 $stash = new UploadStash( $mockRepo );
104 try {
105 $stash->stashFile( $this->tmpFile );
106 $this->fail( 'Expected UploadStashFileException not thrown' );
107 } catch ( UploadStashFileException $e ) {
108 $this->assertInstanceOf( ILocalizedException::class, $e );
109 } catch ( Exception $e ) {
110 $this->fail( 'Unexpected exception class ' . get_class( $e ) );
111 }
112 }
113}
WebRequest clone which takes values from a provided array.
getNewTempFile()
Obtains a new temporary file name.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
static singleton()
Get a RepoGroup instance.
Definition RepoGroup.php:59
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition TestUser.php:7
static isValidRequest( $request)
testValidRequestWithValidRequests( $request)
provideValidRequests
testValidRequestWithInvalidRequests( $request)
provideInvalidRequests
static provideInvalidRequests()
static provideValidRequests()
static TestUser[] $users
Array of UploadStashTestUser.
UploadStash is intended to accomplish a few things:
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2806
returning false will NOT prevent logging $e
Definition hooks.txt:2176