aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/parser/ParserOutputTest.php
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@cscott.net>2023-09-14 12:11:20 -0400
committerC. Scott Ananian <cscott@cscott.net>2024-02-07 21:22:06 -0500
commit0de13d766200708d6152551a0daf0e56b6d77adc (patch)
treef94bc30181de9bfda4259e8f77a417867887d217 /tests/phpunit/includes/parser/ParserOutputTest.php
parent2e3ee2af3fc071ed7d321e65abbd60b485d9d4a3 (diff)
downloadmediawikicore-0de13d766200708d6152551a0daf0e56b6d77adc.tar.gz
mediawikicore-0de13d766200708d6152551a0daf0e56b6d77adc.zip
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able to identify a specific parse when there are dependencies (for example in an edit based on that parse). This is recorded as a property added to the ParserOutput, not the parent CacheTime interface. Even though the render ID is /related/ to the CacheTime interface, CacheTime is also used directly as a parser cache key, and the UUID should not be part of the lookup key. In general we are trying to move the location where these cache properties are set as early as possible, so we check at each location to ensure we don't overwrite a previously-set value. Eventually we can convert most of these checks into assertions that the cache properties have already been set (T350538). The primary location for setting cache properties is the ContentRenderer. Moved setting the revision timestamp into ContentRenderer as well, as it was set along the same code paths. An extra parameter was added to ContentRenderer::getParserOutput() to support this. Added merge code to ParserOutput::mergeInternalMetaDataFrom() which should ensure that cache time, revision, timestamp, and render id are all set properly when multiple slots are combined together in MCR. In order to ensure the render ID is set on all codepaths we needed to plumb the GlobalIdGenerator service into ContentRenderer, ParserCache, ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it should only be necessary in the ContentRenderer. Bug: T350538 Bug: T349868 Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80 Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
Diffstat (limited to 'tests/phpunit/includes/parser/ParserOutputTest.php')
-rw-r--r--tests/phpunit/includes/parser/ParserOutputTest.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php
index 43e81d4dfd1b..0b788804d40e 100644
--- a/tests/phpunit/includes/parser/ParserOutputTest.php
+++ b/tests/phpunit/includes/parser/ParserOutputTest.php
@@ -992,6 +992,43 @@ EOF
'getUsedOptions' => [ 'Foo', 'Bar', 'Zoo' ],
] ];
+ // cache time
+ $someTime = "20240207202040";
+ $someLaterTime = "20240207202112";
+ $a = new ParserOutput();
+ $a->setCacheTime( $someTime );
+ $b = new ParserOutput();
+ yield 'only left cache time' => [ $a, $b, [ 'getCacheTime' => $someTime ] ];
+
+ $a = new ParserOutput();
+ $b = new ParserOutput();
+ $b->setCacheTime( $someTime );
+ yield 'only right cache time' => [ $a, $b, [ 'getCacheTime' => $someTime ] ];
+
+ $a = new ParserOutput();
+ $b = new ParserOutput();
+ $a->setCacheTime( $someLaterTime );
+ $b->setCacheTime( $someTime );
+ yield 'left has later cache time' => [ $a, $b, [ 'getCacheTime' => $someLaterTime ] ];
+
+ $a = new ParserOutput();
+ $b = new ParserOutput();
+ $a->setCacheTime( $someTime );
+ $b->setCacheTime( $someLaterTime );
+ yield 'right has later cache time' => [ $a, $b, [ 'getCacheTime' => $someLaterTime ] ];
+
+ $a = new ParserOutput();
+ $b = new ParserOutput();
+ $a->setCacheTime( -1 );
+ $b->setCacheTime( $someTime );
+ yield 'left is uncacheable' => [ $a, $b, [ 'getCacheTime' => "-1" ] ];
+
+ $a = new ParserOutput();
+ $b = new ParserOutput();
+ $a->setCacheTime( $someTime );
+ $b->setCacheTime( -1 );
+ yield 'right is uncacheable' => [ $a, $b, [ 'getCacheTime' => "-1" ] ];
+
// timestamp ------------
$a = new ParserOutput();
$a->setTimestamp( '20180101000011' );
@@ -1103,6 +1140,7 @@ EOF
* @param array $expected
*/
public function testMergeInternalMetaDataFrom( ParserOutput $a, ParserOutput $b, $expected ) {
+ $this->filterDeprecated( '/^CacheTime::setCacheTime called with -1 as an argument/' );
$a->mergeInternalMetaDataFrom( $b );
$this->assertFieldValues( $a, $expected );
@@ -1320,4 +1358,47 @@ EOF
$this->assertEquals( [ 'baz.com' ], $po->getExtraCSPDefaultSrcs() );
$this->assertEquals( [ 'fred.com', 'xyzzy.com' ], $po->getExtraCSPStyleSrcs() );
}
+
+ /**
+ * @covers \MediaWiki\Parser\ParserOutput::getCacheTime()
+ * @covers \MediaWiki\Parser\ParserOutput::setCacheTime()
+ */
+ public function testCacheTime() {
+ $po = new ParserOutput();
+
+ // Should not have a cache time yet
+ $this->assertFalse( $po->hasCacheTime() );
+ // But calling ::get assigns a cache time
+ $po->getCacheTime();
+ $this->assertTrue( $po->hasCacheTime() );
+ // Reset cache time
+ $po->setCacheTime( "20240207202040" );
+ $this->assertSame( "20240207202040", $po->getCacheTime() );
+ }
+
+ /**
+ * @covers \MediaWiki\Parser\ParserOutput::getRenderId()
+ * @covers \MediaWiki\Parser\ParserOutput::setRenderId()
+ */
+ public function testRenderId() {
+ $po = new ParserOutput();
+
+ // Should be null when unset
+ $this->assertNull( $po->getRenderId() );
+
+ // Sanity check for setter and getter
+ $po->setRenderId( "TestRenderId" );
+ $this->assertEquals( "TestRenderId", $po->getRenderId() );
+ }
+
+ /**
+ * @covers \MediaWiki\Parser\ParserOutput::getRenderId()
+ */
+ public function testRenderIdBackCompat() {
+ $po = new ParserOutput();
+
+ // Parser cache used to contain extension data under a different name
+ $po->setExtensionData( 'parsoid-render-id', "1234/LegacyRenderId" );
+ $this->assertEquals( "LegacyRenderId", $po->getRenderId() );
+ }
}