getParserOutput( $this->getMockTitle() ); } /** * Get WikitextStructure for given text * @param string $text * @return WikiTextStructure */ private function getStructure( $text ) { return new WikiTextStructure( $this->getParserOutput( $text ) ); } public function testHeadings() { $text = <<2 === and more text == Wikitext '''in''' [[Heading]] and also html == more text ==== See also ==== * Also things to see! END; $struct = $this->getStructure( $text ); $headings = $struct->headings(); $this->assertCount( 4, $headings ); $this->assertContains( "Heading one", $headings ); $this->assertContains( "heading two", $headings ); $this->assertContains( "Applicability of the strict mass-energy equivalence formula, E = mc2", $headings ); $this->assertContains( "Wikitext in Heading and also html", $headings ); } public function testDefaultSort() { $text = <<getStructure( $text ); $this->assertEquals( "Michel, Louise", $struct->getDefaultSort() ); } public function testHeadingsFirst() { $text = <<getStructure( $text ); $headings = $struct->headings(); $this->assertCount( 2, $headings ); $this->assertContains( "Heading one", $headings ); $this->assertContains( "heading two", $headings ); } public function testHeadingsNone() { $text = "This text is completely devoid of headings."; $struct = $this->getStructure( $text ); $headings = $struct->headings(); $this->assertArrayEquals( [], $headings ); } public function testTexts() { $text = <<text === And more headers === {| class="wikitable" |- ! Header table |- | row in table |- | another row in table |} END; $struct = $this->getStructure( $text ); $this->assertEquals( "Opening text is opening.", $struct->getOpeningText() ); $this->assertEquals( "Opening text is opening. Then we got more text", $struct->getMainText() ); $this->assertEquals( [ "Header table row in table another row in table" ], $struct->getAuxiliaryText() ); } public function testPreservesWordSpacing() { $text = "
foo
bar

baz

"; $struct = $this->getStructure( $text ); $this->assertEquals( "foo bar baz", $struct->getMainText() ); } }