summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/parser
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/parser')
-rw-r--r--tests/phpunit/includes/parser/MagicVariableTest.php153
-rw-r--r--tests/phpunit/includes/parser/MediaWikiParserTest.php114
-rw-r--r--tests/phpunit/includes/parser/NewParserTest.php450
-rw-r--r--tests/phpunit/includes/parser/ParserMethodsTest.php74
-rw-r--r--tests/phpunit/includes/parser/ParserOutputTest.php59
-rw-r--r--tests/phpunit/includes/parser/ParserPreloadTest.php29
-rw-r--r--tests/phpunit/includes/parser/PreprocessorTest.php108
-rw-r--r--tests/phpunit/includes/parser/TagHooksTest.php61
-rw-r--r--tests/phpunit/includes/parser/TidyTest.php44
9 files changed, 740 insertions, 352 deletions
diff --git a/tests/phpunit/includes/parser/MagicVariableTest.php b/tests/phpunit/includes/parser/MagicVariableTest.php
index 31645313..c2c97c01 100644
--- a/tests/phpunit/includes/parser/MagicVariableTest.php
+++ b/tests/phpunit/includes/parser/MagicVariableTest.php
@@ -9,11 +9,13 @@
* @author Antoine Musso
* @copyright Copyright © 2011, Antoine Musso
* @file
+ * @todo covers tags
*/
-/** */
class MagicVariableTest extends MediaWikiTestCase {
- /** Will contains a parser object*/
+ /**
+ * @var Parser
+ */
private $testParser = null;
/**
@@ -29,12 +31,17 @@ class MagicVariableTest extends MediaWikiTestCase {
);
/** setup a basic parser object */
- function setUp() {
- global $wgContLang;
- $wgContLang = Language::factory( 'en' );
+ protected function setUp() {
+ parent::setUp();
+
+ $contLang = Language::factory( 'en' );
+ $this->setMwGlobals( array(
+ 'wgLanguageCode' => 'en',
+ 'wgContLang' => $contLang,
+ ) );
$this->testParser = new Parser();
- $this->testParser->Options( new ParserOptions() );
+ $this->testParser->Options( ParserOptions::newFromUserAndLang( new User, $contLang ) );
# initialize parser output
$this->testParser->clearState();
@@ -46,9 +53,31 @@ class MagicVariableTest extends MediaWikiTestCase {
$this->testParser->setTitle( $title );
}
- /** destroy parser (TODO: is it really neded?)*/
- function tearDown() {
- unset( $this->testParser );
+ /**
+ * @param int $num upper limit for numbers
+ * @return array of numbers from 1 up to $num
+ */
+ private static function createProviderUpTo( $num ) {
+ $ret = array();
+ for ( $i = 1; $i <= $num; $i++ ) {
+ $ret[] = array( $i );
+ }
+
+ return $ret;
+ }
+
+ /**
+ * @return array of months numbers (as an integer)
+ */
+ public static function provideMonths() {
+ return self::createProviderUpTo( 12 );
+ }
+
+ /**
+ * @return array of days numbers (as an integer)
+ */
+ public static function provideDays() {
+ return self::createProviderUpTo( 31 );
}
############### TESTS #############################################
@@ -58,117 +87,129 @@ class MagicVariableTest extends MediaWikiTestCase {
# day
- /** @dataProvider MediaWikiProvide::Days */
- function testCurrentdayIsUnPadded( $day ) {
+ /** @dataProvider provideDays */
+ public function testCurrentdayIsUnPadded( $day ) {
$this->assertUnPadded( 'currentday', $day );
}
- /** @dataProvider MediaWikiProvide::Days */
- function testCurrentdaytwoIsZeroPadded( $day ) {
+
+ /** @dataProvider provideDays */
+ public function testCurrentdaytwoIsZeroPadded( $day ) {
$this->assertZeroPadded( 'currentday2', $day );
}
- /** @dataProvider MediaWikiProvide::Days */
- function testLocaldayIsUnPadded( $day ) {
+
+ /** @dataProvider provideDays */
+ public function testLocaldayIsUnPadded( $day ) {
$this->assertUnPadded( 'localday', $day );
}
- /** @dataProvider MediaWikiProvide::Days */
- function testLocaldaytwoIsZeroPadded( $day ) {
+
+ /** @dataProvider provideDays */
+ public function testLocaldaytwoIsZeroPadded( $day ) {
$this->assertZeroPadded( 'localday2', $day );
}
-
+
# month
- /** @dataProvider MediaWikiProvide::Months */
- function testCurrentmonthIsZeroPadded( $month ) {
+ /** @dataProvider provideMonths */
+ public function testCurrentmonthIsZeroPadded( $month ) {
$this->assertZeroPadded( 'currentmonth', $month );
}
- /** @dataProvider MediaWikiProvide::Months */
- function testCurrentmonthoneIsUnPadded( $month ) {
+
+ /** @dataProvider provideMonths */
+ public function testCurrentmonthoneIsUnPadded( $month ) {
$this->assertUnPadded( 'currentmonth1', $month );
}
- /** @dataProvider MediaWikiProvide::Months */
- function testLocalmonthIsZeroPadded( $month ) {
+
+ /** @dataProvider provideMonths */
+ public function testLocalmonthIsZeroPadded( $month ) {
$this->assertZeroPadded( 'localmonth', $month );
}
- /** @dataProvider MediaWikiProvide::Months */
- function testLocalmonthoneIsUnPadded( $month ) {
+
+ /** @dataProvider provideMonths */
+ public function testLocalmonthoneIsUnPadded( $month ) {
$this->assertUnPadded( 'localmonth1', $month );
}
-
# revision day
- /** @dataProvider MediaWikiProvide::Days */
- function testRevisiondayIsUnPadded( $day ) {
+ /** @dataProvider provideDays */
+ public function testRevisiondayIsUnPadded( $day ) {
$this->assertUnPadded( 'revisionday', $day );
}
- /** @dataProvider MediaWikiProvide::Days */
- function testRevisiondaytwoIsZeroPadded( $day ) {
+
+ /** @dataProvider provideDays */
+ public function testRevisiondaytwoIsZeroPadded( $day ) {
$this->assertZeroPadded( 'revisionday2', $day );
}
-
+
# revision month
- /** @dataProvider MediaWikiProvide::Months */
- function testRevisionmonthIsZeroPadded( $month ) {
+ /** @dataProvider provideMonths */
+ public function testRevisionmonthIsZeroPadded( $month ) {
$this->assertZeroPadded( 'revisionmonth', $month );
}
- /** @dataProvider MediaWikiProvide::Months */
- function testRevisionmonthoneIsUnPadded( $month ) {
+
+ /** @dataProvider provideMonths */
+ public function testRevisionmonthoneIsUnPadded( $month ) {
$this->assertUnPadded( 'revisionmonth1', $month );
}
/**
* Rough tests for {{SERVERNAME}} magic word
* Bug 31176
+ * @group Database
+ * @dataProvider provideDataServernameFromDifferentProtocols
*/
- function testServernameFromDifferentProtocols() {
- global $wgServer;
- $saved_wgServer= $wgServer;
+ public function testServernameFromDifferentProtocols( $server ) {
+ $this->setMwGlobals( 'wgServer', $server );
- $wgServer = 'http://localhost/';
- $this->assertMagic( 'localhost', 'servername' );
- $wgServer = 'https://localhost/';
- $this->assertMagic( 'localhost', 'servername' );
- $wgServer = '//localhost/'; # bug 31176
$this->assertMagic( 'localhost', 'servername' );
+ }
- $wgServer = $saved_wgServer;
+ public static function provideDataServernameFromDifferentProtocols() {
+ return array(
+ array( 'http://localhost/' ),
+ array( 'https://localhost/' ),
+ array( '//localhost/' ), # bug 31176
+ );
}
############### HELPERS ############################################
/** assertion helper expecting a magic output which is zero padded */
- PUBLIC function assertZeroPadded( $magic, $value ) {
+ public function assertZeroPadded( $magic, $value ) {
$this->assertMagicPadding( $magic, $value, '%02d' );
}
/** assertion helper expecting a magic output which is unpadded */
- PUBLIC function assertUnPadded( $magic, $value ) {
+ public function assertUnPadded( $magic, $value ) {
$this->assertMagicPadding( $magic, $value, '%d' );
}
/**
* Main assertion helper for magic variables padding
- * @param $magic string Magic variable name
+ * @param $magic string Magic variable name
* @param $value mixed Month or day
- * @param $format string sprintf format for $value
+ * @param $format string sprintf format for $value
*/
private function assertMagicPadding( $magic, $value, $format ) {
# Initialize parser timestamp as year 2010 at 12h34 56s.
# month and day are given by the caller ($value). Month < 12!
- if( $value > 12 ) { $month = $value % 12; }
- else { $month = $value; }
-
+ if ( $value > 12 ) {
+ $month = $value % 12;
+ } else {
+ $month = $value;
+ }
+
$this->setParserTS(
sprintf( '2010%02d%02d123456', $month, $value )
);
- # please keep the following commented line of code. It helps debugging.
+ # please keep the following commented line of code. It helps debugging.
//print "\nDEBUG (value $value):" . sprintf( '2010%02d%02d123456', $value, $value ) . "\n";
# format expectation and test it
$expected = sprintf( $format, $value );
- $this->assertMagic( $expected, $magic );
+ $this->assertMagic( $expected, $magic );
}
/** helper to set the parser timestamp and revision timestamp */
@@ -181,8 +222,8 @@ class MagicVariableTest extends MediaWikiTestCase {
* Assertion helper to test a magic variable output
*/
private function assertMagic( $expected, $magic ) {
- if( in_array( $magic, $this->expectedAsInteger ) ) {
- $expected = (int) $expected;
+ if ( in_array( $magic, $this->expectedAsInteger ) ) {
+ $expected = (int)$expected;
}
# Generate a message for the assertion
diff --git a/tests/phpunit/includes/parser/MediaWikiParserTest.php b/tests/phpunit/includes/parser/MediaWikiParserTest.php
index 6a6fded1..c120ca34 100644
--- a/tests/phpunit/includes/parser/MediaWikiParserTest.php
+++ b/tests/phpunit/includes/parser/MediaWikiParserTest.php
@@ -1,36 +1,120 @@
<?php
-require_once( __DIR__ . '/NewParserTest.php' );
+require_once __DIR__ . '/NewParserTest.php';
/**
* The UnitTest must be either a class that inherits from MediaWikiTestCase
- * or a class that provides a public static suite() method which returns
+ * or a class that provides a public static suite() method which returns
* an PHPUnit_Framework_Test object
- *
+ *
* @group Parser
* @group Database
*/
class MediaWikiParserTest {
- public static function suite() {
- global $wgParserTestFiles;
+ /**
+ * @defgroup filtering_constants Filtering constants
+ *
+ * Limit inclusion of parser tests files coming from MediaWiki core
+ * @{
+ */
- $suite = new PHPUnit_Framework_TestSuite;
+ /** Include files shipped with MediaWiki core */
+ const CORE_ONLY = 1;
+ /** Include non core files as set in $wgParserTestFiles */
+ const NO_CORE = 2;
+ /** Include anything set via $wgParserTestFiles */
+ const WITH_ALL = 3; # CORE_ONLY | NO_CORE
+
+ /** @} */
+
+ /**
+ * Get a PHPUnit test suite of parser tests. Optionally filtered with
+ * $flags.
+ *
+ * @par Examples:
+ * Get a suite of parser tests shipped by MediaWiki core:
+ * @code
+ * MediaWikiParserTest::suite( MediaWikiParserTest::CORE_ONLY );
+ * @endcode
+ * Get a suite of various parser tests, like extensions:
+ * @code
+ * MediaWikiParserTest::suite( MediaWikiParserTest::NO_CORE );
+ * @endcode
+ * Get any test defined via $wgParserTestFiles:
+ * @code
+ * MediaWikiParserTest::suite( MediaWikiParserTest::WITH_ALL );
+ * @endcode
+ *
+ * @param $flags bitwise flag to filter out the $wgParserTestFiles that
+ * will be included. Default: MediaWikiParserTest::CORE_ONLY
+ *
+ * @return PHPUnit_Framework_TestSuite
+ */
+ public static function suite( $flags = self::CORE_ONLY ) {
+ if ( is_string( $flags ) ) {
+ $flags = self::CORE_ONLY;
+ }
+ global $wgParserTestFiles, $IP;
+
+ $mwTestDir = $IP . '/tests/';
+
+ # Human friendly helpers
+ $wantsCore = ( $flags & self::CORE_ONLY );
+ $wantsRest = ( $flags & self::NO_CORE );
+
+ # Will hold the .txt parser test files we will include
+ $filesToTest = array();
+
+ # Filter out .txt files
+ foreach ( $wgParserTestFiles as $parserTestFile ) {
+ $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) );
+
+ if ( $isCore && $wantsCore ) {
+ self::debug( "included core parser tests: $parserTestFile" );
+ $filesToTest[] = $parserTestFile;
+ } elseif ( !$isCore && $wantsRest ) {
+ self::debug( "included non core parser tests: $parserTestFile" );
+ $filesToTest[] = $parserTestFile;
+ } else {
+ self::debug( "skipped parser tests: $parserTestFile" );
+ }
+ }
+ self::debug( 'parser tests files: '
+ . implode( ' ', $filesToTest ) );
- foreach ( $wgParserTestFiles as $filename ) {
- $testsName = basename( $filename, '.txt' );
+ $suite = new PHPUnit_Framework_TestSuite;
+ foreach ( $filesToTest as $fileName ) {
+ $testsName = basename( $fileName, '.txt' );
+ $escapedFileName = strtr( $fileName, array( "'" => "\\'", '\\' => '\\\\' ) );
/* This used to be ucfirst( basename( dirname( $filename ) ) )
* and then was ucfirst( basename( $filename, '.txt' )
* but that didn't work with names like foo.tests.txt
*/
- $className = str_replace( '.', '_', ucfirst( basename( $filename, '.txt' ) ) );
-
- eval( "/** @group Database\n@group Parser\n*/ class $className extends NewParserTest { protected \$file = '" . strtr( $filename, array( "'" => "\\'", '\\' => '\\\\' ) ) . "'; } " );
+ $parserTestClassName = str_replace( '.', '_', ucfirst( $testsName ) );
+ $parserTestClassDefinition = <<<EOT
+/**
+ * @group Database
+ * @group Parser
+ * @group ParserTests
+ * @group ParserTests_$parserTestClassName
+ */
+class $parserTestClassName extends NewParserTest {
+ protected \$file = '$escapedFileName';
+}
+EOT;
- $parserTester = new $className( $testsName );
- $suite->addTestSuite( new ReflectionClass ( $parserTester ) );
+ eval( $parserTestClassDefinition );
+ self::debug( "Adding test class $parserTestClassName" );
+ $suite->addTestSuite( $parserTestClassName );
}
-
-
return $suite;
}
+
+ /**
+ * Write $msg under log group 'tests-parser'
+ * @param string $msg Message to log
+ */
+ protected static function debug( $msg ) {
+ return wfDebugLog( 'tests-parser', wfGetCaller() . ' ' . $msg );
+ }
}
diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php
index 69a96e66..eac4de5c 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -6,19 +6,21 @@
* @group Database
* @group Parser
* @group Stub
+ *
+ * @todo covers tags
*/
class NewParserTest extends MediaWikiTestCase {
- static protected $articles = array(); // Array of test articles defined by the tests
- /* The dataProvider is run on a different instance than the test, so it must be static
+ static protected $articles = array(); // Array of test articles defined by the tests
+ /* The data provider is run on a different instance than the test, so it must be static
* When running tests from several files, all tests will see all articles.
*/
static protected $backendToUse;
public $keepUploads = false;
public $runDisabled = false;
+ public $runParsoid = false;
public $regex = '';
public $showProgress = true;
- public $savedInitialGlobals = array();
public $savedWeirdGlobals = array();
public $savedGlobals = array();
public $hooks = array();
@@ -31,10 +33,16 @@ class NewParserTest extends MediaWikiTestCase {
protected $file = false;
- function setUp() {
- global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases;
+ public static function setUpBeforeClass() {
+ // Inject ParserTest well-known interwikis
+ ParserTest::setupInterwikis();
+ }
+
+ protected function setUp() {
+ global $wgNamespaceAliases, $wgContLang;
global $wgHooks, $IP;
- $wgContLang = Language::factory( 'en' );
+
+ parent::setUp();
//Setup CLI arguments
if ( $this->getCliArg( 'regex=' ) ) {
@@ -48,133 +56,138 @@ class NewParserTest extends MediaWikiTestCase {
$tmpGlobals = array();
+ $tmpGlobals['wgLanguageCode'] = 'en';
+ $tmpGlobals['wgContLang'] = Language::factory( 'en' );
+ $tmpGlobals['wgSitename'] = 'MediaWiki';
+ $tmpGlobals['wgServer'] = 'http://example.org';
$tmpGlobals['wgScript'] = '/index.php';
$tmpGlobals['wgScriptPath'] = '/';
$tmpGlobals['wgArticlePath'] = '/wiki/$1';
- $tmpGlobals['wgStyleSheetPath'] = '/skins';
+ $tmpGlobals['wgActionPaths'] = array();
+ $tmpGlobals['wgVariantArticlePath'] = false;
+ $tmpGlobals['wgExtensionAssetsPath'] = '/extensions';
$tmpGlobals['wgStylePath'] = '/skins';
+ $tmpGlobals['wgEnableUploads'] = true;
$tmpGlobals['wgThumbnailScriptPath'] = false;
$tmpGlobals['wgLocalFileRepo'] = array(
- 'class' => 'LocalRepo',
- 'name' => 'local',
- 'url' => 'http://example.com/images',
- 'hashLevels' => 2,
+ 'class' => 'LocalRepo',
+ 'name' => 'local',
+ 'url' => 'http://example.com/images',
+ 'hashLevels' => 2,
'transformVia404' => false,
- 'backend' => 'local-backend'
+ 'backend' => 'local-backend'
);
$tmpGlobals['wgForeignFileRepos'] = array();
+ $tmpGlobals['wgDefaultExternalStore'] = array();
$tmpGlobals['wgEnableParserCache'] = false;
- $tmpGlobals['wgHooks'] = $wgHooks;
+ $tmpGlobals['wgCapitalLinks'] = true;
+ $tmpGlobals['wgNoFollowLinks'] = true;
+ $tmpGlobals['wgNoFollowDomainExceptions'] = array();
+ $tmpGlobals['wgExternalLinkTarget'] = false;
+ $tmpGlobals['wgThumbnailScriptPath'] = false;
+ $tmpGlobals['wgUseImageResize'] = true;
+ $tmpGlobals['wgAllowExternalImages'] = true;
+ $tmpGlobals['wgRawHtml'] = false;
+ $tmpGlobals['wgUseTidy'] = false;
+ $tmpGlobals['wgAlwaysUseTidy'] = false;
+ $tmpGlobals['wgWellFormedXml'] = true;
+ $tmpGlobals['wgAllowMicrodataAttributes'] = true;
+ $tmpGlobals['wgExperimentalHtmlIds'] = false;
+ $tmpGlobals['wgAdaptiveMessageCache'] = true;
+ $tmpGlobals['wgUseDatabaseMessages'] = true;
+ $tmpGlobals['wgLocaltimezone'] = 'UTC';
$tmpGlobals['wgDeferredUpdateList'] = array();
- $tmpGlobals['wgMemc'] = wfGetMainCache();
- $tmpGlobals['messageMemc'] = wfGetMessageCacheStorage();
- $tmpGlobals['parserMemc'] = wfGetParserCacheStorage();
+ $tmpGlobals['wgGroupPermissions'] = array(
+ '*' => array(
+ 'createaccount' => true,
+ 'read' => true,
+ 'edit' => true,
+ 'createpage' => true,
+ 'createtalk' => true,
+ ) );
+ $tmpGlobals['wgNamespaceProtection'] = array( NS_MEDIAWIKI => 'editinterface' );
- // $tmpGlobals['wgContLang'] = new StubContLang;
- $tmpGlobals['wgUser'] = new User;
- $context = new RequestContext();
- $tmpGlobals['wgLang'] = $context->getLanguage();
- $tmpGlobals['wgOut'] = $context->getOutput();
- $tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
- $tmpGlobals['wgRequest'] = $context->getRequest();
+ $tmpGlobals['wgParser'] = new StubObject(
+ 'wgParser', $GLOBALS['wgParserConf']['class'],
+ array( $GLOBALS['wgParserConf'] ) );
+
+ $tmpGlobals['wgFileExtensions'][] = 'svg';
+ $tmpGlobals['wgSVGConverter'] = 'rsvg';
+ $tmpGlobals['wgSVGConverters']['rsvg'] =
+ '$path/rsvg-convert -w $width -h $height $input -o $output';
if ( $GLOBALS['wgStyleDirectory'] === false ) {
$tmpGlobals['wgStyleDirectory'] = "$IP/skins";
}
+ # Replace all media handlers with a mock. We do not need to generate
+ # actual thumbnails to do parser testing, we only care about receiving
+ # a ThumbnailImage properly initialized.
+ global $wgMediaHandlers;
+ foreach ( $wgMediaHandlers as $type => $handler ) {
+ $tmpGlobals['wgMediaHandlers'][$type] = 'MockBitmapHandler';
+ }
+ // Vector images have to be handled slightly differently
+ $tmpGlobals['wgMediaHandlers']['image/svg+xml'] = 'MockSvgHandler';
- foreach ( $tmpGlobals as $var => $val ) {
- if ( array_key_exists( $var, $GLOBALS ) ) {
- $this->savedInitialGlobals[$var] = $GLOBALS[$var];
- }
+ $tmpHooks = $wgHooks;
+ $tmpHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
+ $tmpHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
+ $tmpGlobals['wgHooks'] = $tmpHooks;
+ # add a namespace shadowing a interwiki link, to test
+ # proper precedence when resolving links. (bug 51680)
+ $tmpGlobals['wgExtraNamespaces'] = array( 100 => 'MemoryAlpha' );
- $GLOBALS[$var] = $val;
- }
+ $this->setMwGlobals( $tmpGlobals );
- $this->savedWeirdGlobals['mw_namespace_protection'] = $wgNamespaceProtection[NS_MEDIAWIKI];
$this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
$this->savedWeirdGlobals['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
- $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
$wgNamespaceAliases['Image'] = NS_FILE;
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
- }
- public function tearDown() {
- foreach ( $this->savedInitialGlobals as $var => $val ) {
- $GLOBALS[$var] = $val;
- }
+ MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
+ $wgContLang->resetNamespaces(); # reset namespace cache
+ }
- global $wgNamespaceProtection, $wgNamespaceAliases;
+ protected function tearDown() {
+ global $wgNamespaceAliases, $wgContLang;
- $wgNamespaceProtection[NS_MEDIAWIKI] = $this->savedWeirdGlobals['mw_namespace_protection'];
$wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias'];
$wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias'];
// Restore backends
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
+
+ // Remove temporary pages from the link cache
+ LinkCache::singleton()->clear();
+
+ // Restore message cache (temporary pages and $wgUseDatabaseMessages)
+ MessageCache::destroyInstance();
+
+ parent::tearDown();
+
+ MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
+ $wgContLang->resetNamespaces(); # reset namespace cache
+ }
+
+ public static function tearDownAfterClass() {
+ ParserTest::tearDownInterwikis();
+ parent::tearDownAfterClass();
}
function addDBData() {
$this->tablesUsed[] = 'site_stats';
- $this->tablesUsed[] = 'interwiki';
# disabled for performance
#$this->tablesUsed[] = 'image';
- # Hack: insert a few Wikipedia in-project interwiki prefixes,
- # for testing inter-language links
- $this->db->insert( 'interwiki', array(
- array( 'iw_prefix' => 'wikipedia',
- 'iw_url' => 'http://en.wikipedia.org/wiki/$1',
- 'iw_api' => '',
- 'iw_wikiid' => '',
- 'iw_local' => 0 ),
- array( 'iw_prefix' => 'meatball',
- 'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1',
- 'iw_api' => '',
- 'iw_wikiid' => '',
- 'iw_local' => 0 ),
- array( 'iw_prefix' => 'zh',
- 'iw_url' => 'http://zh.wikipedia.org/wiki/$1',
- 'iw_api' => '',
- 'iw_wikiid' => '',
- 'iw_local' => 1 ),
- array( 'iw_prefix' => 'es',
- 'iw_url' => 'http://es.wikipedia.org/wiki/$1',
- 'iw_api' => '',
- 'iw_wikiid' => '',
- 'iw_local' => 1 ),
- array( 'iw_prefix' => 'fr',
- 'iw_url' => 'http://fr.wikipedia.org/wiki/$1',
- 'iw_api' => '',
- 'iw_wikiid' => '',
- 'iw_local' => 1 ),
- array( 'iw_prefix' => 'ru',
- 'iw_url' => 'http://ru.wikipedia.org/wiki/$1',
- 'iw_api' => '',
- 'iw_wikiid' => '',
- 'iw_local' => 1 ),
- /**
- * @todo Fixme! Why are we inserting duplicate data here? Shouldn't
- * need this IGNORE or shouldn't need the insert at all.
- */
- ), __METHOD__, array( 'IGNORE' )
- );
-
-
# Update certain things in site_stats
$this->db->insert( 'site_stats',
array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ),
__METHOD__
);
- # Reinitialise the LocalisationCache to match the database state
- Language::getLocalisationCache()->unloadAll();
-
- # Clear the message cache
- MessageCache::singleton()->clear();
-
$user = User::newFromId( 0 );
LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
@@ -182,6 +195,10 @@ class NewParserTest extends MediaWikiTestCase {
# We will upload the actual files later. Note that if anything causes LocalFile::load()
# to be triggered before then, it will break via maybeUpgrade() setting the fileExists
# member to false and storing it in cache.
+ # note that the size/width/height/bits/etc of the file
+ # are actually set by inspecting the file itself; the arguments
+ # to recordUpload2 have no effect. That said, we try to make things
+ # match up so it is less confusing to readers of the code & tests.
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) );
if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
$image->recordUpload2(
@@ -189,19 +206,39 @@ class NewParserTest extends MediaWikiTestCase {
'Upload of some lame file',
'Some lame file',
array(
- 'size' => 12345,
- 'width' => 1941,
- 'height' => 220,
- 'bits' => 24,
- 'media_type' => MEDIATYPE_BITMAP,
- 'mime' => 'image/jpeg',
- 'metadata' => serialize( array() ),
- 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
- 'fileExists' => true ),
+ 'size' => 7881,
+ 'width' => 1941,
+ 'height' => 220,
+ 'bits' => 8,
+ 'media_type' => MEDIATYPE_BITMAP,
+ 'mime' => 'image/jpeg',
+ 'metadata' => serialize( array() ),
+ 'sha1' => wfBaseConvert( '1', 16, 36, 31 ),
+ 'fileExists' => true ),
$this->db->timestamp( '20010115123500' ), $user
);
}
+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Thumb.png' ) );
+ if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
+ $image->recordUpload2(
+ '', // archive name
+ 'Upload of some lame thumbnail',
+ 'Some lame thumbnail',
+ array(
+ 'size' => 22589,
+ 'width' => 135,
+ 'height' => 135,
+ 'bits' => 8,
+ 'media_type' => MEDIATYPE_BITMAP,
+ 'mime' => 'image/png',
+ 'metadata' => serialize( array() ),
+ 'sha1' => wfBaseConvert( '2', 16, 36, 31 ),
+ 'fileExists' => true ),
+ $this->db->timestamp( '20130225203040' ), $user
+ );
+ }
+
# This image will be blacklisted in [[MediaWiki:Bad image list]]
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) );
if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
@@ -210,30 +247,41 @@ class NewParserTest extends MediaWikiTestCase {
'zomgnotcensored',
'Borderline image',
array(
+ 'size' => 12345,
+ 'width' => 320,
+ 'height' => 240,
+ 'bits' => 24,
+ 'media_type' => MEDIATYPE_BITMAP,
+ 'mime' => 'image/jpeg',
+ 'metadata' => serialize( array() ),
+ 'sha1' => wfBaseConvert( '3', 16, 36, 31 ),
+ 'fileExists' => true ),
+ $this->db->timestamp( '20010115123500' ), $user
+ );
+ }
+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.svg' ) );
+ if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
+ $image->recordUpload2( '', 'Upload of some lame SVG', 'Some lame SVG', array(
'size' => 12345,
- 'width' => 320,
- 'height' => 240,
+ 'width' => 200,
+ 'height' => 200,
'bits' => 24,
- 'media_type' => MEDIATYPE_BITMAP,
- 'mime' => 'image/jpeg',
+ 'media_type' => MEDIATYPE_DRAWING,
+ 'mime' => 'image/svg+xml',
'metadata' => serialize( array() ),
'sha1' => wfBaseConvert( '', 16, 36, 31 ),
- 'fileExists' => true ),
- $this->db->timestamp( '20010115123500' ), $user
- );
+ 'fileExists' => true
+ ), $this->db->timestamp( '20010115123500' ), $user );
}
}
-
-
-
//ParserTest setup/teardown functions
/**
* Set up the global variables for a consistent environment for each test.
* Ideally this should replace the global configuration entirely.
*/
- protected function setupGlobals( $opts = '', $config = '' ) {
+ protected function setupGlobals( $opts = array(), $config = '' ) {
global $wgFileBackends;
# Find out values for some special options.
$lang =
@@ -263,73 +311,39 @@ class NewParserTest extends MediaWikiTestCase {
$backend = self::$backendToUse;
}
} else {
- $backend = new FSFileBackend( array(
- 'name' => 'local-backend',
+ # Replace with a mock. We do not care about generating real
+ # files on the filesystem, just need to expose the file
+ # informations.
+ $backend = new MockFileBackend( array(
+ 'name' => 'local-backend',
'lockManager' => 'nullLockManager',
'containerPaths' => array(
'local-public' => "$uploadDir",
- 'local-thumb' => "$uploadDir/thumb",
+ 'local-thumb' => "$uploadDir/thumb",
)
) );
}
$settings = array(
- 'wgServer' => 'http://Britney-Spears',
- 'wgScript' => '/index.php',
- 'wgScriptPath' => '/',
- 'wgArticlePath' => '/wiki/$1',
- 'wgExtensionAssetsPath' => '/extensions',
- 'wgActionPaths' => array(),
'wgLocalFileRepo' => array(
- 'class' => 'LocalRepo',
- 'name' => 'local',
- 'url' => 'http://example.com/images',
- 'hashLevels' => 2,
+ 'class' => 'LocalRepo',
+ 'name' => 'local',
+ 'url' => 'http://example.com/images',
+ 'hashLevels' => 2,
'transformVia404' => false,
- 'backend' => $backend
+ 'backend' => $backend
),
'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ),
- 'wgStylePath' => '/skins',
- 'wgStyleSheetPath' => '/skins',
- 'wgSitename' => 'MediaWiki',
'wgLanguageCode' => $lang,
'wgDBprefix' => $this->db->getType() != 'oracle' ? 'unittest_' : 'ut_',
- 'wgRawHtml' => isset( $opts['rawhtml'] ),
- 'wgLang' => null,
- 'wgContLang' => null,
- 'wgNamespacesWithSubpages' => array( 0 => isset( $opts['subpage'] ) ),
+ 'wgRawHtml' => self::getOptionValue( 'wgRawHtml', $opts, false ),
+ 'wgNamespacesWithSubpages' => array( NS_MAIN => isset( $opts['subpage'] ) ),
+ 'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ),
'wgMaxTocLevel' => $maxtoclevel,
- 'wgCapitalLinks' => true,
- 'wgNoFollowLinks' => true,
- 'wgNoFollowDomainExceptions' => array(),
- 'wgThumbnailScriptPath' => false,
- 'wgUseImageResize' => false,
- 'wgUseTeX' => isset( $opts['math'] ),
+ 'wgUseTeX' => isset( $opts['math'] ) || isset( $opts['texvc'] ),
'wgMathDirectory' => $uploadDir . '/math',
- 'wgLocaltimezone' => 'UTC',
- 'wgAllowExternalImages' => true,
- 'wgUseTidy' => false,
'wgDefaultLanguageVariant' => $variant,
- 'wgVariantArticlePath' => false,
- 'wgGroupPermissions' => array( '*' => array(
- 'createaccount' => true,
- 'read' => true,
- 'edit' => true,
- 'createpage' => true,
- 'createtalk' => true,
- ) ),
- 'wgNamespaceProtection' => array( NS_MEDIAWIKI => 'editinterface' ),
- 'wgDefaultExternalStore' => array(),
- 'wgForeignFileRepos' => array(),
'wgLinkHolderBatchSize' => $linkHolderBatchSize,
- 'wgExperimentalHtmlIds' => false,
- 'wgExternalLinkTarget' => false,
- 'wgAlwaysUseTidy' => false,
- 'wgHtml5' => true,
- 'wgWellFormedXml' => true,
- 'wgAllowMicrodataAttributes' => true,
- 'wgAdaptiveMessageCache' => true,
- 'wgUseDatabaseMessages' => true,
);
if ( $config ) {
@@ -347,6 +361,15 @@ class NewParserTest extends MediaWikiTestCase {
/** @since 1.20 */
wfRunHooks( 'ParserTestGlobals', array( &$settings ) );
+ $langObj = Language::factory( $lang );
+ $settings['wgContLang'] = $langObj;
+ $settings['wgLang'] = $langObj;
+
+ $context = new RequestContext();
+ $settings['wgOut'] = $context->getOutput();
+ $settings['wgUser'] = $context->getUser();
+ $settings['wgRequest'] = $context->getRequest();
+
foreach ( $settings as $var => $val ) {
if ( array_key_exists( $var, $GLOBALS ) ) {
$this->savedGlobals[$var] = $GLOBALS[$var];
@@ -355,21 +378,9 @@ class NewParserTest extends MediaWikiTestCase {
$GLOBALS[$var] = $val;
}
- $langObj = Language::factory( $lang );
- $GLOBALS['wgContLang'] = $langObj;
- $context = new RequestContext();
- $GLOBALS['wgLang'] = $context->getLanguage();
-
- $GLOBALS['wgMemc'] = new EmptyBagOStuff;
- $GLOBALS['wgOut'] = $context->getOutput();
- $GLOBALS['wgUser'] = $context->getUser();
-
- global $wgHooks;
-
- $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
- $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
-
MagicWord::clearCache();
+
+ # The entries saved into RepoGroup cache with previous globals will be wrong.
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
@@ -379,9 +390,6 @@ class NewParserTest extends MediaWikiTestCase {
# Publish the articles after we have the final language set
$this->publishTestArticles();
- # The entries saved into RepoGroup cache with previous globals will be wrong.
- RepoGroup::destroySingleton();
- FileBackendGroup::destroySingleton();
MessageCache::destroyInstance();
return $context;
@@ -406,6 +414,7 @@ class NewParserTest extends MediaWikiTestCase {
// wfDebug( "Creating upload directory $dir\n" );
if ( file_exists( $dir ) ) {
wfDebug( "Already exists!\n" );
+
return $dir;
}
@@ -427,10 +436,27 @@ class NewParserTest extends MediaWikiTestCase {
$backend->store( array(
'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/3/3a/Foobar.jpg"
) );
+ $backend->prepare( array( 'dir' => "$base/local-public/e/ea" ) );
+ $backend->store( array(
+ 'src' => "$IP/skins/monobook/wiki.png", 'dst' => "$base/local-public/e/ea/Thumb.png"
+ ) );
$backend->prepare( array( 'dir' => "$base/local-public/0/09" ) );
$backend->store( array(
'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/0/09/Bad.jpg"
) );
+
+ // No helpful SVG file to copy, so make one ourselves
+ $tmpDir = wfTempDir();
+ $tempFsFile = new TempFSFile( "$tmpDir/Foobar.svg" );
+ $tempFsFile->autocollect(); // destroy file when $tempFsFile leaves scope
+ file_put_contents( "$tmpDir/Foobar.svg",
+ '<?xml version="1.0" encoding="utf-8"?>' .
+ '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><text>Foo</text></svg>' );
+
+ $backend->prepare( array( 'dir' => "$base/local-public/f/ff" ) );
+ $backend->quickStore( array(
+ 'src' => "$tmpDir/Foobar.svg", 'dst' => "$base/local-public/f/ff/Foobar.svg"
+ ) );
}
/**
@@ -443,9 +469,6 @@ class NewParserTest extends MediaWikiTestCase {
foreach ( $this->savedGlobals as $var => $val ) {
$GLOBALS[$var] = $val;
}
-
- RepoGroup::destroySingleton();
- LinkCache::singleton()->clear();
}
/**
@@ -456,18 +479,43 @@ class NewParserTest extends MediaWikiTestCase {
return;
}
+ $backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
+ if ( $backend instanceof MockFileBackend ) {
+ # In memory backend, so dont bother cleaning them up.
+ return;
+ }
+
$base = $this->getBaseDir();
// delete the files first, then the dirs.
self::deleteFiles(
- array (
+ array(
"$base/local-public/3/3a/Foobar.jpg",
"$base/local-thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
"$base/local-thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
"$base/local-thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
"$base/local-thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/1280px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/20px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/270px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/300px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/30px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/360px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/400px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/40px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/70px-Foobar.jpg",
+ "$base/local-thumb/3/3a/Foobar.jpg/960px-Foobar.jpg",
+
+ "$base/local-public/e/ea/Thumb.png",
"$base/local-public/0/09/Bad.jpg",
- "$base/local-thumb/0/09/Bad.jpg",
+
+ "$base/local-public/f/ff/Foobar.svg",
+ "$base/local-thumb/f/ff/Foobar.svg/180px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/270px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/360px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/langde-180px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/langde-270px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/langde-360px-Foobar.svg.jpg",
"$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
)
@@ -502,6 +550,7 @@ class NewParserTest extends MediaWikiTestCase {
global $wgParserTestFiles;
$this->file = $wgParserTestFiles[0];
}
+
return new TestFileIterator( $this->file, $this );
}
@@ -523,6 +572,14 @@ class NewParserTest extends MediaWikiTestCase {
return;
}
+ if ( !$this->isWikitextNS( NS_MAIN ) ) {
+ // parser tests frequently assume that the main namespace contains wikitext.
+ // @todo When setting up pages, force the content model. Only skip if
+ // $wgtContentModelUseDB is false.
+ $this->markTestSkipped( "Main namespace does not support wikitext,"
+ . "skipping parser test: $desc" );
+ }
+
wfDebug( "Running parser test: $desc\n" );
$opts = $this->parseOptions( $opts );
@@ -533,8 +590,7 @@ class NewParserTest extends MediaWikiTestCase {
if ( isset( $opts['title'] ) ) {
$titleText = $opts['title'];
- }
- else {
+ } else {
$titleText = 'Parser test';
}
@@ -544,6 +600,20 @@ class NewParserTest extends MediaWikiTestCase {
$title = Title::newFromText( $titleText );
+ # Parser test requiring math. Make sure texvc is executable
+ # or just skip such tests.
+ if ( isset( $opts['math'] ) || isset( $opts['texvc'] ) ) {
+ global $wgTexvc;
+
+ if ( !isset( $wgTexvc ) ) {
+ $this->markTestSkipped( "SKIPPED: \$wgTexvc is not set" );
+ } elseif ( !is_executable( $wgTexvc ) ) {
+ $this->markTestSkipped( "SKIPPED: texvc binary does not exist"
+ . " or is not executable.\n"
+ . "Current configuration is:\n\$wgTexvc = '$wgTexvc'" );
+ }
+ }
+
if ( isset( $opts['pst'] ) ) {
$out = $parser->preSaveTransform( $input, $title, $user, $options );
} elseif ( isset( $opts['msg'] ) ) {
@@ -558,9 +628,10 @@ class NewParserTest extends MediaWikiTestCase {
} elseif ( isset( $opts['comment'] ) ) {
$out = Linker::formatComment( $input, $title, $local );
} elseif ( isset( $opts['preload'] ) ) {
- $out = $parser->getpreloadText( $input, $title, $options );
+ $out = $parser->getPreloadText( $input, $title, $options );
} else {
$output = $parser->parse( $input, $title, $options, true, true, 1337 );
+ $output->setTOCEnabled( !isset( $opts['notoc'] ) );
$out = $output->getText();
if ( isset( $opts['showtitle'] ) ) {
@@ -602,12 +673,12 @@ class NewParserTest extends MediaWikiTestCase {
*
* @group ParserFuzz
*/
- function testFuzzTests() {
+ public function testFuzzTests() {
global $wgParserTestFiles;
$files = $wgParserTestFiles;
- if( $this->getCliArg( 'file=' ) ) {
+ if ( $this->getCliArg( 'file=' ) ) {
$files = array( $this->getCliArg( 'file=' ) );
}
@@ -647,7 +718,9 @@ class NewParserTest extends MediaWikiTestCase {
} catch ( Exception $exception ) {
$input_dump = sprintf( "string(%d) \"%s\"\n", strlen( $input ), $input );
- $this->assertTrue( false, "Test $id, fuzz seed {$this->fuzzSeed}. \n\nInput: $input_dump\n\nError: {$exception->getMessage()}\n\nBacktrace: {$exception->getTraceAsString()}" );
+ $this->assertTrue( false, "Test $id, fuzz seed {$this->fuzzSeed}. \n\n" .
+ "Input: $input_dump\n\nError: {$exception->getMessage()}\n\n" .
+ "Backtrace: {$exception->getTraceAsString()}" );
}
$this->teardownGlobals();
@@ -669,7 +742,6 @@ class NewParserTest extends MediaWikiTestCase {
}
$id++;
-
}
}
@@ -769,15 +841,16 @@ class NewParserTest extends MediaWikiTestCase {
*/
public function requireHook( $name ) {
global $wgParser;
- $wgParser->firstCallInit( ); // make sure hooks are loaded.
+ $wgParser->firstCallInit(); // make sure hooks are loaded.
return isset( $wgParser->mTagHooks[$name] );
}
public function requireFunctionHook( $name ) {
global $wgParser;
- $wgParser->firstCallInit( ); // make sure hooks are loaded.
+ $wgParser->firstCallInit(); // make sure hooks are loaded.
return isset( $wgParser->mFunctionHooks[$name] );
}
+
//Various "cleanup" functions
/**
@@ -803,8 +876,7 @@ class NewParserTest extends MediaWikiTestCase {
public function removeEndingNewline( $s ) {
if ( substr( $s, -1 ) === "\n" ) {
return substr( $s, 0, -1 );
- }
- else {
+ } else {
return $s;
}
}
@@ -863,6 +935,7 @@ class NewParserTest extends MediaWikiTestCase {
}
}
}
+
return $opts;
}
@@ -874,6 +947,7 @@ class NewParserTest extends MediaWikiTestCase {
if ( substr( $opt, 0, 2 ) == '[[' ) {
return substr( $opt, 2, -2 );
}
+
return $opt;
}
diff --git a/tests/phpunit/includes/parser/ParserMethodsTest.php b/tests/phpunit/includes/parser/ParserMethodsTest.php
index dea406c3..e5c5cb21 100644
--- a/tests/phpunit/includes/parser/ParserMethodsTest.php
+++ b/tests/phpunit/includes/parser/ParserMethodsTest.php
@@ -2,19 +2,20 @@
class ParserMethodsTest extends MediaWikiLangTestCase {
- public function dataPreSaveTransform() {
+ public static function providePreSaveTransform() {
return array(
array( 'hello this is ~~~',
- "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
+ "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
),
array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
- 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
),
);
}
/**
- * @dataProvider dataPreSaveTransform
+ * @dataProvider providePreSaveTransform
+ * @covers Parser::preSaveTransform
*/
public function testPreSaveTransform( $text, $expected ) {
global $wgParser;
@@ -28,6 +29,67 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
$this->assertEquals( $expected, $text );
}
- // TODO: Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
-}
+ /**
+ * @covers Parser::callParserFunction
+ */
+ public function testCallParserFunction() {
+ global $wgParser;
+
+ // Normal parses test passing PPNodes. Test passing an array.
+ $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
+ $wgParser->startExternalParse( $title, new ParserOptions(), Parser::OT_HTML );
+ $frame = $wgParser->getPreprocessor()->newFrame();
+ $ret = $wgParser->callParserFunction( $frame, '#tag',
+ array( 'pre', 'foo', 'style' => 'margin-left: 1.6em' )
+ );
+ $ret['text'] = $wgParser->mStripState->unstripBoth( $ret['text'] );
+ $this->assertSame( array(
+ 'found' => true,
+ 'text' => '<pre style="margin-left: 1.6em">foo</pre>',
+ ), $ret, 'callParserFunction works for {{#tag:pre|foo|style=margin-left: 1.6em}}' );
+ }
+
+ /**
+ * @covers Parser::parse
+ * @covers ParserOutput::getSections
+ */
+ public function testGetSections() {
+ global $wgParser;
+ $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
+ $out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() );
+ $this->assertSame( array(
+ array(
+ 'toclevel' => 1,
+ 'level' => '2',
+ 'line' => 'foo',
+ 'number' => '1',
+ 'index' => '1',
+ 'fromtitle' => $title->getPrefixedDBkey(),
+ 'byteoffset' => 0,
+ 'anchor' => 'foo',
+ ),
+ array(
+ 'toclevel' => 1,
+ 'level' => '2',
+ 'line' => 'bar',
+ 'number' => '2',
+ 'index' => '',
+ 'fromtitle' => false,
+ 'byteoffset' => null,
+ 'anchor' => 'bar',
+ ),
+ array(
+ 'toclevel' => 1,
+ 'level' => '2',
+ 'line' => 'baz',
+ 'number' => '3',
+ 'index' => '2',
+ 'fromtitle' => $title->getPrefixedDBkey(),
+ 'byteoffset' => 21,
+ 'anchor' => 'baz',
+ ),
+ ), $out->getSections(), 'getSections() with proper value when <h2> is used' );
+ }
+ //@Todo Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
+}
diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php
new file mode 100644
index 00000000..c73666da
--- /dev/null
+++ b/tests/phpunit/includes/parser/ParserOutputTest.php
@@ -0,0 +1,59 @@
+<?php
+
+class ParserOutputTest extends MediaWikiTestCase {
+
+ public static function provideIsLinkInternal() {
+ return array(
+ // Different domains
+ array( false, 'http://example.org', 'http://mediawiki.org' ),
+ // Same domains
+ array( true, 'http://example.org', 'http://example.org' ),
+ array( true, 'https://example.org', 'https://example.org' ),
+ array( true, '//example.org', '//example.org' ),
+ // Same domain different cases
+ array( true, 'http://example.org', 'http://EXAMPLE.ORG' ),
+ // Paths, queries, and fragments are not relevant
+ array( true, 'http://example.org', 'http://example.org/wiki/Main_Page' ),
+ array( true, 'http://example.org', 'http://example.org?my=query' ),
+ array( true, 'http://example.org', 'http://example.org#its-a-fragment' ),
+ // Different protocols
+ array( false, 'http://example.org', 'https://example.org' ),
+ array( false, 'https://example.org', 'http://example.org' ),
+ // Protocol relative servers always match http and https links
+ array( true, '//example.org', 'http://example.org' ),
+ array( true, '//example.org', 'https://example.org' ),
+ // But they don't match strange things like this
+ array( false, '//example.org', 'irc://example.org' ),
+ );
+ }
+
+ /**
+ * Test to make sure ParserOutput::isLinkInternal behaves properly
+ * @dataProvider provideIsLinkInternal
+ * @covers ParserOutput::isLinkInternal
+ */
+ public function testIsLinkInternal( $shouldMatch, $server, $url ) {
+ $this->assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
+ }
+
+ /**
+ * @covers ParserOutput::setExtensionData
+ * @covers ParserOutput::getExtensionData
+ */
+ public function testExtensionData() {
+ $po = new ParserOutput();
+
+ $po->setExtensionData( "one", "Foo" );
+
+ $this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
+ $this->assertNull( $po->getExtensionData( "spam" ) );
+
+ $po->setExtensionData( "two", "Bar" );
+ $this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
+ $this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
+
+ $po->setExtensionData( "one", null );
+ $this->assertNull( $po->getExtensionData( "one" ) );
+ $this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
+ }
+}
diff --git a/tests/phpunit/includes/parser/ParserPreloadTest.php b/tests/phpunit/includes/parser/ParserPreloadTest.php
index 0e8ef530..d12fee36 100644
--- a/tests/phpunit/includes/parser/ParserPreloadTest.php
+++ b/tests/phpunit/includes/parser/ParserPreloadTest.php
@@ -4,12 +4,24 @@
* @author Antoine Musso
*/
class ParserPreloadTest extends MediaWikiTestCase {
+ /**
+ * @var Parser
+ */
private $testParser;
+ /**
+ * @var ParserOptions
+ */
private $testParserOptions;
+ /**
+ * @var Title
+ */
private $title;
- function setUp() {
- $this->testParserOptions = new ParserOptions();
+ protected function setUp() {
+ global $wgContLang;
+
+ parent::setUp();
+ $this->testParserOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
$this->testParser = new Parser();
$this->testParser->Options( $this->testParserOptions );
@@ -18,7 +30,9 @@ class ParserPreloadTest extends MediaWikiTestCase {
$this->title = Title::newFromText( 'Preload Test' );
}
- function tearDown() {
+ protected function tearDown() {
+ parent::tearDown();
+
unset( $this->testParser );
unset( $this->title );
}
@@ -26,14 +40,14 @@ class ParserPreloadTest extends MediaWikiTestCase {
/**
* @covers Parser::getPreloadText
*/
- function testPreloadSimpleText() {
+ public function testPreloadSimpleText() {
$this->assertPreloaded( 'simple', 'simple' );
}
/**
* @covers Parser::getPreloadText
*/
- function testPreloadedPreIsUnstripped() {
+ public function testPreloadedPreIsUnstripped() {
$this->assertPreloaded(
'<pre>monospaced</pre>',
'<pre>monospaced</pre>',
@@ -44,7 +58,7 @@ class ParserPreloadTest extends MediaWikiTestCase {
/**
* @covers Parser::getPreloadText
*/
- function testPreloadedNowikiIsUnstripped() {
+ public function testPreloadedNowikiIsUnstripped() {
$this->assertPreloaded(
'<nowiki>[[Dummy title]]</nowiki>',
'<nowiki>[[Dummy title]]</nowiki>',
@@ -52,7 +66,7 @@ class ParserPreloadTest extends MediaWikiTestCase {
);
}
- function assertPreloaded( $expected, $text, $msg='') {
+ protected function assertPreloaded( $expected, $text, $msg = '' ) {
$this->assertEquals(
$expected,
$this->testParser->getPreloadText(
@@ -63,5 +77,4 @@ class ParserPreloadTest extends MediaWikiTestCase {
$msg
);
}
-
}
diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php
index fee56748..8aee937c 100644
--- a/tests/phpunit/includes/parser/PreprocessorTest.php
+++ b/tests/phpunit/includes/parser/PreprocessorTest.php
@@ -1,13 +1,21 @@
<?php
class PreprocessorTest extends MediaWikiTestCase {
- var $mTitle = 'Page title';
- var $mPPNodeCount = 0;
- var $mOptions;
+ protected $mTitle = 'Page title';
+ protected $mPPNodeCount = 0;
+ /**
+ * @var ParserOptions
+ */
+ protected $mOptions;
+ /**
+ * @var Preprocessor
+ */
+ protected $mPreprocessor;
- function setUp() {
- global $wgParserConf;
- $this->mOptions = new ParserOptions();
+ protected function setUp() {
+ global $wgParserConf, $wgContLang;
+ parent::setUp();
+ $this->mOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
$name = isset( $wgParserConf['preprocessorClass'] ) ? $wgParserConf['preprocessorClass'] : 'Preprocessor_DOM';
$this->mPreprocessor = new $name( $this );
@@ -17,7 +25,7 @@ class PreprocessorTest extends MediaWikiTestCase {
return array( 'gallery', 'display map' /* Used by Maps, see r80025 CR */, '/foo' );
}
- function provideCases() {
+ public static function provideCases() {
return array(
array( "Foo", "<root>Foo</root>" ),
array( "<!-- Foo -->", "<root><comment>&lt;!-- Foo --&gt;</comment></root>" ),
@@ -51,16 +59,16 @@ class PreprocessorTest extends MediaWikiTestCase {
array( "Foo\n=\n==\n=\n", "<root>Foo\n=\n==\n=\n</root>" ),
array( "{{Foo}}", "<root><template><title>Foo</title></template></root>" ),
array( "\n{{Foo}}", "<root>\n<template lineStart=\"1\"><title>Foo</title></template></root>" ),
- array( "{{Foo|bar}}", "<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part></template></root>" ),
- array( "{{Foo|bar}}a", "<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part></template>a</root>" ),
- array( "{{Foo|bar|baz}}", "<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part><part><name index=\"2\" /><value>baz</value></part></template></root>" ),
+ array( "{{Foo|bar}}", "<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part></template></root>" ),
+ array( "{{Foo|bar}}a", "<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part></template>a</root>" ),
+ array( "{{Foo|bar|baz}}", "<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part><part><name index=\"2\" /><value>baz</value></part></template></root>" ),
array( "{{Foo|1=bar}}", "<root><template><title>Foo</title><part><name>1</name>=<value>bar</value></part></template></root>" ),
array( "{{Foo|=bar}}", "<root><template><title>Foo</title><part><name></name>=<value>bar</value></part></template></root>" ),
- array( "{{Foo|bar=baz}}", "<root><template><title>Foo</title><part><name>bar</name>=<value>baz</value></part></template></root>" ),
+ array( "{{Foo|bar=baz}}", "<root><template><title>Foo</title><part><name>bar</name>=<value>baz</value></part></template></root>" ),
array( "{{Foo|{{bar}}=baz}}", "<root><template><title>Foo</title><part><name><template><title>bar</title></template></name>=<value>baz</value></part></template></root>" ),
- array( "{{Foo|1=bar|baz}}", "<root><template><title>Foo</title><part><name>1</name>=<value>bar</value></part><part><name index=\"1\" /><value>baz</value></part></template></root>" ),
+ array( "{{Foo|1=bar|baz}}", "<root><template><title>Foo</title><part><name>1</name>=<value>bar</value></part><part><name index=\"1\" /><value>baz</value></part></template></root>" ),
array( "{{Foo|1=bar|2=baz}}", "<root><template><title>Foo</title><part><name>1</name>=<value>bar</value></part><part><name>2</name>=<value>baz</value></part></template></root>" ),
- array( "{{Foo|bar|foo=baz}}", "<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part><part><name>foo</name>=<value>baz</value></part></template></root>" ),
+ array( "{{Foo|bar|foo=baz}}", "<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part><part><name>foo</name>=<value>baz</value></part></template></root>" ),
array( "{{{1}}}", "<root><tplarg><title>1</title></tplarg></root>" ),
array( "{{{1|}}}", "<root><tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg></root>" ),
array( "{{{Foo}}}", "<root><tplarg><title>Foo</title></tplarg></root>" ),
@@ -83,26 +91,26 @@ class PreprocessorTest extends MediaWikiTestCase {
array( "Foo <gallery bar=\"baz\" />", "<root>Foo <ext><name>gallery</name><attr> bar=&quot;baz&quot; </attr></ext></root>" ),
array( "Foo <gallery bar=\"1\" baz=2 />", "<root>Foo <ext><name>gallery</name><attr> bar=&quot;1&quot; baz=2 </attr></ext></root>" ),
array( "</foo>Foo<//foo>", "<root><ext><name>/foo</name><attr></attr><inner>Foo</inner><close>&lt;//foo&gt;</close></ext></root>" ), # Worth blacklisting IMHO
- array( "{{#ifexpr: ({{{1|1}}} = 2) | Foo | Bar }}", "<root><template><title>#ifexpr: (<tplarg><title>1</title><part><name index=\"1\" /><value>1</value></part></tplarg> = 2) </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> Bar </value></part></template></root>"),
- array( "{{#if: {{{1|}}} | Foo | {{Bar}} }}", "<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> <template><title>Bar</title></template> </value></part></template></root>"),
- array( "{{#if: {{{1|}}} | Foo | [[Bar]] }}", "<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> [[Bar]] </value></part></template></root>"),
- array( "{{#if: {{{1|}}} | [[Foo]] | Bar }}", "<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> [[Foo]] </value></part><part><name index=\"2\" /><value> Bar </value></part></template></root>"),
- array( "{{#if: {{{1|}}} | 1 | {{#if: {{{1|}}} | 2 | 3 }} }}", "<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> 1 </value></part><part><name index=\"2\" /><value> <template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> 2 </value></part><part><name index=\"2\" /><value> 3 </value></part></template> </value></part></template></root>"),
- array( "{{ {{Foo}}", "<root>{{ <template><title>Foo</title></template></root>"),
- array( "{{Foobar {{Foo}} {{Bar}} {{Baz}} ", "<root>{{Foobar <template><title>Foo</title></template> <template><title>Bar</title></template> <template><title>Baz</title></template> </root>"),
- array( "[[Foo]] |", "<root>[[Foo]] |</root>"),
- array( "{{Foo|Bar|", "<root>{{Foo|Bar|</root>"),
- array( "[[Foo]", "<root>[[Foo]</root>"),
- array( "[[Foo|Bar]", "<root>[[Foo|Bar]</root>"),
- array( "{{Foo| [[Bar] }}", "<root>{{Foo| [[Bar] }}</root>"),
- array( "{{Foo| [[Bar|Baz] }}", "<root>{{Foo| [[Bar|Baz] }}</root>"),
- array( "{{Foo|bar=[[baz]}}", "<root>{{Foo|bar=[[baz]}}</root>"),
- array( "{{foo|", "<root>{{foo|</root>"),
- array( "{{foo|}", "<root>{{foo|}</root>"),
- array( "{{foo|} }}", "<root><template><title>foo</title><part><name index=\"1\" /><value>} </value></part></template></root>"),
- array( "{{foo|bar=|}", "<root>{{foo|bar=|}</root>"),
- array( "{{Foo|} Bar=", "<root>{{Foo|} Bar=</root>"),
- array( "{{Foo|} Bar=}}", "<root><template><title>Foo</title><part><name>} Bar</name>=<value></value></part></template></root>"),
+ array( "{{#ifexpr: ({{{1|1}}} = 2) | Foo | Bar }}", "<root><template><title>#ifexpr: (<tplarg><title>1</title><part><name index=\"1\" /><value>1</value></part></tplarg> = 2) </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> Bar </value></part></template></root>" ),
+ array( "{{#if: {{{1|}}} | Foo | {{Bar}} }}", "<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> <template><title>Bar</title></template> </value></part></template></root>" ),
+ array( "{{#if: {{{1|}}} | Foo | [[Bar]] }}", "<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> [[Bar]] </value></part></template></root>" ),
+ array( "{{#if: {{{1|}}} | [[Foo]] | Bar }}", "<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> [[Foo]] </value></part><part><name index=\"2\" /><value> Bar </value></part></template></root>" ),
+ array( "{{#if: {{{1|}}} | 1 | {{#if: {{{1|}}} | 2 | 3 }} }}", "<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> 1 </value></part><part><name index=\"2\" /><value> <template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> 2 </value></part><part><name index=\"2\" /><value> 3 </value></part></template> </value></part></template></root>" ),
+ array( "{{ {{Foo}}", "<root>{{ <template><title>Foo</title></template></root>" ),
+ array( "{{Foobar {{Foo}} {{Bar}} {{Baz}} ", "<root>{{Foobar <template><title>Foo</title></template> <template><title>Bar</title></template> <template><title>Baz</title></template> </root>" ),
+ array( "[[Foo]] |", "<root>[[Foo]] |</root>" ),
+ array( "{{Foo|Bar|", "<root>{{Foo|Bar|</root>" ),
+ array( "[[Foo]", "<root>[[Foo]</root>" ),
+ array( "[[Foo|Bar]", "<root>[[Foo|Bar]</root>" ),
+ array( "{{Foo| [[Bar] }}", "<root>{{Foo| [[Bar] }}</root>" ),
+ array( "{{Foo| [[Bar|Baz] }}", "<root>{{Foo| [[Bar|Baz] }}</root>" ),
+ array( "{{Foo|bar=[[baz]}}", "<root>{{Foo|bar=[[baz]}}</root>" ),
+ array( "{{foo|", "<root>{{foo|</root>" ),
+ array( "{{foo|}", "<root>{{foo|}</root>" ),
+ array( "{{foo|} }}", "<root><template><title>foo</title><part><name index=\"1\" /><value>} </value></part></template></root>" ),
+ array( "{{foo|bar=|}", "<root>{{foo|bar=|}</root>" ),
+ array( "{{Foo|} Bar=", "<root>{{Foo|} Bar=</root>" ),
+ array( "{{Foo|} Bar=}}", "<root><template><title>Foo</title><part><name>} Bar</name>=<value></value></part></template></root>" ),
/* array( file_get_contents( __DIR__ . '/QuoteQuran.txt' ), file_get_contents( __DIR__ . '/QuoteQuranExpanded.txt' ) ), */
);
}
@@ -114,11 +122,11 @@ class PreprocessorTest extends MediaWikiTestCase {
* @param string $wikiText
* @return string
*/
- function preprocessToXml( $wikiText ) {
+ protected function preprocessToXml( $wikiText ) {
if ( method_exists( $this->mPreprocessor, 'preprocessToXml' ) ) {
return $this->normalizeXml( $this->mPreprocessor->preprocessToXml( $wikiText ) );
}
-
+
$dom = $this->mPreprocessor->preprocessToObj( $wikiText );
if ( is_callable( array( $dom, 'saveXML' ) ) ) {
return $dom->saveXML();
@@ -133,38 +141,36 @@ class PreprocessorTest extends MediaWikiTestCase {
* @param string $xml
* @return string
*/
- function normalizeXml( $xml ) {
+ protected function normalizeXml( $xml ) {
return preg_replace( '!<([a-z]+)/>!', '<$1></$1>', str_replace( ' />', '/>', $xml ) );
-
- $dom = new DOMDocument();
- // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 don't barf when the XML is >256 levels deep
- $dom->loadXML( $xml, 1 << 19 );
- return $dom->saveXML();
}
/**
* @dataProvider provideCases
+ * @covers Preprocessor_DOM::preprocessToXml
*/
- function testPreprocessorOutput( $wikiText, $expectedXml ) {
+ public function testPreprocessorOutput( $wikiText, $expectedXml ) {
$this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) );
}
/**
* These are more complex test cases taken out of wiki articles.
*/
- function provideFiles() {
+ public static function provideFiles() {
return array(
array( "QuoteQuran" ), # http://en.wikipedia.org/w/index.php?title=Template:QuoteQuran/sandbox&oldid=237348988 GFDL + CC-BY-SA by Striver
array( "Factorial" ), # http://en.wikipedia.org/w/index.php?title=Template:Factorial&oldid=98548758 GFDL + CC-BY-SA by Polonium
array( "All_system_messages" ), # http://tl.wiktionary.org/w/index.php?title=Suleras:All_system_messages&oldid=2765 GPL text generated by MediaWiki
array( "Fundraising" ), # http://tl.wiktionary.org/w/index.php?title=MediaWiki:Sitenotice&oldid=5716 GFDL + CC-BY-SA, copied there by Sky Harbor.
+ array( "NestedTemplates" ), # bug 27936
);
}
/**
* @dataProvider provideFiles
+ * @covers Preprocessor_DOM::preprocessToXml
*/
- function testPreprocessorOutputFiles( $filename ) {
+ public function testPreprocessorOutputFiles( $filename ) {
$folder = __DIR__ . "/../../../parser/preprocess";
$wikiText = file_get_contents( "$folder/$filename.txt" );
$output = $this->preprocessToXml( $wikiText );
@@ -183,8 +189,8 @@ class PreprocessorTest extends MediaWikiTestCase {
/**
* Tests from Bug 28642 · https://bugzilla.wikimedia.org/28642
*/
- function provideHeadings() {
- return array( /* These should become headings: */
+ public static function provideHeadings() {
+ return array( /* These should become headings: */
array( "== h ==<!--c1-->", "<root><h level=\"2\" i=\"1\">== h ==<comment>&lt;!--c1--&gt;</comment></h></root>" ),
array( "== h == <!--c1-->", "<root><h level=\"2\" i=\"1\">== h == <comment>&lt;!--c1--&gt;</comment></h></root>" ),
array( "== h ==<!--c1--> ", "<root><h level=\"2\" i=\"1\">== h ==<comment>&lt;!--c1--&gt;</comment> </h></root>" ),
@@ -212,11 +218,11 @@ class PreprocessorTest extends MediaWikiTestCase {
array( "== h == <!--c1--> <!--c2--><!--c3--> ", "<root><h level=\"2\" i=\"1\">== h == <comment>&lt;!--c1--&gt;</comment> <comment>&lt;!--c2--&gt;</comment><comment>&lt;!--c3--&gt;</comment> </h></root>" ),
array( "== h == <!--c1--><!--c2--> <!--c3--> ", "<root><h level=\"2\" i=\"1\">== h == <comment>&lt;!--c1--&gt;</comment><comment>&lt;!--c2--&gt;</comment> <comment>&lt;!--c3--&gt;</comment> </h></root>" ),
array( "== h == <!--c1--> <!--c2--> <!--c3--> ", "<root><h level=\"2\" i=\"1\">== h == <comment>&lt;!--c1--&gt;</comment> <comment>&lt;!--c2--&gt;</comment> <comment>&lt;!--c3--&gt;</comment> </h></root>" ),
+ array( "== h ==<!--c1--> <!--c2-->", "<root><h level=\"2\" i=\"1\">== h ==<comment>&lt;!--c1--&gt;</comment> <comment>&lt;!--c2--&gt;</comment></h></root>" ),
+ array( "== h == <!--c1--> <!--c2-->", "<root><h level=\"2\" i=\"1\">== h == <comment>&lt;!--c1--&gt;</comment> <comment>&lt;!--c2--&gt;</comment></h></root>" ),
+ array( "== h ==<!--c1--> <!--c2--> ", "<root><h level=\"2\" i=\"1\">== h ==<comment>&lt;!--c1--&gt;</comment> <comment>&lt;!--c2--&gt;</comment> </h></root>" ),
/* These are not working: */
- array( "== h ==<!--c1--> <!--c2-->", "<root>== h ==<comment>&lt;!--c1--&gt;</comment> <comment>&lt;!--c2--&gt;</comment></root>" ),
- array( "== h == <!--c1--> <!--c2-->", "<root>== h == <comment>&lt;!--c1--&gt;</comment> <comment>&lt;!--c2--&gt;</comment></root>" ),
- array( "== h ==<!--c1--> <!--c2--> ", "<root>== h ==<comment>&lt;!--c1--&gt;</comment> <comment>&lt;!--c2--&gt;</comment> </root>" ),
array( "== h == x <!--c1--><!--c2--><!--c3--> ", "<root>== h == x <comment>&lt;!--c1--&gt;</comment><comment>&lt;!--c2--&gt;</comment><comment>&lt;!--c3--&gt;</comment> </root>" ),
array( "== h ==<!--c1--> x <!--c2--><!--c3--> ", "<root>== h ==<comment>&lt;!--c1--&gt;</comment> x <comment>&lt;!--c2--&gt;</comment><comment>&lt;!--c3--&gt;</comment> </root>" ),
array( "== h ==<!--c1--><!--c2--><!--c3--> x ", "<root>== h ==<comment>&lt;!--c1--&gt;</comment><comment>&lt;!--c2--&gt;</comment><comment>&lt;!--c3--&gt;</comment> x </root>" ),
@@ -225,9 +231,9 @@ class PreprocessorTest extends MediaWikiTestCase {
/**
* @dataProvider provideHeadings
+ * @covers Preprocessor_DOM::preprocessToXml
*/
- function testHeadings( $wikiText, $expectedXml ) {
+ public function testHeadings( $wikiText, $expectedXml ) {
$this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) );
}
}
-
diff --git a/tests/phpunit/includes/parser/TagHooksTest.php b/tests/phpunit/includes/parser/TagHooksTest.php
index 713ce846..61cbe45d 100644
--- a/tests/phpunit/includes/parser/TagHooksTest.php
+++ b/tests/phpunit/includes/parser/TagHooksTest.php
@@ -4,73 +4,78 @@
* @group Parser
*/
class TagHookTest extends MediaWikiTestCase {
-
public static function provideValidNames() {
return array( array( 'foo' ), array( 'foo-bar' ), array( 'foo_bar' ), array( 'FOO-BAR' ), array( 'foo bar' ) );
}
public static function provideBadNames() {
- return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ), array( "foo\rbar" ) );
+ return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ), array( "foo\rbar" ) );
}
-
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( 'wgAlwaysUseTidy', false );
+ }
+
/**
* @dataProvider provideValidNames
*/
- function testTagHooks( $tag ) {
- global $wgParserConf;
+ public function testTagHooks( $tag ) {
+ global $wgParserConf, $wgContLang;
$parser = new Parser( $wgParserConf );
-
+
$parser->setHook( $tag, array( $this, 'tagCallback' ) );
- $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
+ $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) );
$this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
-
+
$parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
}
-
+
/**
* @dataProvider provideBadNames
* @expectedException MWException
*/
- function testBadTagHooks( $tag ) {
- global $wgParserConf;
+ public function testBadTagHooks( $tag ) {
+ global $wgParserConf, $wgContLang;
$parser = new Parser( $wgParserConf );
-
+
$parser->setHook( $tag, array( $this, 'tagCallback' ) );
- $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
- $this->fail('Exception not thrown.');
+ $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) );
+ $this->fail( 'Exception not thrown.' );
}
-
+
/**
* @dataProvider provideValidNames
*/
- function testFunctionTagHooks( $tag ) {
- global $wgParserConf;
+ public function testFunctionTagHooks( $tag ) {
+ global $wgParserConf, $wgContLang;
$parser = new Parser( $wgParserConf );
-
+
$parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 );
- $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
+ $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) );
$this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
-
+
$parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
}
-
+
/**
* @dataProvider provideBadNames
* @expectedException MWException
*/
- function testBadFunctionTagHooks( $tag ) {
- global $wgParserConf;
+ public function testBadFunctionTagHooks( $tag ) {
+ global $wgParserConf, $wgContLang;
$parser = new Parser( $wgParserConf );
-
+
$parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), SFH_OBJECT_ARGS );
- $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
- $this->fail('Exception not thrown.');
+ $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) );
+ $this->fail( 'Exception not thrown.' );
}
-
+
function tagCallback( $text, $params, $parser ) {
return str_rot13( $text );
}
-
+
function functionTagCallback( &$parser, $frame, $code, $attribs ) {
return str_rot13( $code );
}
diff --git a/tests/phpunit/includes/parser/TidyTest.php b/tests/phpunit/includes/parser/TidyTest.php
new file mode 100644
index 00000000..57a88b9d
--- /dev/null
+++ b/tests/phpunit/includes/parser/TidyTest.php
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * @group Parser
+ */
+class TidyTest extends MediaWikiTestCase {
+ public function setUp() {
+ parent::setUp();
+ $check = MWTidy::tidy( '' );
+ if ( strpos( $check, '<!--' ) !== false ) {
+ $this->markTestSkipped( 'Tidy not found' );
+ }
+ }
+
+ /**
+ * @dataProvider provideTestWrapping
+ */
+ public function testTidyWrapping( $expected, $text, $msg = '' ) {
+ $text = MWTidy::tidy( $text );
+ // We don't care about where Tidy wants to stick is <p>s
+ $text = trim( preg_replace( '#</?p>#', '', $text ) );
+ // Windows, we love you!
+ $text = str_replace( "\r", '', $text );
+ $this->assertEquals( $expected, $text, $msg );
+ }
+
+ public function provideTestWrapping() {
+ return array(
+ array(
+ '<mw:editsection page="foo" section="bar">foo</mw:editsection>',
+ '<mw:editsection page="foo" section="bar">foo</mw:editsection>',
+ '<mw:editsection> should survive tidy'
+ ),
+ array(
+ '<editsection page="foo" section="bar">foo</editsection>',
+ '<editsection page="foo" section="bar">foo</editsection>',
+ '<editsection> should survive tidy'
+ ),
+ array( '<mw:toc>foo</mw:toc>', '<mw:toc>foo</mw:toc>', '<mw:toc> should survive tidy' ),
+ array( "<link foo=\"bar\" />\nfoo", '<link foo="bar"/>foo', '<link> should survive tidy' ),
+ array( "<meta foo=\"bar\" />\nfoo", '<meta foo="bar"/>foo', '<meta> should survive tidy' ),
+ );
+ }
+} \ No newline at end of file