wiki.techinc.nl/tests/LocalFileTest.php
Tim Starling 85fa7504e6 * Split off ultimate base class FileRepo from FSRepo
* Use rawurlencode() for paths instead of urlencode()
* Moved functionality of LocalFile::loadFromFile() to a public static function. This allows Special:Upload to entirely avoid loading metadata from the (potentially remote) store. Changed purgeMetadataCache() to use loadFromDB() instead of loadFromFile().
* Redefined private virtual URLs, giving them a repo name component instead of a host.
* Moved is_writable($wgUploadDirectory) in SpecialUpload.php to the repo
* Added some filename validation to the FSRepo's store/publish
* Changed store and publish to use relative destinations instead of absolute, as was documented
* Deprecated File::recordUpload()! Now use upload() to do both publish and record. Moved the UI bits to SpecialUpload.
* Create a null revision on reupload
* Changed most of the member variable names in UploadForm. $this->mUpload followed by some ambiguous word or abbreviation was not a good naming convention. Also did some reformatting and assorted code cleanup.
2007-06-16 02:55:25 +00:00

90 lines
4 KiB
PHP

<?php
/**
* These tests should work regardless of $wgCapitalLinks
*/
class LocalFileTest extends PHPUnit_Framework_TestCase {
function setUp() {
$info = array(
'name' => 'test',
'directory' => '/testdir',
'url' => '/testurl',
'hashLevels' => 2,
'transformVia404' => false,
);
$this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
$this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
$this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
$this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
$this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
$this->file_lc = $this->repo_lc->newFile( 'test!' );
}
function testGetHashPath() {
$this->assertEquals( '', $this->file_hl0->getHashPath() );
$this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
$this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
}
function testGetRel() {
$this->assertEquals( 'Test!', $this->file_hl0->getRel() );
$this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
$this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
}
function testGetUrlRel() {
$this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
$this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
$this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
}
function testGetArchivePath() {
$this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
$this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
$this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
$this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
}
function testGetThumbPath() {
$this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
$this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
$this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
$this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
}
function testGetArchiveUrl() {
$this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
$this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
$this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
$this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
}
function testGetThumbUrl() {
$this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
$this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
$this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
$this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
}
function testGetArchiveVirtualUrl() {
$this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
$this->assertEquals( 'mwrepo://test/public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
$this->assertEquals( 'mwrepo://test/public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
$this->assertEquals( 'mwrepo://test/public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
}
function testGetThumbVirtualUrl() {
$this->assertEquals( 'mwrepo://test/public/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
$this->assertEquals( 'mwrepo://test/public/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
$this->assertEquals( 'mwrepo://test/public/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
$this->assertEquals( 'mwrepo://test/public/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
}
function testGetUrl() {
$this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
$this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
}
}
?>