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