4 * These tests should work regardless of $wgCapitalLinks
8 class LocalFileTest
extends MediaWikiTestCase
{
10 global $wgCapitalLinks;
12 $wgCapitalLinks = true;
16 'directory' => '/testdir',
19 'transformVia404' => false,
20 'backend' => new FSFileBackend( array(
21 'name' => 'local-backend',
22 'lockManager' => 'fsLockManager',
23 'containerPaths' => array(
24 'cont1' => "/testdir/local-backend/tempimages/cont1",
25 'cont2' => "/testdir/local-backend/tempimages/cont2"
29 $this->repo_hl0
= new LocalRepo( array( 'hashLevels' => 0 ) +
$info );
30 $this->repo_hl2
= new LocalRepo( array( 'hashLevels' => 2 ) +
$info );
31 $this->repo_lc
= new LocalRepo( array( 'initialCapital' => false ) +
$info );
32 $this->file_hl0
= $this->repo_hl0
->newFile( 'test!' );
33 $this->file_hl2
= $this->repo_hl2
->newFile( 'test!' );
34 $this->file_lc
= $this->repo_lc
->newFile( 'test!' );
37 function testGetHashPath() {
38 $this->assertEquals( '', $this->file_hl0
->getHashPath() );
39 $this->assertEquals( 'a/a2/', $this->file_hl2
->getHashPath() );
40 $this->assertEquals( 'c/c4/', $this->file_lc
->getHashPath() );
43 function testGetRel() {
44 $this->assertEquals( 'Test!', $this->file_hl0
->getRel() );
45 $this->assertEquals( 'a/a2/Test!', $this->file_hl2
->getRel() );
46 $this->assertEquals( 'c/c4/test!', $this->file_lc
->getRel() );
49 function testGetUrlRel() {
50 $this->assertEquals( 'Test%21', $this->file_hl0
->getUrlRel() );
51 $this->assertEquals( 'a/a2/Test%21', $this->file_hl2
->getUrlRel() );
52 $this->assertEquals( 'c/c4/test%21', $this->file_lc
->getUrlRel() );
55 function testGetArchivePath() {
56 $this->assertEquals( 'mwstore://local-backend/test-public/archive', $this->file_hl0
->getArchivePath() );
57 $this->assertEquals( 'mwstore://local-backend/test-public/archive/a/a2', $this->file_hl2
->getArchivePath() );
58 $this->assertEquals( 'mwstore://local-backend/test-public/archive/!', $this->file_hl0
->getArchivePath( '!' ) );
59 $this->assertEquals( 'mwstore://local-backend/test-public/archive/a/a2/!', $this->file_hl2
->getArchivePath( '!' ) );
62 function testGetThumbPath() {
63 $this->assertEquals( 'mwstore://local-backend/test-thumb/Test!', $this->file_hl0
->getThumbPath() );
64 $this->assertEquals( 'mwstore://local-backend/test-thumb/a/a2/Test!', $this->file_hl2
->getThumbPath() );
65 $this->assertEquals( 'mwstore://local-backend/test-thumb/Test!/x', $this->file_hl0
->getThumbPath( 'x' ) );
66 $this->assertEquals( 'mwstore://local-backend/test-thumb/a/a2/Test!/x', $this->file_hl2
->getThumbPath( 'x' ) );
69 function testGetArchiveUrl() {
70 $this->assertEquals( '/testurl/archive', $this->file_hl0
->getArchiveUrl() );
71 $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2
->getArchiveUrl() );
72 $this->assertEquals( '/testurl/archive/%21', $this->file_hl0
->getArchiveUrl( '!' ) );
73 $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2
->getArchiveUrl( '!' ) );
76 function testGetThumbUrl() {
77 $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0
->getThumbUrl() );
78 $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2
->getThumbUrl() );
79 $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0
->getThumbUrl( 'x' ) );
80 $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2
->getThumbUrl( 'x' ) );
83 function testGetArchiveVirtualUrl() {
84 $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0
->getArchiveVirtualUrl() );
85 $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2
->getArchiveVirtualUrl() );
86 $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0
->getArchiveVirtualUrl( '!' ) );
87 $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2
->getArchiveVirtualUrl( '!' ) );
90 function testGetThumbVirtualUrl() {
91 $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0
->getThumbVirtualUrl() );
92 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2
->getThumbVirtualUrl() );
93 $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0
->getThumbVirtualUrl( '!' ) );
94 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2
->getThumbVirtualUrl( '!' ) );
97 function testGetUrl() {
98 $this->assertEquals( '/testurl/Test%21', $this->file_hl0
->getUrl() );
99 $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2
->getUrl() );
102 function testWfLocalFile() {
103 $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
104 $this->assertThat( $file, $this->isInstanceOf( 'LocalFile' ), 'wfLocalFile() returns LocalFile for valid Titles' );