aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiUploadTest.php
diff options
context:
space:
mode:
authorTimo Tijhof <krinklemail@gmail.com>2015-02-11 01:42:33 +0000
committerTimo Tijhof <krinklemail@gmail.com>2015-02-11 03:49:02 +0000
commit48d715148bad09faf56b5f854fde0029ac7f5dac (patch)
treec591d68365b2e6561e751aa8504da62df16a5f7e /tests/phpunit/includes/api/ApiUploadTest.php
parent9bd8dc6e2dedebf4a6b3cc045ffec154c296cf25 (diff)
downloadmediawikicore-48d715148bad09faf56b5f854fde0029ac7f5dac.tar.gz
mediawikicore-48d715148bad09faf56b5f854fde0029ac7f5dac.zip
Use MediaWikiTestCase methods for tempdir in unit tests
* Use MediaWikiTestCase::getNewTempFile and getNewTempDirectory instead of wfTempDir(). The upload api tests wrote a tempnam() file directly (where wfTempDir() is typically shared with other systems and concurrent runs). Use MediaWikiTestCase::getNewTempFile and getNewTempDirectory instead. This also ensures its removal by the teardown handler without needing manual unlink() calls. And it doesn't rely on the test passing. (Many unlink calls where at the bottom of tests, which wouldn't be reached in case of failure). * For the upload test, the presistent storing of 'Oberaargletscher_from_Oberaar.jpg' (downloaded from Commons) was removed. Note that this didn't work for Jenkins builds anyway as Jenkins builds set $wgTmpDirectory to a unique directory in tmpfs associated with an individual build. * For filebackend tests, moved directory creation from the dataProvider to the main test. Implemented addTmpFiles() to allow subclasses to register additional files (created by other means) to be cleaned up also. Removed unused $tmpName and $toPath parameters in data provider for FileBackendTest::testStore. And fixed weird double $op2 variable name to be called $op3. * Skipped parserTest.inc, MockFileBackend.php, and UploadFromUrlTestSuite.php as those don't use MediaWikiTestCase. Change-Id: Ic7feb06ef0c1006eb99485470a1a59419f972545
Diffstat (limited to 'tests/phpunit/includes/api/ApiUploadTest.php')
-rw-r--r--tests/phpunit/includes/api/ApiUploadTest.php28
1 files changed, 9 insertions, 19 deletions
diff --git a/tests/phpunit/includes/api/ApiUploadTest.php b/tests/phpunit/includes/api/ApiUploadTest.php
index 7fdefb6cad46..b4b1bf3f6f90 100644
--- a/tests/phpunit/includes/api/ApiUploadTest.php
+++ b/tests/phpunit/includes/api/ApiUploadTest.php
@@ -103,7 +103,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
try {
$randomImageGenerator = new RandomImageGenerator();
- $filePaths = $randomImageGenerator->writeImages( 1, $extension, wfTempDir() );
+ $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->getNewTempDirectory() );
} catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
@@ -143,7 +143,6 @@ class ApiUploadTest extends ApiTestCaseUpload {
// clean up
$this->deleteFileByFilename( $fileName );
- unlink( $filePath );
}
/**
@@ -152,7 +151,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
public function testUploadZeroLength( $session ) {
$mimeType = 'image/png';
- $filePath = tempnam( wfTempDir(), "" );
+ $filePath = $this->getNewTempFile();
$fileName = "apiTestUploadZeroLength.png";
$this->deleteFileByFileName( $fileName );
@@ -180,7 +179,6 @@ class ApiUploadTest extends ApiTestCaseUpload {
// clean up
$this->deleteFileByFilename( $fileName );
- unlink( $filePath );
}
/**
@@ -192,7 +190,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
try {
$randomImageGenerator = new RandomImageGenerator();
- $filePaths = $randomImageGenerator->writeImages( 2, $extension, wfTempDir() );
+ $filePaths = $randomImageGenerator->writeImages( 2, $extension, $this->getNewTempDirectory() );
} catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
@@ -251,8 +249,6 @@ class ApiUploadTest extends ApiTestCaseUpload {
// clean up
$this->deleteFileByFilename( $fileName );
- unlink( $filePaths[0] );
- unlink( $filePaths[1] );
}
/**
@@ -264,7 +260,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
try {
$randomImageGenerator = new RandomImageGenerator();
- $filePaths = $randomImageGenerator->writeImages( 1, $extension, wfTempDir() );
+ $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->getNewTempDirectory() );
} catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
@@ -333,7 +329,6 @@ class ApiUploadTest extends ApiTestCaseUpload {
// clean up
$this->deleteFileByFilename( $fileNames[0] );
$this->deleteFileByFilename( $fileNames[1] );
- unlink( $filePaths[0] );
}
/**
@@ -349,7 +344,7 @@ class ApiUploadTest extends ApiTestCaseUpload {
try {
$randomImageGenerator = new RandomImageGenerator();
- $filePaths = $randomImageGenerator->writeImages( 1, $extension, wfTempDir() );
+ $filePaths = $randomImageGenerator->writeImages( 1, $extension, $this->getNewTempDirectory() );
} catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
@@ -417,7 +412,6 @@ class ApiUploadTest extends ApiTestCaseUpload {
// clean up
$this->deleteFileByFilename( $fileName );
- unlink( $filePath );
}
/**
@@ -431,16 +425,14 @@ class ApiUploadTest extends ApiTestCaseUpload {
$chunkSize = 1048576;
// Download a large image file
- // ( using RandomImageGenerator for large files is not stable )
+ // (using RandomImageGenerator for large files is not stable)
+ // @todo Don't download files from wikimedia.org
$mimeType = 'image/jpeg';
$url = 'http://upload.wikimedia.org/wikipedia/commons/'
. 'e/ed/Oberaargletscher_from_Oberaar%2C_2010_07.JPG';
- $filePath = wfTempDir() . '/Oberaargletscher_from_Oberaar.jpg';
+ $filePath = $this->getNewTempDirectory() . '/Oberaargletscher_from_Oberaar.jpg';
try {
- // Only download if the file is not avaliable in the temp location:
- if ( !is_file( $filePath ) ) {
- copy( $url, $filePath );
- }
+ copy( $url, $filePath );
} catch ( Exception $e ) {
$this->markTestIncomplete( $e->getMessage() );
}
@@ -564,7 +556,5 @@ class ApiUploadTest extends ApiTestCaseUpload {
// clean up
$this->deleteFileByFilename( $fileName );
- // don't remove downloaded temporary file for fast subquent tests.
- //unlink( $filePath );
}
}