rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / media / MediaWikiMediaTestCase.php
blob196f688219d9c087d608bcc9e0c60f751dfb80fe
1 <?php
2 /**
3 * Specificly for testing Media handlers. Sets up a FileRepo backend
4 */
5 abstract class MediaWikiMediaTestCase extends MediaWikiTestCase {
7 /** @var FileRepo */
8 protected $repo;
9 /** @var FSFileBackend */
10 protected $backend;
11 /** @var string */
12 protected $filePath;
14 protected function setUp() {
15 parent::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()
31 ] );
32 $this->repo = new FileRepo( $this->getRepoOptions() );
35 /**
36 * @return array Argument for FileRepo constructor
38 protected function getRepoOptions() {
39 return [
40 'name' => 'temp',
41 'url' => 'http://localhost/thumbtest',
42 'backend' => $this->backend
46 /**
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/';
56 /**
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
62 * @return bool
64 protected function createsThumbnails() {
65 return false;
68 /**
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 ) {
77 if ( !$type ) {
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 );