Pass phpcs-strict on some test files (3/x)
[lhc/web/wiklou.git] / tests / phpunit / includes / LocalFileTest.php
1 <?php
2
3 /**
4 * These tests should work regardless of $wgCapitalLinks
5 * @group Database
6 * @todo Split tests into providers and test methods
7 */
8
9 class LocalFileTest extends MediaWikiTestCase {
10
11 protected function setUp() {
12 parent::setUp();
13
14 $this->setMwGlobals( 'wgCapitalLinks', true );
15
16 $info = array(
17 'name' => 'test',
18 'directory' => '/testdir',
19 'url' => '/testurl',
20 'hashLevels' => 2,
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"
28 )
29 ) )
30 );
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!' );
37 }
38
39 /**
40 * @covers File::getHashPath
41 */
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() );
46 }
47
48 /**
49 * @covers File::getRel
50 */
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() );
55 }
56
57 /**
58 * @covers File::getUrlRel
59 */
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() );
64 }
65
66 /**
67 * @covers File::getArchivePath
68 */
69 public function testGetArchivePath() {
70 $this->assertEquals(
71 'mwstore://local-backend/test-public/archive',
72 $this->file_hl0->getArchivePath()
73 );
74 $this->assertEquals(
75 'mwstore://local-backend/test-public/archive/a/a2',
76 $this->file_hl2->getArchivePath()
77 );
78 $this->assertEquals(
79 'mwstore://local-backend/test-public/archive/!',
80 $this->file_hl0->getArchivePath( '!' )
81 );
82 $this->assertEquals(
83 'mwstore://local-backend/test-public/archive/a/a2/!',
84 $this->file_hl2->getArchivePath( '!' )
85 );
86 }
87
88 /**
89 * @covers File::getThumbPath
90 */
91 public function testGetThumbPath() {
92 $this->assertEquals(
93 'mwstore://local-backend/test-thumb/Test!',
94 $this->file_hl0->getThumbPath()
95 );
96 $this->assertEquals(
97 'mwstore://local-backend/test-thumb/a/a2/Test!',
98 $this->file_hl2->getThumbPath()
99 );
100 $this->assertEquals(
101 'mwstore://local-backend/test-thumb/Test!/x',
102 $this->file_hl0->getThumbPath( 'x' )
103 );
104 $this->assertEquals(
105 'mwstore://local-backend/test-thumb/a/a2/Test!/x',
106 $this->file_hl2->getThumbPath( 'x' )
107 );
108 }
109
110 /**
111 * @covers File::getArchiveUrl
112 */
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( '!' ) );
118 }
119
120 /**
121 * @covers File::getThumbUrl
122 */
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' ) );
128 }
129
130 /**
131 * @covers File::getArchiveVirtualUrl
132 */
133 public function testGetArchiveVirtualUrl() {
134 $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
135 $this->assertEquals(
136 'mwrepo://test/public/archive/a/a2',
137 $this->file_hl2->getArchiveVirtualUrl()
138 );
139 $this->assertEquals(
140 'mwrepo://test/public/archive/%21',
141 $this->file_hl0->getArchiveVirtualUrl( '!' )
142 );
143 $this->assertEquals(
144 'mwrepo://test/public/archive/a/a2/%21',
145 $this->file_hl2->getArchiveVirtualUrl( '!' )
146 );
147 }
148
149 /**
150 * @covers File::getThumbVirtualUrl
151 */
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() );
155 $this->assertEquals(
156 'mwrepo://test/thumb/Test%21/%21',
157 $this->file_hl0->getThumbVirtualUrl( '!' )
158 );
159 $this->assertEquals(
160 'mwrepo://test/thumb/a/a2/Test%21/%21',
161 $this->file_hl2->getThumbVirtualUrl( '!' )
162 );
163 }
164
165 /**
166 * @covers File::getUrl
167 */
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() );
171 }
172
173 /**
174 * @covers ::wfLocalFile
175 */
176 public function testWfLocalFile() {
177 $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
178 $this->assertThat(
179 $file,
180 $this->isInstanceOf( 'LocalFile' ),
181 'wfLocalFile() returns LocalFile for valid Titles'
182 );
183 }
184 }