* (bug 27353) IPv6 address ending in "::WORD" was not recognized
[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 */
7
8 class LocalFileTest extends MediaWikiTestCase {
9 function setUp() {
10 global $wgContLang, $wgCapitalLinks;
11
12 $wgContLang = new Language;
13 $wgCapitalLinks = true;
14 $info = array(
15 'name' => 'test',
16 'directory' => '/testdir',
17 'url' => '/testurl',
18 'hashLevels' => 2,
19 'transformVia404' => false,
20 );
21 $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
22 $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
23 $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
24 $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
25 $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
26 $this->file_lc = $this->repo_lc->newFile( 'test!' );
27 }
28
29 function testGetHashPath() {
30 $this->assertEquals( '', $this->file_hl0->getHashPath() );
31 $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
32 $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
33 }
34
35 function testGetRel() {
36 $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
37 $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
38 $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
39 }
40
41 function testGetUrlRel() {
42 $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
43 $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
44 $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
45 }
46
47 function testGetArchivePath() {
48 $this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
49 $this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
50 $this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
51 $this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
52 }
53
54 function testGetThumbPath() {
55 $this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
56 $this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
57 $this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
58 $this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
59 }
60
61 function testGetArchiveUrl() {
62 $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
63 $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
64 $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
65 $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
66 }
67
68 function testGetThumbUrl() {
69 $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
70 $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
71 $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
72 $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
73 }
74
75 function testGetArchiveVirtualUrl() {
76 $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
77 $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
78 $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
79 $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
80 }
81
82 function testGetThumbVirtualUrl() {
83 $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
84 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
85 $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
86 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
87 }
88
89 function testGetUrl() {
90 $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
91 $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
92 }
93
94 function testWfLocalFile() {
95 $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
96 $this->assertThat( $file, $this->isInstanceOf( 'LocalFile' ), 'wfLocalFile() returns LocalFile for valid Titles' );
97 }
98 }
99
100