Merge "Selenium: record video of every test"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserOutputTest.php
index 7091d9c..390ea41 100644 (file)
@@ -32,6 +32,12 @@ class ParserOutputTest extends MediaWikiLangTestCase {
                ];
        }
 
+       public function tearDown() {
+               MWTimestamp::setFakeTime( false );
+
+               parent::tearDown();
+       }
+
        /**
         * Test to make sure ParserOutput::isLinkInternal behaves properly
         * @dataProvider provideIsLinkInternal
@@ -143,37 +149,6 @@ class ParserOutputTest extends MediaWikiLangTestCase {
                $this->assertNotContains( 'class="foo bar"', $text );
        }
 
-       public function testT203716() {
-               // simulate extra wrapping from old parser cache
-               $out = new ParserOutput( '<div class="mw-parser-output">Foo</div>' );
-               $out = unserialize( serialize( $out ) );
-
-               $plainText = $out->getText( [ 'unwrap' => true ] );
-               $wrappedText = $out->getText( [ 'unwrap' => false ] );
-               $wrappedText2 = $out->getText( [ 'wrapperDivClass' => 'mw-parser-output' ] );
-
-               $this->assertNotContains( '<div', $plainText );
-               $this->assertContains( '<div', $wrappedText );
-               $this->assertStringNotMatchesFormat( '<div%s<div%s', $wrappedText );
-               $this->assertContains( '<div', $wrappedText2 );
-               $this->assertStringNotMatchesFormat( '<div%s<div%s', $wrappedText2 );
-
-               // simulate ParserOuput creation by new parser code
-               $out = new ParserOutput( 'Foo' );
-               $out->addWrapperDivClass( 'mw-parser-outout' );
-               $out = unserialize( serialize( $out ) );
-
-               $plainText = $out->getText( [ 'unwrap' => true ] );
-               $wrappedText = $out->getText( [ 'unwrap' => false ] );
-               $wrappedText2 = $out->getText( [ 'wrapperDivClass' => 'mw-parser-output' ] );
-
-               $this->assertNotContains( '<div', $plainText );
-               $this->assertContains( '<div', $wrappedText );
-               $this->assertStringNotMatchesFormat( '<div%s<div%s', $wrappedText );
-               $this->assertContains( '<div', $wrappedText2 );
-               $this->assertStringNotMatchesFormat( '<div%s<div%s', $wrappedText2 );
-       }
-
        /**
         * @covers ParserOutput::getText
         * @dataProvider provideGetText
@@ -935,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() );
+       }
+
 }