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 testDefaultSort() {
59 {{DEFAULTSORT:Michel, Louise}}
61 $struct = $this->getStructure( $text );
62 $this->assertEquals( "Michel, Louise", $struct->getDefaultSort() );
65 public function testHeadingsFirst() {
71 $struct = $this->getStructure( $text );
72 $headings = $struct->headings();
73 $this->assertCount( 2, $headings );
74 $this->assertContains( "Heading one", $headings );
75 $this->assertContains( "heading two", $headings );
78 public function testHeadingsNone() {
79 $text = "This text is completely devoid of headings.";
80 $struct = $this->getStructure( $text );
81 $headings = $struct->headings();
82 $this->assertArrayEquals( [], $headings );
85 public function testTexts() {
87 Opening text is opening.
88 == Then comes header ==
89 Then we got more<br>text
90 === And more headers ===
97 | another row in table
100 $struct = $this->getStructure( $text );
101 $this->assertEquals( "Opening text is opening.", $struct->getOpeningText() );
102 $this->assertEquals( "Opening text is opening. Then we got more text",
103 $struct->getMainText() );
104 $this->assertEquals( [ "Header table row in table another row in table" ],
105 $struct->getAuxiliaryText() );