Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserOutputTest.php
index 3c73430..34ddb1f 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -32,6 +33,12 @@ class ParserOutputTest extends MediaWikiLangTestCase {
                ];
        }
 
+       public function tearDown() {
+               MWTimestamp::setFakeTime( false );
+
+               parent::tearDown();
+       }
+
        /**
         * Test to make sure ParserOutput::isLinkInternal behaves properly
         * @dataProvider provideIsLinkInternal
@@ -391,7 +398,6 @@ EOF
                $a->addHeadItem( '<foo1>' );
                $a->addHeadItem( '<bar1>', 'bar' );
                $a->addModules( 'test-module-a' );
-               $a->addModuleScripts( 'test-module-script-a' );
                $a->addModuleStyles( 'test-module-styles-a' );
                $b->addJsConfigVars( 'test-config-var-a', 'a' );
 
@@ -400,7 +406,6 @@ EOF
                $b->addHeadItem( '<foo2>' );
                $b->addHeadItem( '<bar2>', 'bar' );
                $b->addModules( 'test-module-b' );
-               $b->addModuleScripts( 'test-module-script-b' );
                $b->addModuleStyles( 'test-module-styles-b' );
                $b->addJsConfigVars( 'test-config-var-b', 'b' );
                $b->addJsConfigVars( 'test-config-var-a', 'X' );
@@ -415,10 +420,6 @@ EOF
                                'test-module-a',
                                'test-module-b',
                        ],
-                       'getModuleScripts' => [
-                               'test-module-script-a',
-                               'test-module-script-b',
-                       ],
                        'getModuleStyles' => [
                                'test-module-styles-a',
                                'test-module-styles-b',
@@ -843,6 +844,11 @@ EOF
                $this->assertFieldValues( $a, $expected );
        }
 
+       /**
+        * @covers ParserOutput::mergeInternalMetaDataFrom
+        * @covers ParserOutput::getTimes
+        * @covers ParserOutput::resetParseStartTime
+        */
        public function testMergeInternalMetaDataFrom_parseStartTime() {
                /** @var object $a */
                $a = new ParserOutput();
@@ -871,7 +877,7 @@ EOF
 
                $bClocks = $b->mParseStartTime;
 
-               $a->mergeInternalMetaDataFrom( $b->object, 'b' );
+               $a->mergeInternalMetaDataFrom( $b->object );
                $mergedClocks = $a->mParseStartTime;
 
                foreach ( $mergedClocks as $clock => $timestamp ) {
@@ -884,7 +890,7 @@ EOF
                $a->resetParseStartTime();
                $aClocks = $a->mParseStartTime;
 
-               $a->mergeInternalMetaDataFrom( $b->object, 'b' );
+               $a->mergeInternalMetaDataFrom( $b->object );
                $mergedClocks = $a->mParseStartTime;
 
                foreach ( $mergedClocks as $clock => $timestamp ) {
@@ -896,7 +902,7 @@ EOF
                $a = new ParserOutput();
                $a = TestingAccessWrapper::newFromObject( $a );
 
-               $a->mergeInternalMetaDataFrom( $b->object, 'b' );
+               $a->mergeInternalMetaDataFrom( $b->object );
                $mergedClocks = $a->mParseStartTime;
 
                foreach ( $mergedClocks as $clock => $timestamp ) {
@@ -904,4 +910,33 @@ EOF
                }
        }
 
+       /**
+        * @covers ParserOutput::getCacheTime
+        * @covers ParserOutput::setCacheTime
+        */
+       public function testGetCacheTime() {
+               $clock = MWTimestamp::convert( TS_UNIX, '20100101000000' );
+               MWTimestamp::setFakeTime( function () use ( &$clock ) {
+                       return $clock++;
+               } );
+
+               $po = new ParserOutput();
+               $time = $po->getCacheTime();
+
+               // Use current (fake) time per default. Ignore the last digit.
+               // Subsequent calls must yield the exact same timestamp as the first.
+               $this->assertStringStartsWith( '2010010100000', $time );
+               $this->assertSame( $time, $po->getCacheTime() );
+
+               // After setting, the getter must return the time that was set.
+               $time = '20110606112233';
+               $po->setCacheTime( $time );
+               $this->assertSame( $time, $po->getCacheTime() );
+
+               // support -1 as a marker for "not cacheable"
+               $time = -1;
+               $po->setCacheTime( $time );
+               $this->assertSame( $time, $po->getCacheTime() );
+       }
+
 }