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