X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fupload%2FUploadStashTest.php;h=e7960651cd6fe9f68549d45482b362fd52dd171f;hb=33afb7440a03df8d1878c94d2f3d3b9fdd1a848b;hp=7c40a2dfb626513692bd9a5d2600cddd1f60776b;hpb=cf35ff756c89ca6d6e003b440076df5ebe7ccef7;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php index 7c40a2dfb6..e7960651cd 100644 --- a/tests/phpunit/includes/upload/UploadStashTest.php +++ b/tests/phpunit/includes/upload/UploadStashTest.php @@ -14,14 +14,13 @@ class UploadStashTest extends MediaWikiTestCase { /** * @var string */ - private $bug29408File; + private $tmpFile; protected function setUp() { parent::setUp(); - // Setup a file for T31408 - $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( @@ -39,29 +38,17 @@ class UploadStashTest extends MediaWikiTestCase { ]; } - 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() { + public function testT31408() { $this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() ); $repo = RepoGroup::singleton()->getLocalRepo(); $stash = new UploadStash( $repo ); // Throws exception caught by PHPUnit on failure - $file = $stash->stashFile( $this->bug29408File ); + $file = $stash->stashFile( $this->tmpFile ); // We'll never reach this point if we hit T31408 $this->assertTrue( true, 'Unrecognized file without extension' ); @@ -104,4 +91,23 @@ class UploadStashTest extends MediaWikiTestCase { $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 ) ); + } + } }