Skip to content

Commit be2dbcc

Browse files
committed
ResourceLoader: Follow-up creation of ResourceLoaderEntryPoint
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
1 parent 260fc1b commit be2dbcc

File tree

6 files changed

+98
-105
lines changed

6 files changed

+98
-105
lines changed

Diff for: autoload.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1916,8 +1916,8 @@
19161916
'MediaWiki\\ResourceLoader\\OOUIIconPackModule' => __DIR__ . '/includes/ResourceLoader/OOUIIconPackModule.php',
19171917
'MediaWiki\\ResourceLoader\\OOUIImageModule' => __DIR__ . '/includes/ResourceLoader/OOUIImageModule.php',
19181918
'MediaWiki\\ResourceLoader\\OOUIModule' => __DIR__ . '/includes/ResourceLoader/OOUIModule.php',
1919-
'MediaWiki\\ResourceLoader\\ResourceEntryPoint' => __DIR__ . '/includes/ResourceLoader/ResourceEntryPoint.php',
19201919
'MediaWiki\\ResourceLoader\\ResourceLoader' => __DIR__ . '/includes/ResourceLoader/ResourceLoader.php',
1920+
'MediaWiki\\ResourceLoader\\ResourceLoaderEntryPoint' => __DIR__ . '/includes/ResourceLoader/ResourceLoaderEntryPoint.php',
19211921
'MediaWiki\\ResourceLoader\\SiteModule' => __DIR__ . '/includes/ResourceLoader/SiteModule.php',
19221922
'MediaWiki\\ResourceLoader\\SiteStylesModule' => __DIR__ . '/includes/ResourceLoader/SiteStylesModule.php',
19231923
'MediaWiki\\ResourceLoader\\SkinModule' => __DIR__ . '/includes/ResourceLoader/SkinModule.php',

Diff for: includes/MediaWikiEntryPoint.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -944,12 +944,19 @@ protected function drainOutputBuffer() {
944944
}
945945

946946
/**
947-
* Enables output capture in the current output buffer.
948-
* The caller may need to call ob_start() to establish a buffer.
949-
* The captured output can be retrieved using getCapturedOutput().
950-
* When output capture is enabled, flushOutputBuffer() will not actually
951-
* send output.
947+
* Enable capturing of the current output buffer.
952948
*
949+
* There may be mutiple levels of output buffering. The level
950+
* we are currently at, at the time of calling this method,
951+
* is the level that will be captured to later retrieve via
952+
* getCapturedOutput().
953+
*
954+
* When capturing is active, flushOutputBuffer() will not actually
955+
* write to the real STDOUT, but instead write only to the capture.
956+
*
957+
* This exists to ease testing.
958+
*
959+
* @internal For use in PHPUnit tests
953960
* @see ob_start()
954961
* @see getCapturedOutput();
955962
*/
@@ -998,13 +1005,17 @@ protected function commitOutputBuffer(): bool {
9981005
}
9991006

