The idea is that all entry points should share the code in the MediaWikiEntryPoint base class. This change by itself doesn't achieve much, it should be followed up by a change moving request handling logic from ResourceLoader into ResourceEntryPoint. Bug: T354216 Change-Id: Iadea44b7867f48a2be6ccbf00c0e56911a5af74e
79 lines
2 KiB
PHP
79 lines
2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Rest;
|
|
|
|
use MediaWiki\MainConfigNames;
|
|
use MediaWiki\Request\FauxRequest;
|
|
use MediaWiki\ResourceLoader\ResourceEntryPoint;
|
|
use MediaWiki\ResourceLoader\ResourceLoader;
|
|
use MediaWiki\Tests\MockEnvironment;
|
|
use Psr\Log\NullLogger;
|
|
use Wikimedia\DependencyStore\KeyValueDependencyStore;
|
|
|
|
/**
|
|
* @covers \MediaWiki\ResourceLoader\ResourceLoader
|
|
* @group Database
|
|
*/
|
|
class ResourceEntryPointTest extends \MediaWikiIntegrationTestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->overrideConfigValue( MainConfigNames::ShowExceptionDetails, true );
|
|
$this->setService( 'ResourceLoader', [ $this, 'newResourceLoader' ] );
|
|
}
|
|
|
|
public function newResourceLoader() {
|
|
$rl = new ResourceLoader(
|
|
$this->getServiceContainer()->getMainConfig(),
|
|
new NullLogger(),
|
|
new KeyValueDependencyStore( new \HashBagOStuff() ),
|
|
[
|
|
'loadScript' => '/w/load.php',
|
|
'maxageVersioned' => null,
|
|
'maxageUnversioned' => null,
|
|
]
|
|
);
|
|
|
|
$rl->register( include MW_INSTALL_PATH . '/resources/Resources.php' );
|
|
return $rl;
|
|
}
|
|
|
|
/**
|
|
* @param MockEnvironment $env
|
|
*
|
|
* @return ResourceEntryPoint
|
|
*/
|
|
private function getEntryPoint( MockEnvironment $env ): ResourceEntryPoint {
|
|
$entryPoint = new ResourceEntryPoint(
|
|
$env->makeFauxContext(),
|
|
$env,
|
|
$this->getServiceContainer()
|
|
);
|
|
|
|
return $entryPoint;
|
|
}
|
|
|
|
public function testResource() {
|
|
$uri = '/w/load.php';
|
|
|
|
$request = new FauxRequest( [ 'modules' => 'site' ] );
|
|
$request->setRequestURL( $uri );
|
|
|
|
$env = new MockEnvironment( $request );
|
|
$entryPoint = $this->getEntryPoint( $env );
|
|
|
|
$entryPoint->establishOutputBufferLevel();
|
|
$entryPoint->run();
|
|
|
|
// NOTE: MediaWikiEntryPoint::doPostOutputShutdown flushes all output buffers
|
|
$content = $entryPoint->captureOutput();
|
|
|
|
$this->assertStringContainsString( 'mw.loader.impl', $content );
|
|
$this->assertStringContainsString( 'site@', $content );
|
|
|
|
// TODO: Assert headers. We'll have to make ResourceLoader use WebResponse
|
|
// instead of calling the global header() function.
|
|
}
|
|
|
|
}
|