wiki.techinc.nl/tests/phpunit/includes/upload/UploadStashTest.php

77 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* @group Database
*/
class UploadStashTest extends MediaWikiTestCase {
/**
* @var Array of UploadStashTestUser
*/
public static $users;
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
protected function setUp() {
parent::setUp();
// Setup a file for bug 29408
$this->bug29408File = __DIR__ . '/bug29408';
file_put_contents( $this->bug29408File, "\x00" );
self::$users = array(
'sysop' => new TestUser(
'Uploadstashtestsysop',
'Upload Stash Test Sysop',
'upload_stash_test_sysop@example.com',
array( 'sysop' )
),
'uploader' => new TestUser(
'Uploadstashtestuser',
'Upload Stash Test User',
'upload_stash_test_user@example.com',
array()
)
);
}
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
protected function tearDown() {
if ( file_exists( $this->bug29408File . "." ) ) {
unlink( $this->bug29408File . "." );
}
if ( file_exists( $this->bug29408File ) ) {
unlink( $this->bug29408File );
}
parent::tearDown();
}
public function testBug29408() {
$this->setMwGlobals( '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' );
}
}