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