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