1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<?php
namespace MediaWiki\Tests\Unit\ResourceLoader;
use MediaWiki\ResourceLoader\FilePath;
use MediaWikiUnitTestCase;
use RuntimeException;
/**
* @group ResourceLoader
* @covers \MediaWiki\ResourceLoader\FilePath
*/
class FilePathTest extends MediaWikiUnitTestCase {
public function testGetterSimple() {
$path = new FilePath( 'dummy/path', '/local', '/remote' );
$this->assertSame( '/local/dummy/path', $path->getLocalPath() );
$this->assertSame( '/remote/dummy/path', $path->getRemotePath() );
$this->assertSame( '/local', $path->getLocalBasePath() );
$this->assertSame( '/remote', $path->getRemoteBasePath() );
$this->assertSame( 'dummy/path', $path->getPath() );
}
public function testGetterWebRoot() {
$path = new FilePath( 'dummy/path', '/local', '/' );
$this->assertSame( '/local/dummy/path', $path->getLocalPath() );
// No double slash (T284391)
$this->assertSame( '/dummy/path', $path->getRemotePath() );
$this->assertSame( '/local', $path->getLocalBasePath() );
$this->assertSame( '/', $path->getRemoteBasePath() );
$this->assertSame( 'dummy/path', $path->getPath() );
}
public function testGetterNoBase() {
$path = new FilePath( 'dummy/path' );
try {
$path->getLocalPath();
$this->fail( 'Expected exception not thrown' );
} catch ( RuntimeException $ex ) {
$this->assertSame(
'Base path was not provided',
$ex->getMessage(),
'Expected exception'
);
}
try {
$path->getRemotePath();
$this->fail( 'Expected exception not thrown' );
} catch ( RuntimeException $ex ) {
$this->assertSame(
'Base path was not provided',
$ex->getMessage(),
'Expected exception'
);
}
$this->assertSame( null, $path->getLocalBasePath() );
$this->assertSame( null, $path->getRemoteBasePath() );
$this->assertSame( 'dummy/path', $path->getPath() );
}
}
|