3 * Specificly for testing Media handlers. Sets up a FileRepo backend
5 abstract class MediaWikiMediaTestCase
extends MediaWikiTestCase
{
9 /** @var FSFileBackend */
14 protected function setUp() {
17 $this->filePath
= $this->getFilePath();
18 $containers = [ '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 repo named "temp".
23 $containers['temp-thumb'] = $this->getNewTempDirectory();
26 $this->backend
= new FSFileBackend( [
27 'name' => 'localtesting',
28 'wikiId' => wfWikiID(),
29 'containerPaths' => $containers,
30 'tmpDirectory' => $this->getNewTempDirectory()
32 $this->repo
= new FileRepo( $this->getRepoOptions() );
36 * @return array Argument for FileRepo 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 );