diff options
author | C. Scott Ananian <cscott@cscott.net> | 2023-09-14 12:11:20 -0400 |
---|---|---|
committer | C. Scott Ananian <cscott@cscott.net> | 2024-02-07 21:22:06 -0500 |
commit | 0de13d766200708d6152551a0daf0e56b6d77adc (patch) | |
tree | f94bc30181de9bfda4259e8f77a417867887d217 /tests | |
parent | 2e3ee2af3fc071ed7d321e65abbd60b485d9d4a3 (diff) | |
download | mediawikicore-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')
11 files changed, 139 insertions, 40 deletions
diff --git a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php index 971f0ca95695..62bb5b63e2e6 100644 --- a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php +++ b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php @@ -17,6 +17,7 @@ use MediaWiki\Page\PageIdentity; use MediaWiki\Page\PageIdentityValue; use MediaWiki\Parser\ParserCacheFactory; use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; +use MediaWiki\Parser\Parsoid\ParsoidRenderID; use MediaWiki\Revision\MutableRevisionRecord; use MediaWiki\Revision\MutableRevisionSlots; use MediaWiki\Revision\RevisionRecord; @@ -1333,8 +1334,9 @@ class DerivedPageDataUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertGreaterThan( $rev->getTimestamp(), $parsoidCached->getCacheTime() ); $this->assertSame( $rev->getId(), $parsoidCached->getCacheRevisionId() ); - // Check that getParsoidRenderID() doesn't throw, so we know that $parsoidCached is valid. - $this->getServiceContainer()->getParsoidOutputAccess()->getParsoidRenderID( $parsoidCached ); + // Check that ParsoidRenderID::newFromParserOutput() doesn't throw, + // so we know that $parsoidCached is valid. + ParsoidRenderID::newFromParserOutput( $parsoidCached ); // The cached ParserOutput should not use the revision timestamp // Create nwe ParserOptions object since we setUseParsoid() above diff --git a/tests/phpunit/includes/page/ParserOutputAccessTest.php b/tests/phpunit/includes/page/ParserOutputAccessTest.php index 1742471a9022..27ff2968cda7 100644 --- a/tests/phpunit/includes/page/ParserOutputAccessTest.php +++ b/tests/phpunit/includes/page/ParserOutputAccessTest.php @@ -81,7 +81,8 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { new NullStatsdDataFactory(), new NullLogger(), $this->getServiceContainer()->getTitleFactory(), - $this->getServiceContainer()->getWikiPageFactory() + $this->getServiceContainer()->getWikiPageFactory(), + $this->getServiceContainer()->getGlobalIdGenerator() ); return $parserCache; @@ -96,7 +97,8 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { '19900220000000', new JsonCodec(), new NullStatsdDataFactory(), - new NullLogger() + new NullLogger(), + $this->getServiceContainer()->getGlobalIdGenerator() ); return $revisionOutputCache; diff --git a/tests/phpunit/includes/parser/ParserCacheTest.php b/tests/phpunit/includes/parser/ParserCacheTest.php index 01aca202f85b..0dd9b69c4b54 100644 --- a/tests/phpunit/includes/parser/ParserCacheTest.php +++ b/tests/phpunit/includes/parser/ParserCacheTest.php @@ -28,6 +28,7 @@ use Psr\Log\LogLevel; use Psr\Log\NullLogger; use TestLogger; use Wikimedia\TestingAccessWrapper; +use Wikimedia\UUID\GlobalIdGenerator; use WikiPage; /** @@ -90,6 +91,8 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase { $wikiPageFactory = $this->createMock( WikiPageFactory::class ); $wikiPageFactory->method( 'newFromTitle' )->willReturn( $wikiPageMock ); } + $globalIdGenerator = $this->createMock( GlobalIdGenerator::class ); + $globalIdGenerator->method( 'newUUIDv1' )->willReturn( 'uuid-uuid' ); return new ParserCache( 'test', $storage ?: new HashBagOStuff(), @@ -99,7 +102,8 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase { new NullStatsdDataFactory(), $logger ?: new NullLogger(), $this->createMock( TitleFactory::class ), - $wikiPageFactory + $wikiPageFactory, + $globalIdGenerator ); } @@ -124,6 +128,10 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase { $parserOutput->recordOption( $option ); } $parserOutput->updateCacheExpiry( 4242 ); + $parserOutput->setRenderId( 'dummy-render-id' ); + $parserOutput->setCacheRevisionId( 0 ); + // ParserOutput::getCacheTime() also sets it as a side effect + $parserOutput->setTimestamp( $parserOutput->getCacheTime() ); return $parserOutput; } @@ -683,6 +691,8 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase { $wikiPageMock->method( 'getContentModel' )->willReturn( CONTENT_MODEL_WIKITEXT ); $wikiPageFactory = $this->createMock( WikiPageFactory::class ); $wikiPageFactory->method( 'newFromTitle' )->willReturn( $wikiPageMock ); + $globalIdGenerator = $this->createMock( GlobalIdGenerator::class ); + $globalIdGenerator->method( 'newUUIDv1' )->willReturn( 'uuid-uuid' ); $cache = $this->getMockBuilder( ParserCache::class ) ->setConstructorArgs( [ 'test', @@ -693,7 +703,8 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase { new NullStatsdDataFactory(), new NullLogger(), $this->createMock( TitleFactory::class ), - $wikiPageFactory + $wikiPageFactory, + $globalIdGenerator ] ) ->onlyMethods( [ 'convertForCache' ] ) ->getMock(); 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() ); + } } diff --git a/tests/phpunit/includes/parser/RevisionOutputCacheTest.php b/tests/phpunit/includes/parser/RevisionOutputCacheTest.php index b3c0f2d4b756..2c35bd0d3369 100644 --- a/tests/phpunit/includes/parser/RevisionOutputCacheTest.php +++ b/tests/phpunit/includes/parser/RevisionOutputCacheTest.php @@ -24,6 +24,7 @@ use Psr\Log\NullLogger; use TestLogger; use WANObjectCache; use Wikimedia\TestingAccessWrapper; +use Wikimedia\UUID\GlobalIdGenerator; /** * @covers \MediaWiki\Parser\RevisionOutputCache @@ -74,6 +75,8 @@ class RevisionOutputCacheTest extends MediaWikiIntegrationTestCase { $expiry = 3600, $epoch = '19900220000000' ): RevisionOutputCache { + $globalIdGenerator = $this->createMock( GlobalIdGenerator::class ); + $globalIdGenerator->method( 'newUUIDv1' )->willReturn( 'uuid-uuid' ); return new RevisionOutputCache( 'test', new WANObjectCache( [ 'cache' => $storage ?: new HashBagOStuff() ] ), @@ -81,7 +84,8 @@ class RevisionOutputCacheTest extends MediaWikiIntegrationTestCase { $epoch, new JsonCodec(), new NullStatsdDataFactory(), - $logger ?: new NullLogger() + $logger ?: new NullLogger(), + $globalIdGenerator ); } diff --git a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewCurrentTest.php b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewCurrentTest.php index 09cadbfdd6ba..9ecbae6d9e49 100644 --- a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewCurrentTest.php +++ b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewCurrentTest.php @@ -63,7 +63,8 @@ class PoolWorkArticleViewCurrentTest extends PoolWorkArticleViewTest { $this->getServiceContainer()->getStatsdDataFactory(), new NullLogger(), $this->getServiceContainer()->getTitleFactory(), - $this->getServiceContainer()->getWikiPageFactory() + $this->getServiceContainer()->getWikiPageFactory(), + $this->getServiceContainer()->getGlobalIdGenerator() ); return $this->parserCache; diff --git a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewOldTest.php b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewOldTest.php index 4d899125fb6e..c3574d7f770a 100644 --- a/tests/phpunit/includes/poolcounter/PoolWorkArticleViewOldTest.php +++ b/tests/phpunit/includes/poolcounter/PoolWorkArticleViewOldTest.php @@ -6,6 +6,7 @@ use MediaWiki\PoolCounter\PoolWorkArticleViewOld; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Status\Status; use Psr\Log\NullLogger; +use Wikimedia\UUID\GlobalIdGenerator; /** * @covers \MediaWiki\PoolCounter\PoolWorkArticleViewOld @@ -58,6 +59,8 @@ class PoolWorkArticleViewOldTest extends PoolWorkArticleViewTest { * @return RevisionOutputCache */ private function installRevisionOutputCache( $bag = null ) { + $globalIdGenerator = $this->createMock( GlobalIdGenerator::class ); + $globalIdGenerator->method( 'newUUIDv1' )->willReturn( 'uuid-uuid' ); $this->cache = new RevisionOutputCache( 'test', new WANObjectCache( [ 'cache' => $bag ?: new HashBagOStuff() ] ), @@ -65,7 +68,8 @@ class PoolWorkArticleViewOldTest extends PoolWorkArticleViewTest { '20200101223344', new JsonCodec(), new NullStatsdDataFactory(), - new NullLogger() + new NullLogger(), + $globalIdGenerator ); return $this->cache; diff --git a/tests/phpunit/integration/includes/Rest/Handler/Helper/HtmlInputTransformHelperTest.php b/tests/phpunit/integration/includes/Rest/Handler/Helper/HtmlInputTransformHelperTest.php index 714dd516f54b..06cda29ff96d 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/Helper/HtmlInputTransformHelperTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/Helper/HtmlInputTransformHelperTest.php @@ -1078,7 +1078,7 @@ class HtmlInputTransformHelperTest extends MediaWikiIntegrationTestCase { $popt = ParserOptions::newFromAnon(); $pout = $access->getParserOutput( $page, $popt )->getValue(); - $key = $access->getParsoidRenderID( $pout ); + $key = ParsoidRenderID::newFromParserOutput( $pout )->getKey(); $html = $pout->getRawText(); // Load the original data based on the ETag diff --git a/tests/phpunit/integration/includes/Rest/Handler/Helper/HtmlOutputRendererHelperTest.php b/tests/phpunit/integration/includes/Rest/Handler/Helper/HtmlOutputRendererHelperTest.php index c4656c77f3f4..7d2512526f4b 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/Helper/HtmlOutputRendererHelperTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/Helper/HtmlOutputRendererHelperTest.php @@ -83,10 +83,6 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { return $count === null ? $this->any() : $this->exactly( $count ); } - public function getParsoidRenderID( ParserOutput $pout ) { - return new ParsoidRenderID( $pout->getCacheRevisionId(), $pout->getCacheTime() ); - } - /** * @param LoggerInterface|null $logger * @@ -106,7 +102,6 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { $expectedCalls = [ 'getParserOutput' => null, 'parseUncacheable' => null, - 'getParsoidRenderID' => null ]; $parsoid = $this->createNoOpMock( ParsoidOutputAccess::class, array_keys( $expectedCalls ) ); @@ -128,9 +123,6 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { return Status::newGood( $pout ); } ); - $parsoid->method( 'getParsoidRenderID' ) - ->willReturnCallback( [ $this, 'getParsoidRenderID' ] ); - $parsoid->expects( $this->exactlyOrAny( $expectedCalls[ 'parseUncacheable' ] ) ) ->method( 'parseUncacheable' ) ->willReturnCallback( function ( @@ -151,10 +143,6 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { return Status::newGood( $pout ); } ); - $parsoid->expects( $this->exactlyOrAny( $expectedCalls[ 'getParsoidRenderID' ] ) ) - ->method( 'getParsoidRenderID' ) - ->willReturnCallback( [ $this, 'getParsoidRenderID' ] ); - return $parsoid; } @@ -186,19 +174,27 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { PageIdentity $page, string $version = null ): ParserOutput { + static $counter = 0; $lang = $parserOpts->getTargetLanguage(); $lang = $lang ? $lang->getCode() : 'en'; $version ??= Parsoid::defaultHTMLVersion(); $html = "<!DOCTYPE html><html lang=\"$lang\"><body><div id='t3s7'>$html</div></body></html>"; + $revTimestamp = null; if ( $rev instanceof RevisionRecord ) { + $revTimestamp = $rev->getTimestamp(); $rev = $rev->getId(); } $pout = new ParserOutput( $html ); $pout->setCacheRevisionId( $rev ?: $page->getLatest() ); $pout->setCacheTime( wfTimestampNow() ); // will use fake time + if ( $revTimestamp ) { + $pout->setTimestamp( $revTimestamp ); + } + // We test that UUIDs are unique, so make a cheap unique UUID + $pout->setRenderId( 'bogus-uuid-' . strval( $counter++ ) ); $pout->setExtensionData( PageBundleParserOutputConverter::PARSOID_PAGE_BUNDLE_KEY, [ 'parsoid' => [ 'ids' => [ 't3s7' => [ 'dsr' => [ 0, 0, 0, 0 ] ], @@ -570,7 +566,7 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { // put HTML into the cache $pout = $helper->getHtml(); - $renderId = $this->getParsoidRenderID( $pout ); + $renderId = ParsoidRenderID::newFromParserOutput( $pout ); $lastModified = $pout->getCacheTime(); if ( $rev ) { @@ -629,8 +625,6 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { $pout = $this->makeParserOutput( $parserOpts, $html, $rev, $page ); return Status::newGood( $pout ); } ); - $poa->method( 'getParsoidRenderID' ) - ->willReturnCallback( [ $this, 'getParsoidRenderID' ] ); $helper = $this->newHelper( null, $poa ); $helper->init( $fakePage, self::PARAM_DEFAULTS, $this->newAuthority() ); @@ -639,7 +633,7 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { $this->assertNull( $helper->getRevisionId() ); $pout = $helper->getHtml(); - $renderId = $this->getParsoidRenderID( $pout ); + $renderId = ParsoidRenderID::newFromParserOutput( $pout ); $lastModified = $pout->getCacheTime(); $this->assertStringContainsString( $renderId->getKey(), $helper->getETag() ); @@ -942,8 +936,6 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { $pout = $this->makeParserOutput( $parserOpts, $html, $revision, $page ); return Status::newGood( $pout ); } ); - $poa->method( 'getParsoidRenderID' ) - ->willReturnCallback( [ $this, 'getParsoidRenderID' ] ); $helper = $this->newHelper( null, $poa ); @@ -1133,7 +1125,7 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { $output = $helper->getHtml(); $this->assertStringContainsString( 'Dummy output', $output->getText() ); - $this->assertSame( '0/dummy-output', $output->getExtensionData( 'parsoid-render-id' ) ); + $this->assertSame( '0/dummy-output', ParsoidRenderID::newFromParserOutput( $output )->getKey() ); } /** diff --git a/tests/phpunit/integration/includes/Rest/Handler/ParsoidOutputAccessTest.php b/tests/phpunit/integration/includes/Rest/Handler/ParsoidOutputAccessTest.php index 0d33b5f764ac..1980ff22933d 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/ParsoidOutputAccessTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/ParsoidOutputAccessTest.php @@ -8,6 +8,7 @@ use MediaWiki\Parser\Parsoid\PageBundleParserOutputConverter; use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; use MediaWiki\Parser\Parsoid\ParsoidParser; use MediaWiki\Parser\Parsoid\ParsoidParserFactory; +use MediaWiki\Parser\Parsoid\ParsoidRenderID; use MediaWiki\Rest\HttpException; use MediaWiki\Revision\MutableRevisionRecord; use MediaWiki\Revision\RevisionAccessException; @@ -186,7 +187,6 @@ class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase { * Tests that getParserOutput() will return output. * * @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getParserOutput - * @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getParsoidRenderID */ public function testGetParserOutput() { $this->resetServicesWithMockedParsoid( 1 ); @@ -201,8 +201,8 @@ class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase { $output = $status->getValue(); - // check that getParsoidRenderID() doesn't throw - $this->assertNotNull( $access->getParsoidRenderID( $output ) ); + // check that ParsoidRenderID::newFromParserOutput() doesn't throw + $this->assertNotNull( ParsoidRenderID::newFromParserOutput( $output ) ); // Ensure that we can still create a valid instance of PageBundle from the ParserOutput $pageBundle = PageBundleParserOutputConverter::pageBundleFromParserOutput( $output ); @@ -340,7 +340,7 @@ class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase { /** @var ParserOutput $parserOutput */ $parserOutput = $status->getValue(); - $this->assertSame( '0/dummy-output', $parserOutput->getExtensionData( 'parsoid-render-id' ) ); + $this->assertSame( '0/dummy-output', ParsoidRenderID::newFromParserOutput( $parserOutput )->getKey() ); $expTime = $parserOutput->getCacheExpiry(); $this->assertSame( 0, $expTime ); @@ -406,9 +406,9 @@ class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase { $this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status1 ); $this->checkMetadata( $status1 ); - // check that getParsoidRenderID() doesn't throw + // check that ParsoidRenderID::newFromParserOutput() doesn't throw $output1 = $status1->getValue(); - $this->assertNotNull( $access->getParsoidRenderID( $output1 ) ); + $this->assertNotNull( ParsoidRenderID::newFromParserOutput( $output1 ) ); } public static function provideSupportsContentModels() { @@ -452,7 +452,7 @@ class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase { /** @var ParserOutput $parserOutput */ $parserOutput = $status->getValue(); $this->assertStringContainsString( __METHOD__, $parserOutput->getRawText() ); - $this->assertNotEmpty( $parserOutput->getExtensionData( 'parsoid-render-id' ) ); + $this->assertNotEmpty( $parserOutput->getRenderId() ); $this->assertNotEmpty( $parserOutput->getCacheRevisionId() ); $this->assertNotEmpty( $parserOutput->getCacheTime() ); } @@ -485,7 +485,7 @@ class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase { /** @var ParserOutput $parserOutput */ $parserOutput = $status->getValue(); $this->assertStringContainsString( __METHOD__, $parserOutput->getRawText() ); - $this->assertNotEmpty( $parserOutput->getExtensionData( 'parsoid-render-id' ) ); + $this->assertNotEmpty( $parserOutput->getRenderId() ); $this->assertNotEmpty( $parserOutput->getCacheRevisionId() ); $this->assertNotEmpty( $parserOutput->getCacheTime() ); } @@ -508,7 +508,7 @@ class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase { /** @var ParserOutput $parserOutput */ $parserOutput = $status->getValue(); $this->assertStringContainsString( __METHOD__, $parserOutput->getRawText() ); - $this->assertNotEmpty( $parserOutput->getExtensionData( 'parsoid-render-id' ) ); + $this->assertNotEmpty( $parserOutput->getRenderId() ); $this->assertNotEmpty( $parserOutput->getCacheRevisionId() ); $this->assertNotEmpty( $parserOutput->getCacheTime() ); } @@ -539,7 +539,7 @@ class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase { /** @var ParserOutput $parserOutput */ $parserOutput = $status->getValue(); $this->assertStringContainsString( __METHOD__, $parserOutput->getRawText() ); - $this->assertNotEmpty( $parserOutput->getExtensionData( 'parsoid-render-id' ) ); + $this->assertNotEmpty( $parserOutput->getRenderId() ); // The revision ID is set to 0, so that's what is in the cache. $this->assertSame( 0, $parserOutput->getCacheRevisionId() ); $this->assertNotEmpty( $parserOutput->getCacheTime() ); diff --git a/tests/phpunit/unit/includes/parser/ParserCacheFactoryTest.php b/tests/phpunit/unit/includes/parser/ParserCacheFactoryTest.php index 610327bedc35..835b7cd93093 100644 --- a/tests/phpunit/unit/includes/parser/ParserCacheFactoryTest.php +++ b/tests/phpunit/unit/includes/parser/ParserCacheFactoryTest.php @@ -9,6 +9,7 @@ use MediaWiki\Parser\ParserCacheFactory; use MediaWiki\Parser\RevisionOutputCache; use MediaWiki\Title\TitleFactory; use Psr\Log\NullLogger; +use Wikimedia\UUID\GlobalIdGenerator; /** * @covers \MediaWiki\Parser\ParserCacheFactory @@ -35,7 +36,8 @@ class ParserCacheFactoryTest extends MediaWikiUnitTestCase { new NullLogger(), $options, $this->createNoOpMock( TitleFactory::class ), - $this->createNoOpMock( WikiPageFactory::class ) + $this->createNoOpMock( WikiPageFactory::class ), + $this->createNoOpMock( GlobalIdGenerator::class ) ); } |