parser: Add parser tests for 4 and 5 tildes in PST
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 7 Jul 2017 01:02:47 +0000 (18:02 -0700)
committerKrinkle <krinklemail@gmail.com>
Fri, 7 Jul 2017 01:05:08 +0000 (01:05 +0000)
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
tests/parser/parserTests.txt

index a373142..77717f0 100644 (file)
@@ -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;
        }
 }
index 44bcdff..4c48ed5 100644 (file)
@@ -13619,11 +13619,15 @@ pre-save transform: Signature expansion
 pst
 !! wikitext
 * ~~~
+* ~~~~
+* ~~~~~
 * <noinclude>~~~</noinclude>
 * <includeonly>~~~</includeonly>
 * <onlyinclude>~~~</onlyinclude>
 !! 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)
 * <noinclude>[[Special:Contributions/127.0.0.1|127.0.0.1]]</noinclude>
 * <includeonly>[[Special:Contributions/127.0.0.1|127.0.0.1]]</includeonly>
 * <onlyinclude>[[Special:Contributions/127.0.0.1|127.0.0.1]]</onlyinclude>