MediaWiki  REL1_24
LocalFileTest.php
Go to the documentation of this file.
00001 <?php
00002 
00009 class LocalFileTest extends MediaWikiTestCase {
00010 
00011     protected function setUp() {
00012         parent::setUp();
00013 
00014         $this->setMwGlobals( 'wgCapitalLinks', true );
00015 
00016         $info = array(
00017             'name' => 'test',
00018             'directory' => '/testdir',
00019             'url' => '/testurl',
00020             'hashLevels' => 2,
00021             'transformVia404' => false,
00022             'backend' => new FSFileBackend( array(
00023                 'name' => 'local-backend',
00024                 'wikiId' => wfWikiId(),
00025                 'containerPaths' => array(
00026                     'cont1' => "/testdir/local-backend/tempimages/cont1",
00027                     'cont2' => "/testdir/local-backend/tempimages/cont2"
00028                 )
00029             ) )
00030         );
00031         $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
00032         $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
00033         $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
00034         $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
00035         $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
00036         $this->file_lc = $this->repo_lc->newFile( 'test!' );
00037     }
00038 
00042     public function testGetHashPath() {
00043         $this->assertEquals( '', $this->file_hl0->getHashPath() );
00044         $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
00045         $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
00046     }
00047 
00051     public function testGetRel() {
00052         $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
00053         $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
00054         $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
00055     }
00056 
00060     public function testGetUrlRel() {
00061         $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
00062         $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
00063         $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
00064     }
00065 
00069     public function testGetArchivePath() {
00070         $this->assertEquals(
00071             'mwstore://local-backend/test-public/archive',
00072             $this->file_hl0->getArchivePath()
00073         );
00074         $this->assertEquals(
00075             'mwstore://local-backend/test-public/archive/a/a2',
00076             $this->file_hl2->getArchivePath()
00077         );
00078         $this->assertEquals(
00079             'mwstore://local-backend/test-public/archive/!',
00080             $this->file_hl0->getArchivePath( '!' )
00081         );
00082         $this->assertEquals(
00083             'mwstore://local-backend/test-public/archive/a/a2/!',
00084             $this->file_hl2->getArchivePath( '!' )
00085         );
00086     }
00087 
00091     public function testGetThumbPath() {
00092         $this->assertEquals(
00093             'mwstore://local-backend/test-thumb/Test!',
00094             $this->file_hl0->getThumbPath()
00095         );
00096         $this->assertEquals(
00097             'mwstore://local-backend/test-thumb/a/a2/Test!',
00098             $this->file_hl2->getThumbPath()
00099         );
00100         $this->assertEquals(
00101             'mwstore://local-backend/test-thumb/Test!/x',
00102             $this->file_hl0->getThumbPath( 'x' )
00103         );
00104         $this->assertEquals(
00105             'mwstore://local-backend/test-thumb/a/a2/Test!/x',
00106             $this->file_hl2->getThumbPath( 'x' )
00107         );
00108     }
00109 
00113     public function testGetArchiveUrl() {
00114         $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
00115         $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
00116         $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
00117         $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
00118     }
00119 
00123     public function testGetThumbUrl() {
00124         $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
00125         $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
00126         $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
00127         $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
00128     }
00129 
00133     public function testGetArchiveVirtualUrl() {
00134         $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
00135         $this->assertEquals(
00136             'mwrepo://test/public/archive/a/a2',
00137             $this->file_hl2->getArchiveVirtualUrl()
00138         );
00139         $this->assertEquals(
00140             'mwrepo://test/public/archive/%21',
00141             $this->file_hl0->getArchiveVirtualUrl( '!' )
00142         );
00143         $this->assertEquals(
00144             'mwrepo://test/public/archive/a/a2/%21',
00145             $this->file_hl2->getArchiveVirtualUrl( '!' )
00146         );
00147     }
00148 
00152     public function testGetThumbVirtualUrl() {
00153         $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
00154         $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
00155         $this->assertEquals(
00156             'mwrepo://test/thumb/Test%21/%21',
00157             $this->file_hl0->getThumbVirtualUrl( '!' )
00158         );
00159         $this->assertEquals(
00160             'mwrepo://test/thumb/a/a2/Test%21/%21',
00161             $this->file_hl2->getThumbVirtualUrl( '!' )
00162         );
00163     }
00164 
00168     public function testGetUrl() {
00169         $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
00170         $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
00171     }
00172 
00176     public function testWfLocalFile() {
00177         $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
00178         $this->assertThat(
00179             $file,
00180             $this->isInstanceOf( 'LocalFile' ),
00181             'wfLocalFile() returns LocalFile for valid Titles'
00182         );
00183     }
00184 }