From 640d6ebb34122af7198c525d2c3e64be5125b9b0 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 6 Jul 2017 18:02:47 -0700 Subject: [PATCH] parser: Add parser tests for 4 and 5 tildes in PST Add logic in ParserTestRunner that sets the same fake timestamp used by the Parser magic word expansion, also in ParserOptions, which is used by preSaveTransform(). Change-Id: I5adacffccb1212651c3031ca2fc4c20f717ff24a --- tests/parser/ParserTestRunner.php | 17 ++++++++++++----- tests/parser/parserTests.txt | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index a373142d7e..77717f0161 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -266,7 +266,10 @@ class ParserTestRunner { $setup['wgSVGConverters'] = [ 'null' => 'echo "1">$output' ]; // Fake constant timestamp - Hooks::register( 'ParserGetVariableValueTs', 'ParserTestRunner::getFakeTimestamp' ); + Hooks::register( 'ParserGetVariableValueTs', function ( &$parser, &$ts ) { + $ts = $this->getFakeTimestamp(); + return true; + } ); $teardown[] = function () { Hooks::clear( 'ParserGetVariableValueTs' ); }; @@ -747,6 +750,7 @@ class ParserTestRunner { $context = RequestContext::getMain(); $user = $context->getUser(); $options = ParserOptions::newFromContext( $context ); + $options->setTimestamp( $this->getFakeTimestamp() ); if ( !isset( $opts['wrap'] ) ) { $options->setWrapOutputClass( false ); @@ -1598,11 +1602,14 @@ class ParserTestRunner { } /** - * The ParserGetVariableValueTs hook, used to make sure time-related parser + * Fake constant timestamp to make sure time-related parser * functions give a persistent value. + * + * - Parser::getVariableValue (via ParserGetVariableValueTs hook) + * - Parser::preSaveTransform (via ParserOptions) */ - static function getFakeTimestamp( &$parser, &$ts ) { - $ts = 123; // parsed as '1970-01-01T00:02:03Z' - return true; + private function getFakeTimestamp() { + // parsed as '1970-01-01T00:02:03Z' + return 123; } } diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 44bcdffeb4..4c48ed53d6 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -13619,11 +13619,15 @@ pre-save transform: Signature expansion pst !! wikitext * ~~~ +* ~~~~ +* ~~~~~ * ~~~ * ~~~ * ~~~ !! html/php * [[Special:Contributions/127.0.0.1|127.0.0.1]] +* [[Special:Contributions/127.0.0.1|127.0.0.1]] 00:02, 1 January 1970 (UTC) +* 00:02, 1 January 1970 (UTC) * [[Special:Contributions/127.0.0.1|127.0.0.1]] * [[Special:Contributions/127.0.0.1|127.0.0.1]] * [[Special:Contributions/127.0.0.1|127.0.0.1]] -- 2.20.1