wiki.techinc.nl/tests/phpunit/includes/content/JavaScriptContentHandlerIntegrationTest.php
C. Scott Ananian 008095280a Use canonical parser options when rendering JavaScript/CSS for side effects
In the JavaScript and CSS content handlers we render the page "as
wikitext" solely to generate categories, toc, etc, and then throw that
output away and replace the generated HTML.  Simplify the code paths
and the caching by using the canonical options which don't split by
user language, etc.

Three minor issues with the current patch, which can hopefully be
addressed in follow ups:

1. WikiPage::makeParserOptionsFromTitleAndModel() has a very cumbersome
   name and arguably doesn't belong in WikiPage in the first place.
   T313455 already exists to find a better place for this/way to do this.

2. Title::isConversionTable() requires a downcast of the page reference
   to a full title object.  This method also probably wants to live
   somewhere else.

3. It really would be nice to combine this more properly with
   ContentHandler::getParserOutputForIndexing(), but that method
   uses a ParserOutputAccess object which requires a PageRecord,
   and we don't have a PageRecord available in fillParserOutput().

Bug: T307691
Change-Id: I081105741b507ed49e19cb878550ba4293e09413
2022-07-28 10:45:35 -04:00

49 lines
1.2 KiB
PHP

<?php
/**
* @group ContentHandler
* @group Database
* ^--- needed, because we do need the database to test link updates
*/
class JavaScriptContentHandlerIntegrationTest extends TextContentHandlerIntegrationTest {
public static function provideGetParserOutput() {
yield 'Basic render' => [
'title' => 'MediaWiki:Test.js',
'model' => null,
'text' => "hello <world>\n",
'expectedHtml' => "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello &lt;world>\n\n</pre>",
'expectedFields' => [
'Links' => [
],
'Sections' => [
],
],
];
yield 'Links' => [
'title' => 'MediaWiki:Test.js',
'model' => null,
'text' => "hello(); // [[world]]\n",
'expectedHtml' => "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello(); // [[world]]\n\n</pre>",
'expectedFields' => [
'Links' => [
[ 'World' => 0, ],
],
'Sections' => [
],
],
];
yield 'TOC' => [
'title' => 'MediaWiki:Test.js',
'model' => null,
'text' => "==One==\n<h2>Two</h2>",
'expectedHtml' => "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n==One==\n&lt;h2>Two&lt;/h2>\n</pre>",
'expectedFields' => [
'Links' => [
],
# T307691
'Sections' => [
],
],
];
}
}