4 * These tests should work regardless of $wgCapitalLinks
6 * @todo Split tests into providers and test methods
9 class LocalFileTest
extends MediaWikiTestCase
{
11 protected function setUp() {
14 $this->setMwGlobals( 'wgCapitalLinks', true );
18 'directory' => '/testdir',
21 'transformVia404' => false,
22 'backend' => new FSFileBackend( array(
23 'name' => 'local-backend',
24 'wikiId' => wfWikiId(),
25 'containerPaths' => array(
26 'cont1' => "/testdir/local-backend/tempimages/cont1",
27 'cont2' => "/testdir/local-backend/tempimages/cont2"
31 $this->repo_hl0
= new LocalRepo( array( 'hashLevels' => 0 ) +
$info );
32 $this->repo_hl2
= new LocalRepo( array( 'hashLevels' => 2 ) +
$info );
33 $this->repo_lc
= new LocalRepo( array( 'initialCapital' => false ) +
$info );
34 $this->file_hl0
= $this->repo_hl0
->newFile( 'test!' );
35 $this->file_hl2
= $this->repo_hl2
->newFile( 'test!' );
36 $this->file_lc
= $this->repo_lc
->newFile( 'test!' );
40 * @covers File::getHashPath
42 public function testGetHashPath() {
43 $this->assertEquals( '', $this->file_hl0
->getHashPath() );
44 $this->assertEquals( 'a/a2/', $this->file_hl2
->getHashPath() );
45 $this->assertEquals( 'c/c4/', $this->file_lc
->getHashPath() );
49 * @covers File::getRel
51 public function testGetRel() {
52 $this->assertEquals( 'Test!', $this->file_hl0
->getRel() );
53 $this->assertEquals( 'a/a2/Test!', $this->file_hl2
->getRel() );
54 $this->assertEquals( 'c/c4/test!', $this->file_lc
->getRel() );
58 * @covers File::getUrlRel
60 public function testGetUrlRel() {
61 $this->assertEquals( 'Test%21', $this->file_hl0
->getUrlRel() );
62 $this->assertEquals( 'a/a2/Test%21', $this->file_hl2
->getUrlRel() );
63 $this->assertEquals( 'c/c4/test%21', $this->file_lc
->getUrlRel() );
67 * @covers File::getArchivePath
69 public function testGetArchivePath() {
71 'mwstore://local-backend/test-public/archive',
72 $this->file_hl0
->getArchivePath()
75 'mwstore://local-backend/test-public/archive/a/a2',
76 $this->file_hl2
->getArchivePath()
79 'mwstore://local-backend/test-public/archive/!',
80 $this->file_hl0
->getArchivePath( '!' )
83 'mwstore://local-backend/test-public/archive/a/a2/!',
84 $this->file_hl2
->getArchivePath( '!' )
89 * @covers File::getThumbPath
91 public function testGetThumbPath() {
93 'mwstore://local-backend/test-thumb/Test!',
94 $this->file_hl0
->getThumbPath()
97 'mwstore://local-backend/test-thumb/a/a2/Test!',
98 $this->file_hl2
->getThumbPath()
101 'mwstore://local-backend/test-thumb/Test!/x',
102 $this->file_hl0
->getThumbPath( 'x' )
105 'mwstore://local-backend/test-thumb/a/a2/Test!/x',
106 $this->file_hl2
->getThumbPath( 'x' )
111 * @covers File::getArchiveUrl
113 public function testGetArchiveUrl() {
114 $this->assertEquals( '/testurl/archive', $this->file_hl0
->getArchiveUrl() );
115 $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2
->getArchiveUrl() );
116 $this->assertEquals( '/testurl/archive/%21', $this->file_hl0
->getArchiveUrl( '!' ) );
117 $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2
->getArchiveUrl( '!' ) );
121 * @covers File::getThumbUrl
123 public function testGetThumbUrl() {
124 $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0
->getThumbUrl() );
125 $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2
->getThumbUrl() );
126 $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0
->getThumbUrl( 'x' ) );
127 $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2
->getThumbUrl( 'x' ) );
131 * @covers File::getArchiveVirtualUrl
133 public function testGetArchiveVirtualUrl() {
134 $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0
->getArchiveVirtualUrl() );
136 'mwrepo://test/public/archive/a/a2',
137 $this->file_hl2
->getArchiveVirtualUrl()
140 'mwrepo://test/public/archive/%21',
141 $this->file_hl0
->getArchiveVirtualUrl( '!' )
144 'mwrepo://test/public/archive/a/a2/%21',
145 $this->file_hl2
->getArchiveVirtualUrl( '!' )
150 * @covers File::getThumbVirtualUrl
152 public function testGetThumbVirtualUrl() {
153 $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0
->getThumbVirtualUrl() );
154 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2
->getThumbVirtualUrl() );
156 'mwrepo://test/thumb/Test%21/%21',
157 $this->file_hl0
->getThumbVirtualUrl( '!' )
160 'mwrepo://test/thumb/a/a2/Test%21/%21',
161 $this->file_hl2
->getThumbVirtualUrl( '!' )
166 * @covers File::getUrl
168 public function testGetUrl() {
169 $this->assertEquals( '/testurl/Test%21', $this->file_hl0
->getUrl() );
170 $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2
->getUrl() );
174 * @covers ::wfLocalFile
176 public function testWfLocalFile() {
177 $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
180 $this->isInstanceOf( 'LocalFile' ),
181 'wfLocalFile() returns LocalFile for valid Titles'