Follows-up Iadea44b7867f48a2be6ccbf00c0e56911a5af74e. ResourceLoaderEntryPoint: * Rename from Resource to ResourceLoader, as it is the entry point for ResourceLoader. * Fix accidental use of ingroup on the file docblock instead of the class. https://phabricator.wikimedia.org/F42046908 * Fix broken "see" reference to "/load.php" on the ResourceEntryPoint class on doc.wikimedia.org. Files are indexed in Doxygen by full name without leading slash. * Remove load.php from docgroup, akin to index.php. tests: * Remove unrelated Rest namespace from test suite. * Remove redundant default values in newResourceLoader(), especially null values were confusing by showing an apparent intent to set a value without actually isplacing the default, given that isset/?? treat set null as not set. * Simplify test by using the built-in startup module instead. EntryPoint: * Remove comment in test about doPostOutputShutdown. It sounded like it was explaining that we use getCapturedOutput() instead of run() because the latter calls doPostOutputShutdown which we want to avoid. Except, we don't avoid it, since run() is called and does call doPostOutputShutdown. Unclear what it was explaining. * Improve docs around getCapturedOutput() in the base class, and make explicit that this seemingly unused complexity exists for the purpose of testing. Bug: T354216 Change-Id: I5139fda90a3d5ac7ea1ed917c8045d1a09961d78
66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\ResourceLoader;
|
|
|
|
use MediaWiki\MainConfigNames;
|
|
use MediaWiki\Request\FauxRequest;
|
|
use MediaWiki\ResourceLoader\ResourceLoader;
|
|
use MediaWiki\ResourceLoader\ResourceLoaderEntryPoint;
|
|
use MediaWiki\Tests\MockEnvironment;
|
|
use MediaWikiIntegrationTestCase;
|
|
|
|
/**
|
|
* @covers \MediaWiki\ResourceLoader\ResourceLoader
|
|
* @group Database
|
|
*/
|
|
class ResourceLoaderEntryPointTest extends MediaWikiIntegrationTestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->overrideConfigValue( MainConfigNames::ShowExceptionDetails, true );
|
|
$this->setService( 'ResourceLoader', [ $this, 'newResourceLoader' ] );
|
|
}
|
|
|
|
public function newResourceLoader() {
|
|
// See also ResourceLoaderTestCase::getResourceLoaderContext
|
|
return new ResourceLoader(
|
|
$this->getServiceContainer()->getMainConfig(),
|
|
null,
|
|
null,
|
|
[
|
|
'loadScript' => '/w/load.php',
|
|
]
|
|
);
|
|
}
|
|
|
|
private function getEntryPoint( FauxRequest $request ) {
|
|
$env = new MockEnvironment( $request );
|
|
return new ResourceLoaderEntryPoint(
|
|
$env->makeFauxContext(),
|
|
$env,
|
|
$this->getServiceContainer()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Further tested in StartUpModuleTest and ResourceLoaderTest
|
|
*/
|
|
public function testExecute() {
|
|
// Simulate a real request, such as the one from RL\ClientHtml::getHeadHtml
|
|
$request = new FauxRequest( [ 'modules' => 'startup', 'only' => 'scripts', 'raw' => '1' ] );
|
|
$request->setRequestURL( '/w/load.php' );
|
|
$entryPoint = $this->getEntryPoint( $request );
|
|
|
|
$entryPoint->enableOutputCapture();
|
|
$entryPoint->run();
|
|
$content = $entryPoint->getCapturedOutput();
|
|
|
|
$this->assertStringContainsString( 'function isCompatible', $content );
|
|
$this->assertStringContainsString( 'mw.loader.addSource(', $content );
|
|
|
|
// TODO: Assert headers once ResourceLoader doesn't call header()
|
|
// directly (maybe a library version of WebResponse).
|
|
}
|
|
|
|
}
|