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;
|
resourceloader: Tweak RL\FilePath handling in packageFiles
ResourceLoader's FilePath is designed to allow a FileModule
to include files that exist outside of the module's localBasePath,
to allow skins and extensions to extend core MediaWiki modules.
This is accomplished by having the FileModule use the FilePath's
localBasePath instead, in FileModule::getLocalPath.
(Similarly for remoteBasePath, but these are going out of fashion.)
However, the code processing 'packageFiles' did not handle this right:
it used FilePath's localBasePath when it appeared as a 'file',
but not when it was returned by a 'callback' or 'versionCallback',
using the FileModule's localBasePath instead in that case. Most
existing uses of FilePath in 'packageFiles' required the same base
path as the module, so it was convenient to avoid providing it twice.
To keep that convenience (already relied on by some extensions too)
while also allowing skins and extensions to add files from their own
directories to existing modules, the code processing 'packageFiles'
now uses FilePath's base paths in all cases, but they are optional,
and will fall back to the FileModule's paths when not provided.
Follow-up to 2890bca27db3636348b1a052e9e4d23a6bb1e272.
Change-Id: I38a0761ae4633a567b685b52c1d73b6ce280ffb7
2022-05-24 00:42:21 +00:00
|
|
|
use RuntimeException;
|
2022-05-06 09:09:56 +00:00
|
|
|
|
2019-07-19 22:36:06 +00:00
|
|
|
/**
|
2024-03-09 19:59:18 +00:00
|
|
|
* @group ResourceLoader
|
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() {
|
resourceloader: Tweak RL\FilePath handling in packageFiles
ResourceLoader's FilePath is designed to allow a FileModule
to include files that exist outside of the module's localBasePath,
to allow skins and extensions to extend core MediaWiki modules.
This is accomplished by having the FileModule use the FilePath's
localBasePath instead, in FileModule::getLocalPath.
(Similarly for remoteBasePath, but these are going out of fashion.)
However, the code processing 'packageFiles' did not handle this right:
it used FilePath's localBasePath when it appeared as a 'file',
but not when it was returned by a 'callback' or 'versionCallback',
using the FileModule's localBasePath instead in that case. Most
existing uses of FilePath in 'packageFiles' required the same base
path as the module, so it was convenient to avoid providing it twice.
To keep that convenience (already relied on by some extensions too)
while also allowing skins and extensions to add files from their own
directories to existing modules, the code processing 'packageFiles'
now uses FilePath's base paths in all cases, but they are optional,
and will fall back to the FileModule's paths when not provided.
Follow-up to 2890bca27db3636348b1a052e9e4d23a6bb1e272.
Change-Id: I38a0761ae4633a567b685b52c1d73b6ce280ffb7
2022-05-24 00:42:21 +00:00
|
|
|
$path = new FilePath( 'dummy/path' );
|
2021-06-08 23:34:03 +00:00
|
|
|
|
resourceloader: Tweak RL\FilePath handling in packageFiles
ResourceLoader's FilePath is designed to allow a FileModule
to include files that exist outside of the module's localBasePath,
to allow skins and extensions to extend core MediaWiki modules.
This is accomplished by having the FileModule use the FilePath's
localBasePath instead, in FileModule::getLocalPath.
(Similarly for remoteBasePath, but these are going out of fashion.)
However, the code processing 'packageFiles' did not handle this right:
it used FilePath's localBasePath when it appeared as a 'file',
but not when it was returned by a 'callback' or 'versionCallback',
using the FileModule's localBasePath instead in that case. Most
existing uses of FilePath in 'packageFiles' required the same base
path as the module, so it was convenient to avoid providing it twice.
To keep that convenience (already relied on by some extensions too)
while also allowing skins and extensions to add files from their own
directories to existing modules, the code processing 'packageFiles'
now uses FilePath's base paths in all cases, but they are optional,
and will fall back to the FileModule's paths when not provided.
Follow-up to 2890bca27db3636348b1a052e9e4d23a6bb1e272.
Change-Id: I38a0761ae4633a567b685b52c1d73b6ce280ffb7
2022-05-24 00:42:21 +00:00
|
|
|
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() );
|
2021-06-08 23:34:03 +00:00
|
|
|
$this->assertSame( 'dummy/path', $path->getPath() );
|
|
|
|
|
}
|
2019-07-14 22:16:07 +00:00
|
|
|
}
|