Merge "Warn if stateful ParserOutput transforms are used"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserPreloadTest.php
1 <?php
2 /**
3 * Basic tests for Parser::getPreloadText
4 * @author Antoine Musso
5 *
6 * @covers Parser
7 * @covers StripState
8 *
9 * @covers Preprocessor_DOM
10 * @covers PPDStack
11 * @covers PPDStackElement
12 * @covers PPDPart
13 * @covers PPFrame_DOM
14 * @covers PPTemplateFrame_DOM
15 * @covers PPCustomFrame_DOM
16 * @covers PPNode_DOM
17 *
18 * @covers Preprocessor_Hash
19 * @covers PPDStack_Hash
20 * @covers PPDStackElement_Hash
21 * @covers PPDPart_Hash
22 * @covers PPFrame_Hash
23 * @covers PPTemplateFrame_Hash
24 * @covers PPCustomFrame_Hash
25 * @covers PPNode_Hash_Tree
26 * @covers PPNode_Hash_Text
27 * @covers PPNode_Hash_Array
28 * @covers PPNode_Hash_Attr
29 */
30 class ParserPreloadTest extends MediaWikiTestCase {
31 /**
32 * @var Parser
33 */
34 private $testParser;
35 /**
36 * @var ParserOptions
37 */
38 private $testParserOptions;
39 /**
40 * @var Title
41 */
42 private $title;
43
44 protected function setUp() {
45 global $wgContLang;
46
47 parent::setUp();
48 $this->testParserOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
49
50 $this->testParser = new Parser();
51 $this->testParser->Options( $this->testParserOptions );
52 $this->testParser->clearState();
53
54 $this->title = Title::newFromText( 'Preload Test' );
55 }
56
57 protected function tearDown() {
58 parent::tearDown();
59
60 unset( $this->testParser );
61 unset( $this->title );
62 }
63
64 public function testPreloadSimpleText() {
65 $this->assertPreloaded( 'simple', 'simple' );
66 }
67
68 public function testPreloadedPreIsUnstripped() {
69 $this->assertPreloaded(
70 '<pre>monospaced</pre>',
71 '<pre>monospaced</pre>',
72 '<pre> in preloaded text must be unstripped (T29467)'
73 );
74 }
75
76 public function testPreloadedNowikiIsUnstripped() {
77 $this->assertPreloaded(
78 '<nowiki>[[Dummy title]]</nowiki>',
79 '<nowiki>[[Dummy title]]</nowiki>',
80 '<nowiki> in preloaded text must be unstripped (T29467)'
81 );
82 }
83
84 protected function assertPreloaded( $expected, $text, $msg = '' ) {
85 $this->assertEquals(
86 $expected,
87 $this->testParser->getPreloadText(
88 $text,
89 $this->title,
90 $this->testParserOptions
91 ),
92 $msg
93 );
94 }
95 }