Merge "Added --lastUpdatedId option to backlink namespace population script"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / MediaWikiMediaTestCase.php
1 <?php
2 /**
3 * Specificly for testing Media handlers. Sets up a FSFile backend
4 */
5 abstract class MediaWikiMediaTestCase extends MediaWikiTestCase {
6
7 /** @var FSRepo */
8 protected $repo;
9 /** @var FSFileBackend */
10 protected $backend;
11 /** @var string */
12 protected $filePath;
13
14
15 protected function setUp() {
16 parent::setUp();
17
18 $this->filePath = $this->getFilePath();
19 $containers = array( 'data' => $this->filePath );
20 if ( $this->createsThumbnails() ) {
21 // We need a temp directory for the thumbnails
22 // the container is named 'temp-thumb' because it is the
23 // thumb directory for a FSRepo named "temp".
24 $containers['temp-thumb'] = $this->getNewTempDirectory();
25 }
26
27 $this->backend = new FSFileBackend( array(
28 'name' => 'localtesting',
29 'wikiId' => wfWikiId(),
30 'containerPaths' => $containers
31 ) );
32 $this->repo = new FSRepo( $this->getRepoOptions() );
33 }
34
35 /**
36 * @return Array Argument for FSRepo constructor
37 */
38 protected function getRepoOptions() {
39 return array(
40 'name' => 'temp',
41 'url' => 'http://localhost/thumbtest',
42 'backend' => $this->backend
43 );
44 }
45
46 /**
47 * The result of this method will set the file path to use,
48 * as well as the protected member $filePath
49 *
50 * @return String path where files are
51 */
52 protected function getFilePath() {
53 return __DIR__ . '/../../data/media/';
54 }
55
56 /**
57 * Will the test create thumbnails (and thus do we need to set aside
58 * a temporary directory for them?)
59 *
60 * Override this method if your test case creates thumbnails
61 *
62 * @return boolean
63 */
64 protected function createsThumbnails() {
65 return false;
66 }
67
68 /**
69 * Utility function: Get a new file object for a file on disk but not actually in db.
70 *
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
75 */
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] );
82 }
83 return new UnregisteredLocalFile( false, $this->repo,
84 "mwstore://localtesting/data/$name", $type );
85 }
86 }