summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/upload/UploadStashTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/upload/UploadStashTest.php')
-rw-r--r--tests/phpunit/includes/upload/UploadStashTest.php53
1 files changed, 37 insertions, 16 deletions
diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php
index e644a259..c9dbb138 100644
--- a/tests/phpunit/includes/upload/UploadStashTest.php
+++ b/tests/phpunit/includes/upload/UploadStashTest.php
@@ -1,5 +1,7 @@
<?php
-
+/**
+ * @group Database
+ */
class UploadStashTest extends MediaWikiTestCase {
/**
* @var Array of UploadStashTestUser
@@ -8,49 +10,68 @@ class UploadStashTest extends MediaWikiTestCase {
public function setUp() {
parent::setUp();
-
+
// Setup a file for bug 29408
$this->bug29408File = dirname( __FILE__ ) . '/bug29408';
- file_put_contents( $this->bug29408File, "\x00" );
-
+ file_put_contents( $this->bug29408File, "\x00" );
+
self::$users = array(
'sysop' => new ApiTestUser(
'Uploadstashtestsysop',
'Upload Stash Test Sysop',
- 'upload_stash_test_sysop@sample.com',
+ 'upload_stash_test_sysop@example.com',
array( 'sysop' )
),
'uploader' => new ApiTestUser(
'Uploadstashtestuser',
'Upload Stash Test User',
- 'upload_stash_test_user@sample.com',
+ 'upload_stash_test_user@example.com',
array()
)
);
}
- /**
- * @group Database
- */
public function testBug29408() {
global $wgUser;
$wgUser = self::$users['uploader']->user;
-
+
$repo = RepoGroup::singleton()->getLocalRepo();
$stash = new UploadStash( $repo );
-
+
// Throws exception caught by PHPUnit on failure
$file = $stash->stashFile( $this->bug29408File );
// We'll never reach this point if we hit bug 29408
$this->assertTrue( true, 'Unrecognized file without extension' );
-
+
$stash->removeFile( $file->getFileKey() );
}
-
+
+ public function testValidRequest() {
+ $request = new FauxRequest( array( 'wpFileKey' => 'foo') );
+ $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpFileKey' );
+
+ $request = new FauxRequest( array( 'wpSessionKey' => 'foo') );
+ $this->assertFalse( UploadFromStash::isValidRequest($request), 'Check failure on bad wpSessionKey' );
+
+ $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') );
+ $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpFileKey' );
+
+ $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test') );
+ $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check good wpSessionKey' );
+
+ $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo') );
+ $this->assertTrue( UploadFromStash::isValidRequest($request), 'Check key precedence' );
+ }
+
public function tearDown() {
parent::tearDown();
-
- unlink( $this->bug29408File . "." );
-
+
+ if( file_exists( $this->bug29408File . "." ) ) {
+ unlink( $this->bug29408File . "." );
+ }
+
+ if( file_exists( $this->bug29408File ) ) {
+ unlink( $this->bug29408File );
+ }
}
}