MediaWiki
REL1_19
|
00001 <?php 00002 00008 class LocalFileTest extends MediaWikiTestCase { 00009 function setUp() { 00010 global $wgCapitalLinks; 00011 00012 $wgCapitalLinks = true; 00013 00014 $info = array( 00015 'name' => 'test', 00016 'directory' => '/testdir', 00017 'url' => '/testurl', 00018 'hashLevels' => 2, 00019 'transformVia404' => false, 00020 'backend' => new FSFileBackend( array( 00021 'name' => 'local-backend', 00022 'lockManager' => 'fsLockManager', 00023 'containerPaths' => array( 00024 'cont1' => "/testdir/local-backend/tempimages/cont1", 00025 'cont2' => "/testdir/local-backend/tempimages/cont2" 00026 ) 00027 ) ) 00028 ); 00029 $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info ); 00030 $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info ); 00031 $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info ); 00032 $this->file_hl0 = $this->repo_hl0->newFile( 'test!' ); 00033 $this->file_hl2 = $this->repo_hl2->newFile( 'test!' ); 00034 $this->file_lc = $this->repo_lc->newFile( 'test!' ); 00035 } 00036 00037 function testGetHashPath() { 00038 $this->assertEquals( '', $this->file_hl0->getHashPath() ); 00039 $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() ); 00040 $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() ); 00041 } 00042 00043 function testGetRel() { 00044 $this->assertEquals( 'Test!', $this->file_hl0->getRel() ); 00045 $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() ); 00046 $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() ); 00047 } 00048 00049 function testGetUrlRel() { 00050 $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() ); 00051 $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() ); 00052 $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() ); 00053 } 00054 00055 function testGetArchivePath() { 00056 $this->assertEquals( 'mwstore://local-backend/test-public/archive', $this->file_hl0->getArchivePath() ); 00057 $this->assertEquals( 'mwstore://local-backend/test-public/archive/a/a2', $this->file_hl2->getArchivePath() ); 00058 $this->assertEquals( 'mwstore://local-backend/test-public/archive/!', $this->file_hl0->getArchivePath( '!' ) ); 00059 $this->assertEquals( 'mwstore://local-backend/test-public/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) ); 00060 } 00061 00062 function testGetThumbPath() { 00063 $this->assertEquals( 'mwstore://local-backend/test-thumb/Test!', $this->file_hl0->getThumbPath() ); 00064 $this->assertEquals( 'mwstore://local-backend/test-thumb/a/a2/Test!', $this->file_hl2->getThumbPath() ); 00065 $this->assertEquals( 'mwstore://local-backend/test-thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) ); 00066 $this->assertEquals( 'mwstore://local-backend/test-thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) ); 00067 } 00068 00069 function testGetArchiveUrl() { 00070 $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() ); 00071 $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() ); 00072 $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) ); 00073 $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) ); 00074 } 00075 00076 function testGetThumbUrl() { 00077 $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() ); 00078 $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() ); 00079 $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) ); 00080 $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) ); 00081 } 00082 00083 function testGetArchiveVirtualUrl() { 00084 $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() ); 00085 $this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() ); 00086 $this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) ); 00087 $this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) ); 00088 } 00089 00090 function testGetThumbVirtualUrl() { 00091 $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() ); 00092 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() ); 00093 $this->assertEquals( 'mwrepo://test/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) ); 00094 $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) ); 00095 } 00096 00097 function testGetUrl() { 00098 $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() ); 00099 $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() ); 00100 } 00101 00102 function testWfLocalFile() { 00103 $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" ); 00104 $this->assertThat( $file, $this->isInstanceOf( 'LocalFile' ), 'wfLocalFile() returns LocalFile for valid Titles' ); 00105 } 00106 } 00107 00108