]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/tests/LocalFileTest.php
MediaWiki 1.16.0
[autoinstalls/mediawiki.git] / maintenance / tests / LocalFileTest.php
1 <?php
2
3 /**
4  * These tests should work regardless of $wgCapitalLinks
5  */
6
7 class LocalFileTest extends PHPUnit_Framework_TestCase {
8         function setUp() {
9                 global $wgContLang;
10                 $wgContLang = new Language;
11                 $info = array(
12                         'name' => 'test',
13                         'directory' => '/testdir',
14                         'url' => '/testurl',
15                         'hashLevels' => 2,
16                         'transformVia404' => false,
17                 );
18                 $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
19                 $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
20                 $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
21                 $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
22                 $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
23                 $this->file_lc = $this->repo_lc->newFile( 'test!' );
24         }
25
26         function tearDown() {
27                 global $wgContLang;
28                 unset($wgContLang);
29         }
30
31         function testGetHashPath() {
32                 $this->assertEquals( '', $this->file_hl0->getHashPath() );
33                 $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
34                 $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
35         }
36
37         function testGetRel() {
38                 $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
39                 $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
40                 $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
41         }
42
43         function testGetUrlRel() {
44                 $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
45                 $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
46                 $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
47         }
48
49         function testGetArchivePath() {
50                 $this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
51                 $this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
52                 $this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
53                 $this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
54         }
55
56         function testGetThumbPath() { 
57                 $this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
58                 $this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
59                 $this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
60                 $this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
61         }
62
63         function testGetArchiveUrl() {
64                 $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
65                 $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
66                 $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
67                 $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
68         }
69
70         function testGetThumbUrl() {
71                 $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
72                 $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
73                 $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
74                 $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
75         }
76
77         function testGetArchiveVirtualUrl() {
78                 $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
79                 $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
80                 $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
81                 $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
82         }
83
84         function testGetThumbVirtualUrl() {
85                 $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
86                 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
87                 $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
88                 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
89         }
90
91         function testGetUrl() {
92                 $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
93                 $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
94         }
95 }
96
97