MediaWiki REL1_30
WikitextStructureTest.php
Go to the documentation of this file.
1<?php
2
4
5 private function getMockTitle() {
6 return Title::newFromText( "TestTitle" );
7 }
8
14 private function getParserOutput( $text ) {
15 $content = new WikitextContent( $text );
16 return $content->getParserOutput( $this->getMockTitle() );
17 }
18
24 private function getStructure( $text ) {
25 return new WikiTextStructure( $this->getParserOutput( $text ) );
26 }
27
28 public function testHeadings() {
29 $text = <<<END
30Some text here
31== Heading one ==
32Some text
33==== heading two ====
34More text
35=== Applicability of the strict mass-energy equivalence formula, ''E'' = ''mc''<sup>2</sup> ===
36and more text
37== Wikitext '''in''' [[Heading]] and also <b>html</b> ==
38more text
39==== See also ====
40* Also things to see!
41END;
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",
48 $headings );
49 $this->assertContains( "Wikitext in Heading and also html", $headings );
50 }
51
52 public function testDefaultSort() {
53 $text = <<<END
54Louise Michel
55== Heading one ==
56Some text
57==== See also ====
58* Also things to see!
59{{DEFAULTSORT:Michel, Louise}}
60END;
61 $struct = $this->getStructure( $text );
62 $this->assertEquals( "Michel, Louise", $struct->getDefaultSort() );
63 }
64
65 public function testHeadingsFirst() {
66 $text = <<<END
67== Heading one ==
68Some text
69==== heading two ====
70END;
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 );
76 }
77
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 );
83 }
84
85 public function testTexts() {
86 $text = <<<END
87Opening text is opening.
88== Then comes header ==
89Then we got more<br>text
90=== And more headers ===
91{| class="wikitable"
92|-
93! Header table
94|-
95| row in table
96|-
97| another row in table
98|}
99END;
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() );
106 }
107}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software Also
Definition COPYING.txt:43
Base class that store and restore the Language objects.
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Class allowing to explore structure of parsed wikitext.
Content object for wiki text pages.
getParserOutput( $text)
Get parser output for Wiki text.
getStructure( $text)
Get WikitextStructure for given text.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs table
Definition deferred.txt:16
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add headers
Definition design.txt:18