2011-10-24 10:51:46 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Basic tests for Parser::getPreloadText
|
|
|
|
|
* @author Antoine Musso
|
2017-02-27 04:44:31 +00:00
|
|
|
*
|
|
|
|
|
* @covers Parser
|
|
|
|
|
* @covers StripState
|
|
|
|
|
*
|
|
|
|
|
* @covers Preprocessor_DOM
|
|
|
|
|
* @covers PPDStack
|
|
|
|
|
* @covers PPDStackElement
|
|
|
|
|
* @covers PPDPart
|
|
|
|
|
* @covers PPFrame_DOM
|
|
|
|
|
* @covers PPTemplateFrame_DOM
|
|
|
|
|
* @covers PPCustomFrame_DOM
|
|
|
|
|
* @covers PPNode_DOM
|
|
|
|
|
*
|
|
|
|
|
* @covers Preprocessor_Hash
|
|
|
|
|
* @covers PPDStack_Hash
|
|
|
|
|
* @covers PPDStackElement_Hash
|
|
|
|
|
* @covers PPDPart_Hash
|
|
|
|
|
* @covers PPFrame_Hash
|
|
|
|
|
* @covers PPTemplateFrame_Hash
|
|
|
|
|
* @covers PPCustomFrame_Hash
|
|
|
|
|
* @covers PPNode_Hash_Tree
|
|
|
|
|
* @covers PPNode_Hash_Text
|
|
|
|
|
* @covers PPNode_Hash_Array
|
|
|
|
|
* @covers PPNode_Hash_Attr
|
2011-10-24 10:51:46 +00:00
|
|
|
*/
|
|
|
|
|
class ParserPreloadTest extends MediaWikiTestCase {
|
2013-10-22 23:50:38 +00:00
|
|
|
/**
|
|
|
|
|
* @var Parser
|
|
|
|
|
*/
|
2011-10-24 10:51:46 +00:00
|
|
|
private $testParser;
|
2013-10-22 23:50:38 +00:00
|
|
|
/**
|
|
|
|
|
* @var ParserOptions
|
|
|
|
|
*/
|
2011-10-24 10:51:46 +00:00
|
|
|
private $testParserOptions;
|
2013-10-22 23:50:38 +00:00
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
2011-10-24 10:51:46 +00:00
|
|
|
private $title;
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2012-10-14 19:34:26 +00:00
|
|
|
global $wgContLang;
|
2012-10-23 17:02:36 +00:00
|
|
|
|
2012-10-14 19:34:26 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
$this->testParserOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
|
2011-10-24 10:51:46 +00:00
|
|
|
|
|
|
|
|
$this->testParser = new Parser();
|
|
|
|
|
$this->testParser->Options( $this->testParserOptions );
|
|
|
|
|
$this->testParser->clearState();
|
|
|
|
|
|
|
|
|
|
$this->title = Title::newFromText( 'Preload Test' );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function tearDown() {
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::tearDown();
|
|
|
|
|
|
2011-10-24 10:51:46 +00:00
|
|
|
unset( $this->testParser );
|
|
|
|
|
unset( $this->title );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 23:50:38 +00:00
|
|
|
public function testPreloadSimpleText() {
|
2011-10-24 10:51:46 +00:00
|
|
|
$this->assertPreloaded( 'simple', 'simple' );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 23:50:38 +00:00
|
|
|
public function testPreloadedPreIsUnstripped() {
|
2011-10-24 10:51:46 +00:00
|
|
|
$this->assertPreloaded(
|
|
|
|
|
'<pre>monospaced</pre>',
|
|
|
|
|
'<pre>monospaced</pre>',
|
2017-02-20 23:45:58 +00:00
|
|
|
'<pre> in preloaded text must be unstripped (T29467)'
|
2011-10-24 10:51:46 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 23:50:38 +00:00
|
|
|
public function testPreloadedNowikiIsUnstripped() {
|
2011-10-24 10:51:46 +00:00
|
|
|
$this->assertPreloaded(
|
|
|
|
|
'<nowiki>[[Dummy title]]</nowiki>',
|
|
|
|
|
'<nowiki>[[Dummy title]]</nowiki>',
|
2017-02-20 23:45:58 +00:00
|
|
|
'<nowiki> in preloaded text must be unstripped (T29467)'
|
2011-10-24 10:51:46 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 23:50:38 +00:00
|
|
|
protected function assertPreloaded( $expected, $text, $msg = '' ) {
|
2011-10-24 10:51:46 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected,
|
|
|
|
|
$this->testParser->getPreloadText(
|
|
|
|
|
$text,
|
|
|
|
|
$this->title,
|
|
|
|
|
$this->testParserOptions
|
|
|
|
|
),
|
|
|
|
|
$msg
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|