Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / upload / UploadStashTest.php
blobd5d1188e7d974776a6a7d27c545cd419cd418a2e
1 <?php
3 /**
4 * @group Database
6 * @covers UploadStash
7 */
8 class UploadStashTest extends MediaWikiTestCase {
9 /**
10 * @var array 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 = __DIR__ . '/bug29408';
24 file_put_contents( $this->bug29408File, "\x00" );
26 self::$users = array(
27 'sysop' => new TestUser(
28 'Uploadstashtestsysop',
29 'Upload Stash Test Sysop',
30 'upload_stash_test_sysop@example.com',
31 array( 'sysop' )
33 'uploader' => new TestUser(
34 'Uploadstashtestuser',
35 'Upload Stash Test User',
36 'upload_stash_test_user@example.com',
37 array()
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']->user );
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 array(
73 'Check failure on bad wpFileKey' =>
74 array( new FauxRequest( array( 'wpFileKey' => 'foo' ) ) ),
75 'Check failure on bad wpSessionKey' =>
76 array( new FauxRequest( array( 'wpSessionKey' => 'foo' ) ) ),
80 /**
81 * @dataProvider provideInvalidRequests
83 public function testValidRequestWithInvalidRequests( $request ) {
84 $this->assertFalse( UploadFromStash::isValidRequest( $request ) );
87 public static function provideValidRequests() {
88 return array(
89 'Check good wpFileKey' =>
90 array( new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ) ),
91 'Check good wpSessionKey' =>
92 array( new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ) ),
93 'Check key precedence' =>
94 array( new FauxRequest( array(
95 'wpFileKey' => 'testkey-test.test',
96 'wpSessionKey' => 'foo'
97 ) ) ),
101 * @dataProvider provideValidRequests
103 public function testValidRequestWithValidRequests( $request ) {
104 $this->assertTrue( UploadFromStash::isValidRequest( $request ) );