wiki.techinc.nl/tests/phpunit/includes/parser/ParserPreloadTest.php

96 lines
2 KiB
PHP
Raw Normal View History

<?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;
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
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' );
}
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
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
);
}
}