Follows-upb36d883. By far most data providers are static (and PHPUnit expects them to be static and calls them that way). Most of these classes already had their data providers static but additional commits sloppily introduced non-static ones. * ResourceLoaderWikiModuleTest,8968d8787f. * TitleTest,545f1d3a73. Odd unused method 'dataTestIsValidMoveOperation' was introduced in550b878e63. * GlobalVarConfigTest,a3e18c3670. Change-Id: I5da99f7cd3da68c550ae507ffe1f725d31e7666f
107 lines
2.6 KiB
PHP
107 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Database
|
|
*
|
|
* @covers UploadStash
|
|
*/
|
|
class UploadStashTest extends MediaWikiTestCase {
|
|
/**
|
|
* @var array Array of UploadStashTestUser
|
|
*/
|
|
public static $users;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $bug29408File;
|
|
|
|
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()
|
|
)
|
|
);
|
|
}
|
|
|
|
protected function tearDown() {
|
|
if ( file_exists( $this->bug29408File . "." ) ) {
|
|
unlink( $this->bug29408File . "." );
|
|
}
|
|
|
|
if ( file_exists( $this->bug29408File ) ) {
|
|
unlink( $this->bug29408File );
|
|
}
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* @todo give this test a real name explaining what is being tested here
|
|
*/
|
|
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 static function provideInvalidRequests() {
|
|
return array(
|
|
'Check failure on bad wpFileKey' =>
|
|
array( new FauxRequest( array( 'wpFileKey' => 'foo' ) ) ),
|
|
'Check failure on bad wpSessionKey' =>
|
|
array( new FauxRequest( array( 'wpSessionKey' => 'foo' ) ) ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideInvalidRequests
|
|
*/
|
|
public function testValidRequestWithInvalidRequests( $request ) {
|
|
$this->assertFalse( UploadFromStash::isValidRequest( $request ) );
|
|
}
|
|
|
|
public static function provideValidRequests() {
|
|
return array(
|
|
'Check good wpFileKey' =>
|
|
array( new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ) ),
|
|
'Check good wpSessionKey' =>
|
|
array( new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ) ),
|
|
'Check key precedence' =>
|
|
array( new FauxRequest( array(
|
|
'wpFileKey' => 'testkey-test.test',
|
|
'wpSessionKey' => 'foo'
|
|
) ) ),
|
|
);
|
|
}
|
|
/**
|
|
* @dataProvider provideValidRequests
|
|
*/
|
|
public function testValidRequestWithValidRequests( $request ) {
|
|
$this->assertTrue( UploadFromStash::isValidRequest( $request ) );
|
|
}
|
|
|
|
}
|