4 * @covers WikiTextStructure
6 class WikitextStructureTest
extends MediaWikiLangTestCase
{
8 private function getMockTitle() {
9 return Title
::newFromText( "TestTitle" );
13 * Get parser output for Wiki text
15 * @return ParserOutput
17 private function getParserOutput( $text ) {
18 $content = new WikitextContent( $text );
19 return $content->getParserOutput( $this->getMockTitle() );
23 * Get WikitextStructure for given text
25 * @return WikiTextStructure
27 private function getStructure( $text ) {
28 return new WikiTextStructure( $this->getParserOutput( $text ) );
31 public function testHeadings() {
38 === Applicability of the strict mass-energy equivalence formula, ''E'' = ''mc''<sup>2</sup> ===
40 == Wikitext '''in''' [[Heading]] and also <b>html</b> ==
45 $struct = $this->getStructure( $text );
46 $headings = $struct->headings();
47 $this->assertCount( 4, $headings );
48 $this->assertContains( "Heading one", $headings );
49 $this->assertContains( "heading two", $headings );
50 $this->assertContains( "Applicability of the strict mass-energy equivalence formula, E = mc2",
52 $this->assertContains( "Wikitext in Heading and also html", $headings );
55 public function testDefaultSort() {
62 {{DEFAULTSORT:Michel, Louise}}
64 $struct = $this->getStructure( $text );
65 $this->assertEquals( "Michel, Louise", $struct->getDefaultSort() );
68 public function testHeadingsFirst() {
74 $struct = $this->getStructure( $text );
75 $headings = $struct->headings();
76 $this->assertCount( 2, $headings );
77 $this->assertContains( "Heading one", $headings );
78 $this->assertContains( "heading two", $headings );
81 public function testHeadingsNone() {
82 $text = "This text is completely devoid of headings.";
83 $struct = $this->getStructure( $text );
84 $headings = $struct->headings();
85 $this->assertArrayEquals( [], $headings );
88 public function testTexts() {
90 Opening text is opening.
91 == Then comes header ==
92 Then we got more<br>text
93 === And more headers ===
100 | another row in table
103 $struct = $this->getStructure( $text );
104 $this->assertEquals( "Opening text is opening.", $struct->getOpeningText() );
105 $this->assertEquals( "Opening text is opening. Then we got more text",
106 $struct->getMainText() );
107 $this->assertEquals( [ "Header table row in table another row in table" ],
108 $struct->getAuxiliaryText() );