]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - tests/phpunit/includes/parser/ParserPreloadTest.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / tests / phpunit / includes / parser / ParserPreloadTest.php
diff --git a/tests/phpunit/includes/parser/ParserPreloadTest.php b/tests/phpunit/includes/parser/ParserPreloadTest.php
new file mode 100644 (file)
index 0000000..7707395
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+/**
+ * Basic tests for Parser::getPreloadText
+ * @author Antoine Musso
+ *
+ * @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
+ */
+class ParserPreloadTest extends MediaWikiTestCase {
+       /**
+        * @var Parser
+        */
+       private $testParser;
+       /**
+        * @var ParserOptions
+        */
+       private $testParserOptions;
+       /**
+        * @var Title
+        */
+       private $title;
+
+       protected function setUp() {
+               global $wgContLang;
+
+               parent::setUp();
+               $this->testParserOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
+
+               $this->testParser = new Parser();
+               $this->testParser->Options( $this->testParserOptions );
+               $this->testParser->clearState();
+
+               $this->title = Title::newFromText( 'Preload Test' );
+       }
+
+       protected function tearDown() {
+               parent::tearDown();
+
+               unset( $this->testParser );
+               unset( $this->title );
+       }
+
+       public function testPreloadSimpleText() {
+               $this->assertPreloaded( 'simple', 'simple' );
+       }
+
+       public function testPreloadedPreIsUnstripped() {
+               $this->assertPreloaded(
+                       '<pre>monospaced</pre>',
+                       '<pre>monospaced</pre>',
+                       '<pre> in preloaded text must be unstripped (T29467)'
+               );
+       }
+
+       public function testPreloadedNowikiIsUnstripped() {
+               $this->assertPreloaded(
+                       '<nowiki>[[Dummy title]]</nowiki>',
+                       '<nowiki>[[Dummy title]]</nowiki>',
+                       '<nowiki> in preloaded text must be unstripped (T29467)'
+               );
+       }
+
+       protected function assertPreloaded( $expected, $text, $msg = '' ) {
+               $this->assertEquals(
+                       $expected,
+                       $this->testParser->getPreloadText(
+                               $text,
+                               $this->title,
+                               $this->testParserOptions
+                       ),
+                       $msg
+               );
+       }
+}