2019-07-14 22:16:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-05-06 09:09:56 +00:00
|
|
|
namespace MediaWiki\Tests\Unit\ResourceLoader;
|
|
|
|
|
|
|
|
|
|
use MediaWiki\ResourceLoader\FilePath;
|
|
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
|
|
2019-07-19 22:36:06 +00:00
|
|
|
/**
|
2022-05-06 09:09:56 +00:00
|
|
|
* @covers \MediaWiki\ResourceLoader\FilePath
|
2019-07-19 22:36:06 +00:00
|
|
|
*/
|
2022-05-06 09:09:56 +00:00
|
|
|
class FilePathTest extends MediaWikiUnitTestCase {
|
2019-07-14 22:16:07 +00:00
|
|
|
|
2019-07-19 22:36:06 +00:00
|
|
|
public function testConstructor() {
|
2022-05-06 09:09:56 +00:00
|
|
|
$path = new FilePath( 'dummy/path', '/local', '/remote' );
|
2019-07-14 22:16:07 +00:00
|
|
|
|
2022-05-06 09:09:56 +00:00
|
|
|
$this->assertInstanceOf( FilePath::class, $path );
|
2019-07-14 22:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 23:34:03 +00:00
|
|
|
public function testGetterSimple() {
|
2022-05-06 09:09:56 +00:00
|
|
|
$path = new FilePath( 'dummy/path', '/local', '/remote' );
|
2019-07-14 22:16:07 +00:00
|
|
|
|
2019-07-19 22:36:06 +00:00
|
|
|
$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() );
|
2019-07-14 22:16:07 +00:00
|
|
|
}
|
2021-06-08 23:34:03 +00:00
|
|
|
|
|
|
|
|
public function testGetterWebRoot() {
|
2022-05-06 09:09:56 +00:00
|
|
|
$path = new FilePath( 'dummy/path', '/local', '/' );
|
2021-06-08 23:34:03 +00:00
|
|
|
|
|
|
|
|
$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() {
|
2022-05-06 09:09:56 +00:00
|
|
|
$path = new FilePath( 'dummy/path', '', '' );
|
2021-06-08 23:34:03 +00:00
|
|
|
|
|
|
|
|
// No transformation
|
|
|
|
|
$this->assertSame( 'dummy/path', $path->getLocalPath() );
|
|
|
|
|
$this->assertSame( 'dummy/path', $path->getRemotePath() );
|
|
|
|
|
$this->assertSame( '', $path->getLocalBasePath() );
|
|
|
|
|
$this->assertSame( '', $path->getRemoteBasePath() );
|
|
|
|
|
$this->assertSame( 'dummy/path', $path->getPath() );
|
|
|
|
|
}
|
2019-07-14 22:16:07 +00:00
|
|
|
}
|