2016-05-16 20:24:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
2017-12-25 01:08:48 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiTextStructure
|
|
|
|
|
*/
|
2016-05-16 20:24:10 +00:00
|
|
|
class WikitextStructureTest extends MediaWikiLangTestCase {
|
|
|
|
|
|
|
|
|
|
private function getMockTitle() {
|
|
|
|
|
return Title::newFromText( "TestTitle" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get parser output for Wiki text
|
2017-08-11 15:46:31 +00:00
|
|
|
* @param string $text
|
2016-05-16 20:24:10 +00:00
|
|
|
* @return ParserOutput
|
|
|
|
|
*/
|
|
|
|
|
private function getParserOutput( $text ) {
|
|
|
|
|
$content = new WikitextContent( $text );
|
|
|
|
|
return $content->getParserOutput( $this->getMockTitle() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get WikitextStructure for given text
|
2017-08-11 15:46:31 +00:00
|
|
|
* @param string $text
|
2016-05-16 20:24:10 +00:00
|
|
|
* @return WikiTextStructure
|
|
|
|
|
*/
|
|
|
|
|
private function getStructure( $text ) {
|
|
|
|
|
return new WikiTextStructure( $this->getParserOutput( $text ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testHeadings() {
|
|
|
|
|
$text = <<<END
|
|
|
|
|
Some text here
|
|
|
|
|
== Heading one ==
|
|
|
|
|
Some text
|
|
|
|
|
==== heading two ====
|
|
|
|
|
More text
|
|
|
|
|
=== Applicability of the strict mass-energy equivalence formula, ''E'' = ''mc''<sup>2</sup> ===
|
|
|
|
|
and more text
|
|
|
|
|
== Wikitext '''in''' [[Heading]] and also <b>html</b> ==
|
|
|
|
|
more text
|
2016-06-14 21:01:13 +00:00
|
|
|
==== See also ====
|
|
|
|
|
* Also things to see!
|
2016-05-16 20:24:10 +00:00
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 14:30:43 +00:00
|
|
|
public function testDefaultSort() {
|
|
|
|
|
$text = <<<END
|
|
|
|
|
Louise Michel
|
|
|
|
|
== Heading one ==
|
|
|
|
|
Some text
|
|
|
|
|
==== See also ====
|
|
|
|
|
* Also things to see!
|
|
|
|
|
{{DEFAULTSORT:Michel, Louise}}
|
|
|
|
|
END;
|
|
|
|
|
$struct = $this->getStructure( $text );
|
|
|
|
|
$this->assertEquals( "Michel, Louise", $struct->getDefaultSort() );
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-16 20:24:10 +00:00
|
|
|
public function testHeadingsFirst() {
|
|
|
|
|
$text = <<<END
|
|
|
|
|
== Heading one ==
|
|
|
|
|
Some text
|
|
|
|
|
==== heading two ====
|
|
|
|
|
END;
|
|
|
|
|
$struct = $this->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 = <<<END
|
|
|
|
|
Opening text is opening.
|
|
|
|
|
== Then comes header ==
|
|
|
|
|
Then we got more<br>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() );
|
2018-03-01 23:02:54 +00:00
|
|
|
$this->assertEquals( [ "Header table row in table another row in table" ],
|
2016-05-16 20:24:10 +00:00
|
|
|
$struct->getAuxiliaryText() );
|
|
|
|
|
}
|
|
|
|
|
}
|