3 * Specificly for testing Media handlers. Sets up a FSFile backend
5 abstract class MediaWikiMediaTestCase
extends MediaWikiTestCase
{
9 /** @var FSFileBackend */
15 protected function setUp() {
18 $this->filePath
= $this->getFilePath();
19 $containers = array( 'data' => $this->filePath
);
20 if ( $this->createsThumbnails() ) {
21 // We need a temp directory for the thumbnails
22 // the container is named 'temp-thumb' because it is the
23 // thumb directory for a FSRepo named "temp".
24 $containers['temp-thumb'] = $this->getNewTempDirectory();
27 $this->backend
= new FSFileBackend( array(
28 'name' => 'localtesting',
29 'wikiId' => wfWikiId(),
30 'containerPaths' => $containers
32 $this->repo
= new FSRepo( $this->getRepoOptions() );
36 * @return array Argument for FSRepo constructor
38 protected function getRepoOptions() {
41 'url' => 'http://localhost/thumbtest',
42 'backend' => $this->backend
47 * The result of this method will set the file path to use,
48 * as well as the protected member $filePath
50 * @return string Path where files are
52 protected function getFilePath() {
53 return __DIR__
. '/../../data/media/';
57 * Will the test create thumbnails (and thus do we need to set aside
58 * a temporary directory for them?)
60 * Override this method if your test case creates thumbnails
64 protected function createsThumbnails() {
69 * Utility function: Get a new file object for a file on disk but not actually in db.
71 * File must be in the path returned by getFilePath()
72 * @param string $name File name
73 * @param string $type MIME type [optional]
74 * @return UnregisteredLocalFile
76 protected function dataFile( $name, $type = null ) {
78 // Autodetect by file extension for the lazy.
79 $magic = MimeMagic
::singleton();
80 $parts = explode( $name, '.' );
81 $type = $magic->guessTypesForExtension( $parts[count( $parts ) - 1] );
83 return new UnregisteredLocalFile( false, $this->repo
,
84 "mwstore://localtesting/data/$name", $type );