| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Request\FauxRequest; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class UploadStashTest extends MediaWikiIntegrationTestCase { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
private $tmpFile; |
| 15 |
|
| 16 |
protected function setUp(): void { |
| 17 |
parent::setUp(); |
| 18 |
|
| 19 |
$this->tmpFile = $this->getNewTempFile(); |
| 20 |
file_put_contents( $this->tmpFile, "\x00" ); |
| 21 |
} |
| 22 |
|
| 23 |
public static function provideInvalidRequests() { |
| 24 |
return [ |
| 25 |
'Check failure on bad wpFileKey' => |
| 26 |
[ new FauxRequest( [ 'wpFileKey' => 'foo' ] ) ], |
| 27 |
'Check failure on bad wpSessionKey' => |
| 28 |
[ new FauxRequest( [ 'wpSessionKey' => 'foo' ] ) ], |
| 29 |
]; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public function testValidRequestWithInvalidRequests( $request ) { |
| 36 |
$this->assertFalse( UploadFromStash::isValidRequest( $request ) ); |
| 37 |
} |
| 38 |
|
| 39 |
public static function provideValidRequests() { |
| 40 |
return [ |
| 41 |
'Check good wpFileKey' => |
| 42 |
[ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ], |
| 43 |
'Check good wpSessionKey' => |
| 44 |
[ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ], |
| 45 |
'Check key precedence' => |
| 46 |
[ new FauxRequest( [ |
| 47 |
'wpFileKey' => 'testkey-test.test', |
| 48 |
'wpSessionKey' => 'foo' |
| 49 |
] ) ], |
| 50 |
]; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function testValidRequestWithValidRequests( $request ) { |
| 57 |
$this->assertTrue( UploadFromStash::isValidRequest( $request ) ); |
| 58 |
} |
| 59 |
} |