Merge "Revert "Add .gitignore to the /skins directory""
[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( 'mwstore://local-backend/test-public/archive', $this->file_hl0->getArchivePath() );
71 $this->assertEquals( 'mwstore://local-backend/test-public/archive/a/a2', $this->file_hl2->getArchivePath() );
72 $this->assertEquals( 'mwstore://local-backend/test-public/archive/!', $this->file_hl0->getArchivePath( '!' ) );
73 $this->assertEquals( 'mwstore://local-backend/test-public/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
74 }
75
76 /**
77 * @covers File::getThumbPath
78 */
79 public function testGetThumbPath() {
80 $this->assertEquals( 'mwstore://local-backend/test-thumb/Test!', $this->file_hl0->getThumbPath() );
81 $this->assertEquals( 'mwstore://local-backend/test-thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
82 $this->assertEquals( 'mwstore://local-backend/test-thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
83 $this->assertEquals( 'mwstore://local-backend/test-thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
84 }
85
86 /**
87 * @covers File::getArchiveUrl
88 */
89 public function testGetArchiveUrl() {
90 $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
91 $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
92 $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
93 $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
94 }
95
96 /**
97 * @covers File::getThumbUrl
98 */
99 public function testGetThumbUrl() {
100 $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
101 $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
102 $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
103 $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
104 }
105
106 /**
107 * @covers File::getArchiveVirtualUrl
108 */
109 public function testGetArchiveVirtualUrl() {
110 $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
111 $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
112 $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
113 $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
114 }
115
116 /**
117 * @covers File::getThumbVirtualUrl
118 */
119 public function testGetThumbVirtualUrl() {
120 $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
121 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
122 $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
123 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
124 }
125
126 /**
127 * @covers File::getUrl
128 */
129 public function testGetUrl() {
130 $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
131 $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
132 }
133
134 /**
135 * @covers ::wfLocalFile
136 */
137 public function testWfLocalFile() {
138 $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
139 $this->assertThat( $file, $this->isInstanceOf( 'LocalFile' ), 'wfLocalFile() returns LocalFile for valid Titles' );
140 }
141 }