| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\OutputTransform; |
| 4 |
|
| 5 |
use LogicException; |
| 6 |
use MediaWiki\Context\RequestContext; |
| 7 |
use MediaWiki\MainConfigNames; |
| 8 |
use MediaWiki\Parser\ParserOutput; |
| 9 |
use MediaWikiLangTestCase; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class DefaultOutputPipelineFactoryTest extends MediaWikiLangTestCase { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public function testTransform( $options, $text, $expect ) { |
| 28 |
|
| 29 |
$this->overrideConfigValue( MainConfigNames::DefaultSkin, 'fallback' ); |
| 30 |
RequestContext::resetMain(); |
| 31 |
|
| 32 |
$this->overrideConfigValues( [ |
| 33 |
MainConfigNames::ScriptPath => '/w', |
| 34 |
MainConfigNames::Script => '/w/index.php', |
| 35 |
MainConfigNames::ParserEnableLegacyHeadingDOM => false, |
| 36 |
] ); |
| 37 |
|
| 38 |
$po = new ParserOutput( $text ); |
| 39 |
TestUtils::initSections( $po ); |
| 40 |
$actual = $this->getServiceContainer()->getDefaultOutputPipeline() |
| 41 |
->run( $po, null, $options )->getContentHolderText(); |
| 42 |
$this->assertSame( $expect, $actual ); |
| 43 |
} |
| 44 |
|
| 45 |
public static function provideTransform() { |
| 46 |
return [ |
| 47 |
'No options' => [ |
| 48 |
[], TestUtils::TEST_DOC, <<<EOF |
| 49 |
<p>Test document. |
| 50 |
</p> |
| 51 |
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div> |
| 52 |
<ul> |
| 53 |
<li class="toclevel-1 tocsection-1"><a href="#Section_1"><span class="tocnumber">1</span> <span class="toctext">Section 1</span></a></li> |
| 54 |
<li class="toclevel-1 tocsection-2"><a href="#Section_2"><span class="tocnumber">2</span> <span class="toctext">Section 2</span></a> |
| 55 |
<ul> |
| 56 |
<li class="toclevel-2 tocsection-3"><a href="#Section_2.1"><span class="tocnumber">2.1</span> <span class="toctext">Section 2.1</span></a></li> |
| 57 |
</ul> |
| 58 |
</li> |
| 59 |
<li class="toclevel-1 tocsection-4"><a href="#Section_3"><span class="tocnumber">3</span> <span class="toctext">Section 3</span></a></li> |
| 60 |
</ul> |
| 61 |
</div> |
| 62 |
|
| 63 |
<div class="mw-heading mw-heading2"><h2 id="Section_1">Section 1</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></div> |
| 64 |
<p>One |
| 65 |
</p> |
| 66 |
<div class="mw-heading mw-heading2"><h2 id="Section_2">Section 2</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=2" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></div> |
| 67 |
<p>Two |
| 68 |
</p> |
| 69 |
<div class="mw-heading mw-heading3"><h3 id="Section_2.1">Section 2.1</h3></div> |
| 70 |
<p>Two point one |
| 71 |
</p> |
| 72 |
<div class="mw-heading mw-heading2"><h2 id="Section_3">Section 3</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=4" title="Edit section: Section 3">edit</a><span class="mw-editsection-bracket">]</span></span></div> |
| 73 |
<p>Three |
| 74 |
</p> |
| 75 |
EOF |
| 76 |
], |
| 77 |
'Disable section edit links' => [ |
| 78 |
[ 'enableSectionEditLinks' => false ], TestUtils::TEST_DOC, <<<EOF |
| 79 |
<p>Test document. |
| 80 |
</p> |
| 81 |
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div> |
| 82 |
<ul> |
| 83 |
<li class="toclevel-1 tocsection-1"><a href="#Section_1"><span class="tocnumber">1</span> <span class="toctext">Section 1</span></a></li> |
| 84 |
<li class="toclevel-1 tocsection-2"><a href="#Section_2"><span class="tocnumber">2</span> <span class="toctext">Section 2</span></a> |
| 85 |
<ul> |
| 86 |
<li class="toclevel-2 tocsection-3"><a href="#Section_2.1"><span class="tocnumber">2.1</span> <span class="toctext">Section 2.1</span></a></li> |
| 87 |
</ul> |
| 88 |
</li> |
| 89 |
<li class="toclevel-1 tocsection-4"><a href="#Section_3"><span class="tocnumber">3</span> <span class="toctext">Section 3</span></a></li> |
| 90 |
</ul> |
| 91 |
</div> |
| 92 |
|
| 93 |
<div class="mw-heading mw-heading2"><h2 id="Section_1">Section 1</h2></div> |
| 94 |
<p>One |
| 95 |
</p> |
| 96 |
<div class="mw-heading mw-heading2"><h2 id="Section_2">Section 2</h2></div> |
| 97 |
<p>Two |
| 98 |
</p> |
| 99 |
<div class="mw-heading mw-heading3"><h3 id="Section_2.1">Section 2.1</h3></div> |
| 100 |
<p>Two point one |
| 101 |
</p> |
| 102 |
<div class="mw-heading mw-heading2"><h2 id="Section_3">Section 3</h2></div> |
| 103 |
<p>Three |
| 104 |
</p> |
| 105 |
EOF |
| 106 |
], |
| 107 |
'Disable TOC, but wrap' => [ |
| 108 |
[ 'allowTOC' => false, 'wrapperDivClass' => 'mw-parser-output' ], TestUtils::TEST_DOC, <<<EOF |
| 109 |
<div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><p>Test document. |
| 110 |
</p> |
| 111 |
|
| 112 |
<div class="mw-heading mw-heading2"><h2 id="Section_1">Section 1</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></div> |
| 113 |
<p>One |
| 114 |
</p> |
| 115 |
<div class="mw-heading mw-heading2"><h2 id="Section_2">Section 2</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=2" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></div> |
| 116 |
<p>Two |
| 117 |
</p> |
| 118 |
<div class="mw-heading mw-heading3"><h3 id="Section_2.1">Section 2.1</h3></div> |
| 119 |
<p>Two point one |
| 120 |
</p> |
| 121 |
<div class="mw-heading mw-heading2"><h2 id="Section_3">Section 3</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&action=edit&section=4" title="Edit section: Section 3">edit</a><span class="mw-editsection-bracket">]</span></span></div> |
| 122 |
<p>Three |
| 123 |
</p></div> |
| 124 |
EOF |
| 125 |
], |
| 126 |
'Style deduplication disabled' => [ |
| 127 |
[ 'deduplicateStyles' => false ], TestUtils::TEST_TO_DEDUP, TestUtils::TEST_TO_DEDUP |
| 128 |
], |
| 129 |
]; |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public function testTransform_failsIfNoText() { |
| 137 |
$po = new ParserOutput( null ); |
| 138 |
|
| 139 |
$this->expectException( LogicException::class ); |
| 140 |
$this->getServiceContainer()->getDefaultOutputPipeline() |
| 141 |
->run( $po, null, [] ); |
| 142 |
} |
| 143 |
} |