3 class WikitextStructureTest
extends MediaWikiLangTestCase
{
5 private function getMockTitle() {
6 return Title
::newFromText( "TestTitle" );
10 * Get parser output for Wiki text
12 * @return ParserOutput
14 private function getParserOutput( $text ) {
15 $content = new WikitextContent( $text );
16 return $content->getParserOutput( $this->getMockTitle() );
20 * Get WikitextStructure for given text
22 * @return WikiTextStructure
24 private function getStructure( $text ) {
25 return new WikiTextStructure( $this->getParserOutput( $text ) );
28 public function testHeadings() {
35 === Applicability of the strict mass-energy equivalence formula, ''E'' = ''mc''<sup>2</sup> ===
37 == Wikitext '''in''' [[Heading]] and also <b>html</b> ==
42 $struct = $this->getStructure( $text );
43 $headings = $struct->headings();
44 $this->assertCount( 4, $headings );
45 $this->assertContains( "Heading one", $headings );
46 $this->assertContains( "heading two", $headings );
47 $this->assertContains( "Applicability of the strict mass-energy equivalence formula, E = mc2",
49 $this->assertContains( "Wikitext in Heading and also html", $headings );
52 public function testHeadingsFirst() {
58 $struct = $this->getStructure( $text );
59 $headings = $struct->headings();
60 $this->assertCount( 2, $headings );
61 $this->assertContains( "Heading one", $headings );
62 $this->assertContains( "heading two", $headings );
65 public function testHeadingsNone() {
66 $text = "This text is completely devoid of headings.";
67 $struct = $this->getStructure( $text );
68 $headings = $struct->headings();
69 $this->assertArrayEquals( [], $headings );
72 public function testTexts() {
74 Opening text is opening.
75 == Then comes header ==
76 Then we got more<br>text
77 === And more headers ===
84 | another row in table
87 $struct = $this->getStructure( $text );
88 $this->assertEquals( "Opening text is opening.", $struct->getOpeningText() );
89 $this->assertEquals( "Opening text is opening. Then we got more text",
90 $struct->getMainText() );
91 $this->assertEquals( [ "Header table row in table another row in table" ],
92 $struct->getAuxiliaryText() );