/**
* @var string
*/
- private $bug29408File;
+ private $tmpFile;
protected function setUp() {
parent::setUp();
- // Setup a file for bug 29408
- $this->bug29408File = wfTempDir() . '/bug29408';
- file_put_contents( $this->bug29408File, "\x00" );
+ $this->tmpFile = $this->getNewTempFile();
+ file_put_contents( $this->tmpFile, "\x00" );
self::$users = [
'sysop' => new TestUser(
];
}
- 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
*/
$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
+ $file = $stash->stashFile( $this->tmpFile );
+ // We'll never reach this point if we hit T31408
$this->assertTrue( true, 'Unrecognized file without extension' );
$stash->removeFile( $file->getFileKey() );
$this->assertTrue( UploadFromStash::isValidRequest( $request ) );
}
+ public function testExceptionWhenStoreTempFails() {
+ $mockRepoStoreStatusResult = Status::newFatal( 'TEST_ERROR' );
+ $mockRepo = $this->getMockBuilder( FileRepo::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockRepo->expects( $this->once() )
+ ->method( 'storeTemp' )
+ ->willReturn( $mockRepoStoreStatusResult );
+
+ $stash = new UploadStash( $mockRepo );
+ try {
+ $stash->stashFile( $this->tmpFile );
+ $this->fail( 'Expected UploadStashFileException not thrown' );
+ } catch ( UploadStashFileException $e ) {
+ $this->assertInstanceOf( ILocalizedException::class, $e );
+ } catch ( Exception $e ) {
+ $this->fail( 'Unexpected exception class ' . get_class( $e ) );
+ }
+ }
}