];
}
+ public function tearDown() {
+ MWTimestamp::setFakeTime( false );
+
+ parent::tearDown();
+ }
+
/**
* Test to make sure ParserOutput::isLinkInternal behaves properly
* @dataProvider provideIsLinkInternal
$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
}
}
+ /**
+ * @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() );
+ }
+
}