wiki.techinc.nl/tests/phpunit/unit/includes/resourceloader/ResourceLoaderFilePathTest.php
Timo Tijhof 526c6a4172 resourceloader: Fix remote bash path at document root passed into SkinModule
For any other module, the document root would get processed only
once, but for SkinModule the internal paths would be for the skin
directory, and the path for core ends up processed once.

Once in SkinModule::getStyleFiles via extractBasePaths(), which turns
a document root (wgScript=wgResourceBasePath="") empty string into
a slash (as it should). And then again later by FilePath::getRemotePath
when it is time to perform background image remapping.

The hybrid approach of SkinModule hasn't really been supported or
tested for in this case, but it hasn't been an issue for most installs
because the paths naturally don't end up ambiguous, except for
document root installs. This is likely not the last we've seen of
this, but for now it seems feasible to try to make FilePath
responsible for handling this when it is encountered .

Bug: T284391
Change-Id: I6f5f232bd6da6c655246a5e678a5600889cd78aa
2021-06-08 23:18:22 -07:00

45 lines
1.6 KiB
PHP

<?php
/**
* @covers ResourceLoaderFilePath
*/
class ResourceLoaderFilePathTest extends MediaWikiUnitTestCase {
public function testConstructor() {
$path = new ResourceLoaderFilePath( 'dummy/path', '/local', '/remote' );
$this->assertInstanceOf( ResourceLoaderFilePath::class, $path );
}
public function testGetterSimple() {
$path = new ResourceLoaderFilePath( '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 ResourceLoaderFilePath( '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 ResourceLoaderFilePath( 'dummy/path', '', '' );
// 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() );
}
}