Merge "Add language handling to imageinfo/extmetadata API"
[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 class ParserPreloadTest extends MediaWikiTestCase {
7 /**
8 * @var Parser
9 */
10 private $testParser;
11 /**
12 * @var ParserOptions
13 */
14 private $testParserOptions;
15 /**
16 * @var Title
17 */
18 private $title;
19
20 protected function setUp() {
21 global $wgContLang;
22
23 parent::setUp();
24 $this->testParserOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
25
26 $this->testParser = new Parser();
27 $this->testParser->Options( $this->testParserOptions );
28 $this->testParser->clearState();
29
30 $this->title = Title::newFromText( 'Preload Test' );
31 }
32
33 protected function tearDown() {
34 parent::tearDown();
35
36 unset( $this->testParser );
37 unset( $this->title );
38 }
39
40 /**
41 * @covers Parser::getPreloadText
42 */
43 public function testPreloadSimpleText() {
44 $this->assertPreloaded( 'simple', 'simple' );
45 }
46
47 /**
48 * @covers Parser::getPreloadText
49 */
50 public function testPreloadedPreIsUnstripped() {
51 $this->assertPreloaded(
52 '<pre>monospaced</pre>',
53 '<pre>monospaced</pre>',
54 '<pre> in preloaded text must be unstripped (bug 27467)'
55 );
56 }
57
58 /**
59 * @covers Parser::getPreloadText
60 */
61 public function testPreloadedNowikiIsUnstripped() {
62 $this->assertPreloaded(
63 '<nowiki>[[Dummy title]]</nowiki>',
64 '<nowiki>[[Dummy title]]</nowiki>',
65 '<nowiki> in preloaded text must be unstripped (bug 27467)'
66 );
67 }
68
69 protected function assertPreloaded( $expected, $text, $msg = '' ) {
70 $this->assertEquals(
71 $expected,
72 $this->testParser->getPreloadText(
73 $text,
74 $this->title,
75 $this->testParserOptions
76 ),
77 $msg
78 );
79 }
80 }