2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* These tests should work regardless of $wgCapitalLinks
|
2013-10-24 16:45:52 +00:00
|
|
|
* @todo Split tests into providers and test methods
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-12-28 18:17:16 +00:00
|
|
|
class LocalFileTest extends MediaWikiTestCase {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', true );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$info = [
|
2013-02-14 11:22:13 +00:00
|
|
|
'name' => 'test',
|
|
|
|
|
'directory' => '/testdir',
|
|
|
|
|
'url' => '/testurl',
|
|
|
|
|
'hashLevels' => 2,
|
2010-12-14 16:26:35 +00:00
|
|
|
'transformVia404' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'backend' => new FSFileBackend( [
|
2013-02-14 11:22:13 +00:00
|
|
|
'name' => 'local-backend',
|
2013-12-03 20:55:44 +00:00
|
|
|
'wikiId' => wfWikiId(),
|
2016-02-17 09:09:32 +00:00
|
|
|
'containerPaths' => [
|
2012-01-07 01:33:23 +00:00
|
|
|
'cont1' => "/testdir/local-backend/tempimages/cont1",
|
|
|
|
|
'cont2' => "/testdir/local-backend/tempimages/cont2"
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
] )
|
|
|
|
|
];
|
|
|
|
|
$this->repo_hl0 = new LocalRepo( [ 'hashLevels' => 0 ] + $info );
|
|
|
|
|
$this->repo_hl2 = new LocalRepo( [ 'hashLevels' => 2 ] + $info );
|
|
|
|
|
$this->repo_lc = new LocalRepo( [ 'initialCapital' => false ] + $info );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
|
|
|
|
|
$this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
|
|
|
|
|
$this->file_lc = $this->repo_lc->newFile( 'test!' );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getHashPath
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetHashPath() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( '', $this->file_hl0->getHashPath() );
|
|
|
|
|
$this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
|
|
|
|
|
$this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getRel
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetRel() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$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() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getUrlRel
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetUrlRel() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$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() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getArchivePath
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetArchivePath() {
|
2014-04-24 12:35:05 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwstore://local-backend/test-public/archive',
|
|
|
|
|
$this->file_hl0->getArchivePath()
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwstore://local-backend/test-public/archive/a/a2',
|
|
|
|
|
$this->file_hl2->getArchivePath()
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwstore://local-backend/test-public/archive/!',
|
|
|
|
|
$this->file_hl0->getArchivePath( '!' )
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwstore://local-backend/test-public/archive/a/a2/!',
|
|
|
|
|
$this->file_hl2->getArchivePath( '!' )
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getThumbPath
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetThumbPath() {
|
2014-04-24 12:35:05 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwstore://local-backend/test-thumb/Test!',
|
|
|
|
|
$this->file_hl0->getThumbPath()
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwstore://local-backend/test-thumb/a/a2/Test!',
|
|
|
|
|
$this->file_hl2->getThumbPath()
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwstore://local-backend/test-thumb/Test!/x',
|
|
|
|
|
$this->file_hl0->getThumbPath( 'x' )
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwstore://local-backend/test-thumb/a/a2/Test!/x',
|
|
|
|
|
$this->file_hl2->getThumbPath( 'x' )
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getArchiveUrl
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetArchiveUrl() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$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( '!' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getThumbUrl
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetThumbUrl() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$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' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getArchiveVirtualUrl
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetArchiveVirtualUrl() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
|
2014-04-24 12:35:05 +00:00
|
|
|
$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( '!' )
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getThumbVirtualUrl
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetThumbVirtualUrl() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
|
|
|
|
|
$this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
|
2014-04-24 12:35:05 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwrepo://test/thumb/Test%21/%21',
|
|
|
|
|
$this->file_hl0->getThumbVirtualUrl( '!' )
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mwrepo://test/thumb/a/a2/Test%21/%21',
|
|
|
|
|
$this->file_hl2->getThumbVirtualUrl( '!' )
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getUrl
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testGetUrl() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
|
|
|
|
|
$this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ::wfLocalFile
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testWfLocalFile() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
|
2014-04-24 12:35:05 +00:00
|
|
|
$this->assertThat(
|
|
|
|
|
$file,
|
|
|
|
|
$this->isInstanceOf( 'LocalFile' ),
|
|
|
|
|
'wfLocalFile() returns LocalFile for valid Titles'
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|