Debian Codegraph @

tests/phpunit/includes/OutputTransform/TestUtils.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\OutputTransform;
4
5 use MediaWiki\Parser\ParserOutput;
6 use Wikimedia\Parsoid\Core\SectionMetadata;
7 use Wikimedia\Parsoid\Core\TOCData;
8
9 /**
10 * Consts and utils used for OutputTransform tests
11 */
12 class TestUtils {
13 public const TEST_DOC = <<<HTML
14 <p>Test document.
15 </p>
16 <meta property="mw:PageProp/toc" />
17 <h2 data-mw-anchor="Section_1">Section 1<mw:editsection page="Test Page" section="1">Section 1</mw:editsection></h2>
18 <p>One
19 </p>
20 <h2 data-mw-anchor="Section_2">Section 2<mw:editsection page="Test Page" section="2">Section 2</mw:editsection></h2>
21 <p>Two
22 </p>
23 <h3 data-mw-anchor="Section_2.1">Section 2.1</h3>
24 <p>Two point one
25 </p>
26 <h2 data-mw-anchor="Section_3">Section 3<mw:editsection page="Test Page" section="4">Section 3</mw:editsection></h2>
27 <p>Three
28 </p>
29 HTML;
30 public const TEST_DOC_WITH_LINKS_LEGACY_MARKUP = <<<HTML
31 <p>Test document.
32 </p>
33 <meta property="mw:PageProp/toc" />
34 <h2><span class="mw-headline" id="Section_1">Section 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&amp;action=edit&amp;section=1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
35 <p>One
36 </p>
37 <h2><span class="mw-headline" id="Section_2">Section 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&amp;action=edit&amp;section=2" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
38 <p>Two
39 </p>
40 <h3><span class="mw-headline" id="Section_2.1">Section 2.1</span></h3>
41 <p>Two point one
42 </p>
43 <h2><span class="mw-headline" id="Section_3">Section 3</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&amp;action=edit&amp;section=4" title="Edit section: Section 3">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
44 <p>Three
45 </p>
46 HTML;
47 public const TEST_DOC_WITH_LINKS_NEW_MARKUP = <<<HTML
48 <p>Test document.
49 </p>
50 <meta property="mw:PageProp/toc" />
51 <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&amp;action=edit&amp;section=1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
52 <p>One
53 </p>
54 <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&amp;action=edit&amp;section=2" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
55 <p>Two
56 </p>
57 <div class="mw-heading mw-heading3"><h3 id="Section_2.1">Section 2.1</h3></div>
58 <p>Two point one
59 </p>
60 <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&amp;action=edit&amp;section=4" title="Edit section: Section 3">edit</a><span class="mw-editsection-bracket">]</span></span></div>
61 <p>Three
62 </p>
63 HTML;
64 public const TEST_DOC_WITHOUT_LINKS_LEGACY_MARKUP = <<<HTML
65 <p>Test document.
66 </p>
67 <meta property="mw:PageProp/toc" />
68 <h2><span class="mw-headline" id="Section_1">Section 1</span></h2>
69 <p>One
70 </p>
71 <h2><span class="mw-headline" id="Section_2">Section 2</span></h2>
72 <p>Two
73 </p>
74 <h3><span class="mw-headline" id="Section_2.1">Section 2.1</span></h3>
75 <p>Two point one
76 </p>
77 <h2><span class="mw-headline" id="Section_3">Section 3</span></h2>
78 <p>Three
79 </p>
80 HTML;
81 public const TEST_DOC_WITHOUT_LINKS_NEW_MARKUP = <<<HTML
82 <p>Test document.
83 </p>
84 <meta property="mw:PageProp/toc" />
85 <div class="mw-heading mw-heading2"><h2 id="Section_1">Section 1</h2></div>
86 <p>One
87 </p>
88 <div class="mw-heading mw-heading2"><h2 id="Section_2">Section 2</h2></div>
89 <p>Two
90 </p>
91 <div class="mw-heading mw-heading3"><h3 id="Section_2.1">Section 2.1</h3></div>
92 <p>Two point one
93 </p>
94 <div class="mw-heading mw-heading2"><h2 id="Section_3">Section 3</h2></div>
95 <p>Three
96 </p>
97 HTML;
98
99 // In this test, the `>` is not escaped in the 'data-mw-anchor' attribute and tag content, which
100 // is allowed in HTML, but it's not the serialization used by the Parser. Extensions that modify
101 // the HTML, e.g. DiscussionTools, can cause this to appear.
102 public const TEST_DOC_ANGLE_BRACKETS = <<<HTML
103 <h2 data-mw-anchor=">">><mw:editsection page="Test Page" section="1">></mw:editsection></h2>
104 HTML;
105 public const TEST_DOC_ANGLE_BRACKETS_WITH_LINKS_LEGACY_MARKUP = <<<HTML
106 <h2><span class="mw-headline" id="&gt;">></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&amp;action=edit&amp;section=1" title="Edit section: &gt;">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
107 HTML;
108 public const TEST_DOC_ANGLE_BRACKETS_WITH_LINKS_NEW_MARKUP = <<<HTML
109 <div class="mw-heading mw-heading2"><h2 id="&gt;">></h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Test_Page&amp;action=edit&amp;section=1" title="Edit section: &gt;">edit</a><span class="mw-editsection-bracket">]</span></span></div>
110 HTML;
111 public const TEST_DOC_ANGLE_BRACKETS_WITHOUT_LINKS_LEGACY_MARKUP = <<<HTML
112 <h2><span class="mw-headline" id="&gt;">></span></h2>
113 HTML;
114 public const TEST_DOC_ANGLE_BRACKETS_WITHOUT_LINKS_NEW_MARKUP = <<<HTML
115 <div class="mw-heading mw-heading2"><h2 id="&gt;">></h2></div>
116 HTML;
117
118 public const TEST_TO_DEDUP = <<<HTML
119 <p>This is a test document.</p>
120 <style data-mw-deduplicate="duplicate1">.Duplicate1 {}</style>
121 <style data-mw-deduplicate="duplicate1">.Duplicate1 {}</style>
122 <style data-mw-deduplicate="duplicate2">.Duplicate2 {}</style>
123 <style data-mw-deduplicate="duplicate1">.Duplicate1 {}</style>
124 <style data-mw-deduplicate="duplicate2">.Duplicate2 {}</style>
125 <style data-mw-not-deduplicate="duplicate1">.Duplicate1 {}</style>
126 <style data-mw-deduplicate="duplicate1">.Same-attribute-different-content {}</style>
127 <style data-mw-deduplicate="duplicate3">.Duplicate1 {}</style>
128 <style>.Duplicate1 {}</style>
129 HTML;
130
131 public static function initSections( ParserOutput $po ): void {
132 $po->setTOCData( new TOCData( SectionMetadata::fromLegacy( [
133 'index' => "1",
134 'level' => 1,
135 'toclevel' => 1,
136 'number' => "1",
137 'line' => "Section 1",
138 'anchor' => "Section_1"
139 ] ), SectionMetadata::fromLegacy( [
140 'index' => "2",
141 'level' => 1,
142 'toclevel' => 1,
143 'number' => "2",
144 'line' => "Section 2",
145 'anchor' => "Section_2"
146 ] ), SectionMetadata::fromLegacy( [
147 'index' => "3",
148 'level' => 2,
149 'toclevel' => 2,
150 'number' => "2.1",
151 'line' => "Section 2.1",
152 'anchor' => "Section_2.1"
153 ] ), SectionMetadata::fromLegacy( [
154 'index' => "4",
155 'level' => 1,
156 'toclevel' => 1,
157 'number' => "3",
158 'line' => "Section 3",
159 'anchor' => "Section_3"
160 ] ), ) );
161 }
162 }