10001007
/**
1001-
* Commits all output buffers down to the capture buffer level,
1002-
* then clears the capture buffer and returns its contents.
1008+
* Stop capturing and return all output
1009+
*
1010+
* It flushes and drains all output buffers, but lets it go
1011+
* to a return value instead of the real STDOUT.
10031012
*
1004-
* Needs enableOutputCapture() to be called before run().
1013+
* You must call enableOutputCapture() and run() before getCapturedOutput().
10051014
*
1015+
* @internal For use in PHPUnit tests
10061016
* @see enableOutputCapture();
10071017
* @see ob_end_clean
1018+
* @return string HTTP response body
10081019
*/
10091020
public function getCapturedOutput(): string {
10101021
if ( $this->outputCaptureLevel === null ) {

Diff for: includes/ResourceLoader/ResourceEntryPoint.php renamed to includes/ResourceLoader/ResourceLoaderEntryPoint.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
22
/**
3-
* Entry point implementation for @ref ResourceLoader, which serves static CSS/JavaScript
4-
* via @ref MediaWiki\ResourceLoader\Module Module subclasses.
5-
*
6-
* @see /load.php The web entry point
7-
*
83
* This program is free software; you can redistribute it and/or modify
94
* it under the terms of the GNU General Public License as published by
105
* the Free Software Foundation; either version 2 of the License, or
@@ -21,16 +16,22 @@
2116
* http://www.gnu.org/copyleft/gpl.html
2217
*
2318
* @file
24-
* @ingroup entrypoint
25-
* @ingroup ResourceLoader
2619
*/
2720

2821
namespace MediaWiki\ResourceLoader;
2922

3023
use MediaWiki\MediaWikiEntryPoint;
3124
use Profiler;
3225

33-
class ResourceEntryPoint extends MediaWikiEntryPoint {
26+
/**
27+
* Entry point implementation for @ref ResourceLoader, which serves static CSS/JavaScript
28+
* via @ref MediaWiki\ResourceLoader\Module Module subclasses.
29+
*
30+
* @see load.php
31+
* @ingroup ResourceLoader
32+
* @ingroup entrypoint
33+
*/
34+
class ResourceLoaderEntryPoint extends MediaWikiEntryPoint {
3435

3536
/**
3637
* Main entry point

Diff for: load.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
/**
3-
* The web entry point for @ref ResourceLoader, which serves static CSS/JavaScript.
4-
*
5-
* @see MediaWiki\ResourceLoader\ResourceEntryPoint The implementation.
3+
* @see MediaWiki\ResourceLoader\ResourceLoaderEntryPoint
64
*
75
* This program is free software; you can redistribute it and/or modify
86
* it under the terms of the GNU General Public License as published by
@@ -20,16 +18,14 @@
2018
* http://www.gnu.org/copyleft/gpl.html
2119
*
2220
* @file
23-
* @ingroup entrypoint
24-
* @ingroup ResourceLoader
2521
* @author Roan Kattouw
2622
* @author Trevor Parscal
2723
*/
2824

2925
use MediaWiki\Context\RequestContext;
3026
use MediaWiki\EntryPointEnvironment;
3127
use MediaWiki\MediaWikiServices;
32-
use MediaWiki\ResourceLoader\ResourceEntryPoint;
28+
use MediaWiki\ResourceLoader\ResourceLoaderEntryPoint;
3329

3430
// This endpoint is supposed to be independent of request cookies and other
3531
// details of the session. Enforce this constraint with respect to session use.
@@ -39,7 +35,7 @@
3935

4036
require __DIR__ . '/includes/WebStart.php';
4137

42-
( new ResourceEntryPoint(
38+
( new ResourceLoaderEntryPoint(
4339
RequestContext::getMain(),
4440
new EntryPointEnvironment(),
4541
MediaWikiServices::getInstance()

Diff for: tests/phpunit/includes/ResourceLoader/ResourceEntryPointTest.php

-81
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace MediaWiki\Tests\ResourceLoader;
4+
5+
use MediaWiki\MainConfigNames;
6+
use MediaWiki\Request\FauxRequest;
7+
use MediaWiki\ResourceLoader\ResourceLoader;
8+
use MediaWiki\ResourceLoader\ResourceLoaderEntryPoint;
9+
use MediaWiki\Tests\MockEnvironment;
10+
use MediaWikiIntegrationTestCase;
11+
12+
/**
13+
* @covers \MediaWiki\ResourceLoader\ResourceLoader
14+
* @group Database
15+
*/
16+
class ResourceLoaderEntryPointTest extends MediaWikiIntegrationTestCase {
17+
18+
protected function setUp(): void {
19+
parent::setUp();
20+
21+
$this->overrideConfigValue( MainConfigNames::ShowExceptionDetails, true );
22+
$this->setService( 'ResourceLoader', [ $this, 'newResourceLoader' ] );
23+
}
24+
25+
public function newResourceLoader() {
26+
// See also ResourceLoaderTestCase::getResourceLoaderContext
27+
return new ResourceLoader(
28+
$this->getServiceContainer()->getMainConfig(),
29+
null,
30+
null,
31+
[
32+
'loadScript' => '/w/load.php',
33+
]
34+
);
35+
}
36+
37+
private function getEntryPoint( FauxRequest $request ) {
38+
$env = new MockEnvironment( $request );
39+
return new ResourceLoaderEntryPoint(
40+
$env->makeFauxContext(),
41+
$env,
42+
$this->getServiceContainer()
43+
);
44+
}
45+
46+
/**
47+
* Further tested in StartUpModuleTest and ResourceLoaderTest
48+
*/
49+
public function testExecute() {
50+
// Simulate a real request, such as the one from RL\ClientHtml::getHeadHtml
51+
$request = new FauxRequest( [ 'modules' => 'startup', 'only' => 'scripts', 'raw' => '1' ] );
52+
$request->setRequestURL( '/w/load.php' );
53+
$entryPoint = $this->getEntryPoint( $request );
54+
55+
$entryPoint->enableOutputCapture();
56+
$entryPoint->run();
57+
$content = $entryPoint->getCapturedOutput();
58+
59+
$this->assertStringContainsString( 'function isCompatible', $content );
60+
$this->assertStringContainsString( 'mw.loader.addSource(', $content );
61+
62+
// TODO: Assert headers once ResourceLoader doesn't call header()
63+
// directly (maybe a library version of WebResponse).
64+
}
65+
66+
}

0 commit comments

Comments
 (0)