Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / media / MediaWikiMediaTestCase.php
blobad967ac00a35630daa3c722d4e594f2f0d00a0ba
1 <?php
3 use MediaWiki\WikiMap\WikiMap;
4 use Wikimedia\FileBackend\FSFileBackend;
6 /**
7 * Specificly for testing Media handlers. Sets up a FileRepo backend
8 */
9 abstract class MediaWikiMediaTestCase extends MediaWikiIntegrationTestCase {
11 /** @var FileRepo */
12 protected $repo;
13 /** @var FSFileBackend */
14 protected $backend;
15 /** @var string */
16 protected $filePath;
18 protected function setUp(): void {
19 parent::setUp();
21 $this->filePath = $this->getFilePath();
22 $containers = [ 'data' => $this->filePath ];
23 if ( $this->createsThumbnails() ) {
24 // We need a temp directory for the thumbnails
25 // the container is named 'temp-thumb' because it is the
26 // thumb directory for a repo named "temp".
27 $containers['temp-thumb'] = $this->getNewTempDirectory();
30 $this->backend = new FSFileBackend( [
31 'name' => 'localtesting',
32 'wikiId' => WikiMap::getCurrentWikiId(),
33 'containerPaths' => $containers,
34 'tmpDirectory' => $this->getNewTempDirectory(),
35 'obResetFunc' => static function () {
36 // do nothing, we need the output buffer in tests
38 ] );
39 $this->repo = new FileRepo( $this->getRepoOptions() );
42 /**
43 * @return array Argument for FileRepo constructor
45 protected function getRepoOptions() {
46 return [
47 'name' => 'temp',
48 'url' => 'http://localhost/thumbtest',
49 'backend' => $this->backend
53 /**
54 * The result of this method will set the file path to use,
55 * as well as the protected member $filePath
57 * @return string Path where files are
59 protected function getFilePath() {
60 return __DIR__ . '/../../data/media/';
63 /**
64 * Will the test create thumbnails (and thus do we need to set aside
65 * a temporary directory for them?)
67 * Override this method if your test case creates thumbnails
69 * @return bool
71 protected function createsThumbnails() {
72 return false;
75 /**
76 * Utility function: Get a new file object for a file on disk but not actually in db.
78 * File must be in the path returned by getFilePath()
79 * @param string $name File name
80 * @param string|false $type MIME type [optional]
81 * @return UnregisteredLocalFile
83 protected function dataFile( $name, $type = false ) {
84 return new UnregisteredLocalFile( false, $this->repo,
85 "mwstore://localtesting/data/$name", $type );
88 /**
89 * Get a mock LocalFile with the specified metadata, specified as a
90 * serialized string. The metadata-related methods will return this
91 * metadata. The behaviour of the other methods is undefined.
93 * @since 1.37
94 * @param string $metadata
95 * @return LocalFile
97 protected function getMockFileWithMetadata( $metadata ) {
98 return new class( $metadata ) extends LocalFile {
99 public function __construct( $metadata ) {
100 $this->loadMetadataFromString( $metadata );
101 $this->dataLoaded = true;