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