MediaWiki  1.28.1
UploadStashTest.php
Go to the documentation of this file.
1 <?php
2 
12  public static $users;
13 
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 
57  public function testBug29408() {
58  $this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() );
59 
60  $repo = RepoGroup::singleton()->getLocalRepo();
61  $stash = new UploadStash( $repo );
62 
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' );
67 
68  $stash->removeFile( $file->getFileKey() );
69  }
70 
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' ] ) ],
77  ];
78  }
79 
84  $this->assertFalse( UploadFromStash::isValidRequest( $request ) );
85  }
86 
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  ] ) ],
98  ];
99  }
104  $this->assertTrue( UploadFromStash::isValidRequest( $request ) );
105  }
106 
107 }
testValidRequestWithInvalidRequests($request)
provideInvalidRequests
wfTempDir()
Tries to get the system directory for temporary files.
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:59
static TestUser[] $users
Array of UploadStashTestUser.
static provideValidRequests()
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
UploadStash is intended to accomplish a few things:
Definition: UploadStash.php:54
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2573
static isValidRequest($request)
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition: TestUser.php:7
testValidRequestWithValidRequests($request)
provideValidRequests
setMwGlobals($pairs, $value=null)
static provideInvalidRequests()