8 class UploadStashTest
extends MediaWikiTestCase
{
10 * @var TestUser[] Array of UploadStashTestUser
17 private $bug29408File;
19 protected function setUp() {
22 // Setup a file for bug 29408
23 $this->bug29408File
= wfTempDir() . '/bug29408';
24 file_put_contents( $this->bug29408File
, "\x00" );
27 'sysop' => new TestUser(
28 'Uploadstashtestsysop',
29 'Upload Stash Test Sysop',
30 'upload_stash_test_sysop@example.com',
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
);
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() {
73 'Check failure on bad wpFileKey' =>
74 [ new FauxRequest( [ 'wpFileKey' => 'foo' ] ) ],
75 'Check failure on bad wpSessionKey' =>
76 [ new FauxRequest( [ 'wpSessionKey' => 'foo' ] ) ],
81 * @dataProvider provideInvalidRequests
83 public function testValidRequestWithInvalidRequests( $request ) {
84 $this->assertFalse( UploadFromStash
::isValidRequest( $request ) );
87 public static function provideValidRequests() {
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' =>
95 'wpFileKey' => 'testkey-test.test',
96 'wpSessionKey' => 'foo'
101 * @dataProvider provideValidRequests
103 public function testValidRequestWithValidRequests( $request ) {
104 $this->assertTrue( UploadFromStash
::isValidRequest( $request ) );