# tests/phpunit/media
'FakeDimensionFile' => "$testDir/phpunit/includes/media/FakeDimensionFile.php",
+ 'MediaWikiMediaTestCase' => "$testDir/phpunit/includes/media/MediaWikiMediaTestCase.php",
# tests/phpunit/mocks
'MockFSFile' => "$testDir/phpunit/mocks/filebackend/MockFSFile.php",
/**
* @covers DjVuHandler
*/
-class DjVuTest extends MediaWikiTestCase {
-
- /**
- * @var string the directory where test files are
- */
- protected $filePath;
-
- /**
- * @var FSRepo the repository to use
- */
- protected $repo;
+class DjVuTest extends MediaWikiMediaTestCase {
/**
* @var DjVuHandler
$djvuSupport = new DjVuSupport();
if ( !$djvuSupport->isEnabled() ) {
- $this->markTestSkipped( 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
+ $this->markTestSkipped(
+ 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
}
- //file repo setup
- $this->filePath = __DIR__ . '/../../data/media/';
- $backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'wikiId' => wfWikiId(),
- 'lockManager' => new NullLockManager( array() ),
- 'containerPaths' => array( 'data' => $this->filePath )
- ) );
- $this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
- 'backend' => $backend
- ) );
-
$this->handler = new DjVuHandler();
}
- protected function dataFile( $name, $type ) {
- return new UnregisteredLocalFile(
- false,
- $this->repo,
- 'mwstore://localtesting/data/' . $name,
- $type
- );
- }
-
public function testGetImageSize() {
$this->assertArrayEquals(
array( 2480, 3508, 'DjVu', 'width="2480" height="3508"' ),
*
* @todo covers tags
*/
-class ExifRotationTest extends MediaWikiTestCase {
+class ExifRotationTest extends MediaWikiMediaTestCase {
protected function setUp() {
parent::setUp();
$this->checkPHPExtension( 'exif' );
$this->handler = new BitmapHandler();
- $filePath = __DIR__ . '/../../data/media';
-
- $tmpDir = $this->getNewTempDirectory();
-
- $this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
- 'backend' => new FSFileBackend( array(
- 'name' => 'localtesting',
- 'wikiId' => wfWikiId(),
- 'containerPaths' => array( 'temp-thumb' => $tmpDir, 'data' => $filePath )
- ) )
- ) );
$this->setMwGlobals( array(
'wgShowEXIF' => true,
) );
}
+ /**
+ * Mark this test as creating thumbnail files.
+ */
+ protected function createsThumbnails() {
+ return true;
+ }
+
/**
* @dataProvider provideFiles
*/
}
}
- /* Utility function */
- private function dataFile( $name, $type ) {
- return new UnregisteredLocalFile( false, $this->repo,
- "mwstore://localtesting/data/$name", $type );
- }
-
public static function provideFiles() {
return array(
array(
<?php
-class FormatMetadataTest extends MediaWikiTestCase {
-
- /** @var FSFileBackend */
- protected $backend;
- /** @var FSRepo */
- protected $repo;
+class FormatMetadataTest extends MediaWikiMediaTestCase {
protected function setUp() {
parent::setUp();
$this->checkPHPExtension( 'exif' );
- $filePath = __DIR__ . '/../../data/media';
- $this->backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'wikiId' => wfWikiId(),
- 'containerPaths' => array( 'data' => $filePath )
- ) );
- $this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
- 'backend' => $this->backend
- ) );
-
$this->setMwGlobals( 'wgShowEXIF', true );
}
// TODO: more test cases
);
}
-
- private function dataFile( $name, $type ) {
- return new UnregisteredLocalFile( false, $this->repo,
- "mwstore://localtesting/data/$name", $type );
- }
}
<?php
-class GIFHandlerTest extends MediaWikiTestCase {
+class GIFHandlerTest extends MediaWikiMediaTestCase {
- /** @var FSFileBackend */
- protected $backend;
/** @var GIFHandler */
protected $handler;
- /** @var FSRepo */
- protected $repo;
- /** @var string */
- protected $filePath;
protected function setUp() {
parent::setUp();
- $this->filePath = __DIR__ . '/../../data/media';
- $this->backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'wikiId' => wfWikiId(),
- 'containerPaths' => array( 'data' => $this->filePath )
- ) );
- $this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
- 'backend' => $this->backend
- ) );
$this->handler = new GIFHandler();
}
),
);
}
-
- private function dataFile( $name, $type ) {
- return new UnregisteredLocalFile( false, $this->repo,
- "mwstore://localtesting/data/$name", $type );
- }
}
/**
* @covers JpegHandler
*/
-class JpegTest extends MediaWikiTestCase {
-
- protected $filePath;
+class JpegTest extends MediaWikiMediaTestCase {
protected function setUp() {
parent::setUp();
$this->checkPHPExtension( 'exif' );
- $this->filePath = __DIR__ . '/../../data/media/';
-
$this->setMwGlobals( 'wgShowEXIF', true );
- $this->backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'wikiId' => wfWikiId(),
- 'containerPaths' => array( 'data' => $this->filePath )
- ) );
- $this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
- 'backend' => $this->backend
- ) );
-
$this->handler = new JpegHandler;
}
$this->assertEquals( $res, $expected );
}
-
- private function dataFile( $name, $type ) {
- return new UnregisteredLocalFile( false, $this->repo,
- "mwstore://localtesting/data/$name", $type );
- }
}
--- /dev/null
+<?php
+/**
+ * Specificly for testing Media handlers. Sets up a FSFile backend
+ */
+abstract class MediaWikiMediaTestCase extends MediaWikiTestCase {
+
+ /** @var FSRepo */
+ protected $repo;
+ /** @var FSFileBackend */
+ protected $backend;
+ /** @var string */
+ protected $filePath;
+
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->filePath = $this->getFilePath();
+ $containers = array( 'data' => $this->filePath );
+ if ( $this->createsThumbnails() ) {
+ // We need a temp directory for the thumbnails
+ // the container is named 'temp-thumb' because it is the
+ // thumb directory for a FSRepo named "temp".
+ $containers['temp-thumb'] = $this->getNewTempDirectory();
+ }
+
+ $this->backend = new FSFileBackend( array(
+ 'name' => 'localtesting',
+ 'wikiId' => wfWikiId(),
+ 'containerPaths' => $containers
+ ) );
+ $this->repo = new FSRepo( array(
+ 'name' => 'temp',
+ 'url' => 'http://localhost/thumbtest',
+ 'backend' => $this->backend
+ ) );
+ }
+
+ /**
+ * The result of this method will set the file path to use,
+ * as well as the protected member $filePath
+ *
+ * @return String path where files are
+ */
+ protected function getFilePath() {
+ return __DIR__ . '/../../data/media/';
+ }
+
+ /**
+ * Will the test create thumbnails (and thus do we need to set aside
+ * a temporary directory for them?)
+ *
+ * Override this method if your test case creates thumbnails
+ *
+ * @return boolean
+ */
+ protected function createsThumbnails() {
+ return false;
+ }
+
+ /**
+ * Utility function: Get a new file object for a file on disk but not actually in db.
+ *
+ * File must be in the path returned by getFilePath()
+ * @param $name String File name
+ * @param $type String MIME type
+ * @return UnregisteredLocalFile
+ */
+ protected function dataFile( $name, $type ) {
+ return new UnregisteredLocalFile( false, $this->repo,
+ "mwstore://localtesting/data/$name", $type );
+ }
+}
<?php
-class PNGHandlerTest extends MediaWikiTestCase {
+class PNGHandlerTest extends MediaWikiMediaTestCase {
/** @var PNGHandler */
protected $handler;
- /** @var FSRepo */
- protected $repo;
- /** @var FSFileBackend */
- protected $backend;
- /** @var string */
- protected $filePath;
protected function setUp() {
parent::setUp();
-
- $this->filePath = __DIR__ . '/../../data/media';
- $this->backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'wikiId' => wfWikiId(),
- 'containerPaths' => array( 'data' => $this->filePath )
- ) );
- $this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
- 'backend' => $this->backend
- ) );
$this->handler = new PNGHandler();
}
),
);
}
-
- private function dataFile( $name, $type ) {
- return new UnregisteredLocalFile( false, $this->repo,
- "mwstore://localtesting/data/$name", $type );
- }
}
<?php
-class SvgTest extends MediaWikiTestCase {
+class SvgTest extends MediaWikiMediaTestCase {
protected function setUp() {
parent::setUp();
$this->setMwGlobals( 'wgShowEXIF', true );
- $this->backend = new FSFileBackend( array(
- 'name' => 'localtesting',
- 'wikiId' => wfWikiId(),
- 'containerPaths' => array( 'data' => $this->filePath )
- ) );
- $this->repo = new FSRepo( array(
- 'name' => 'temp',
- 'url' => 'http://localhost/thumbtest',
- 'backend' => $this->backend
- ) );
-
$this->handler = new SvgHandler;
}
array( 'Wikimedia-logo.svg', array() )
);
}
-
- private function dataFile( $name, $type ) {
- return new UnregisteredLocalFile( false, $this->repo,
- "mwstore://localtesting/data/$name", $type );
- }
}
'ApiQueryTestBase',
'ApiQueryContinueTestBase',
'MediaWikiLangTestCase',
+ 'MediaWikiMediaTestCase',
'MediaWikiTestCase',
'ResourceLoaderTestCase',
'PHPUnit_Framework_TestCase',