Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / media / MediaWikiMediaTestCase.php
blobcb10be3d27dcac4e639ec99b29c512241e17ecdb
1 <?php
2 /**
3 * Specificly for testing Media handlers. Sets up a FSFile backend
4 */
5 abstract class MediaWikiMediaTestCase extends MediaWikiTestCase {
7 /** @var FSRepo */
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 = 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
30 ) );
31 $this->repo = new FSRepo( $this->getRepoOptions() );
34 /**
35 * @return array Argument for FSRepo constructor
37 protected function getRepoOptions() {
38 return array(
39 'name' => 'temp',
40 'url' => 'http://localhost/thumbtest',
41 'backend' => $this->backend
45 /**
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/';
55 /**
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
61 * @return bool
63 protected function createsThumbnails() {
64 return false;
67 /**
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 ) {
76 if ( !$type ) {
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 );