aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/parser/ParserCacheTest.php
diff options
context:
space:
mode:
authorPetr Pchelko <ppchelko@wikimedia.org>2020-09-23 14:31:14 -0700
committerPetr Pchelko <ppchelko@wikimedia.org>2020-10-13 08:31:22 -0700
commit13574e8404dae1597da4b7eb90763738f07d7f8e (patch)
tree9af444254b66a118fda75d982f5759ce6b839908 /tests/phpunit/includes/parser/ParserCacheTest.php
parentccc6e4e65fcc19367fc83c288680d15204ac1d45 (diff)
downloadmediawikicore-13574e8404dae1597da4b7eb90763738f07d7f8e.tar.gz
mediawikicore-13574e8404dae1597da4b7eb90763738f07d7f8e.zip
Deprecate ParserCache::getKey and replace it with getMetadata
Bug: T263689 Change-Id: I4a71e5a7eb1c25cd53b857c115883cd00160736b
Diffstat (limited to 'tests/phpunit/includes/parser/ParserCacheTest.php')
-rw-r--r--tests/phpunit/includes/parser/ParserCacheTest.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/phpunit/includes/parser/ParserCacheTest.php b/tests/phpunit/includes/parser/ParserCacheTest.php
index d589fcd7301e..4fbf8d09af83 100644
--- a/tests/phpunit/includes/parser/ParserCacheTest.php
+++ b/tests/phpunit/includes/parser/ParserCacheTest.php
@@ -103,6 +103,110 @@ class ParserCacheTest extends MediaWikiIntegrationTestCase {
}
/**
+ * @covers ParserCache::getMetadata
+ * @covers ParserCache::getKey
+ */
+ public function testGetMetadataMissing() {
+ $cache = $this->createParserCache();
+
+ $metadataFromCache = $cache->getMetadata( $this->page, ParserCache::USE_CURRENT_ONLY );
+ $this->assertFalse( $cache->getKey( $this->page,
+ ParserOptions::newFromAnon(), ParserCache::USE_CURRENT_ONLY ) );
+ $this->assertNotFalse( $cache->getKey( $this->page, ParserOptions::newFromAnon() ) );
+ $this->assertNull( $metadataFromCache );
+ }
+
+ /**
+ * @covers ParserCache::getMetadata
+ * @covers ParserCache::getKey
+ */
+ public function testGetMetadataAllGood() {
+ $cache = $this->createParserCache();
+ $parserOutput = $this->createDummyParserOutput();
+ $cache->save( $parserOutput, $this->page, ParserOptions::newFromAnon(), $this->cacheTime );
+
+ $metadataFromCache = $cache->getMetadata( $this->page, ParserCache::USE_CURRENT_ONLY );
+ $this->assertNotNull( $metadataFromCache );
+ $this->assertNotFalse( $cache->getKey( $this->page,
+ ParserOptions::newFromAnon(), ParserCache::USE_CURRENT_ONLY ) );
+ $this->assertSame( $this->getDummyUsedOptions(), $metadataFromCache->getUsedOptions() );
+ $this->assertSame( 4242, $metadataFromCache->getCacheExpiry() );
+ $this->assertSame( $this->page->getRevisionRecord()->getId(),
+ $metadataFromCache->getCacheRevisionId() );
+ $this->assertSame( $this->cacheTime, $metadataFromCache->getCacheTime() );
+ }
+
+ /**
+ * @covers ParserCache::getMetadata
+ * @covers ParserCache::getKey
+ */
+ public function testGetMetadataExpired() {
+ $cache = $this->createParserCache();
+ $parserOutput = $this->createDummyParserOutput();
+ $cache->save( $parserOutput, $this->page, ParserOptions::newFromAnon(), $this->cacheTime );
+ $this->page->getTitle()->invalidateCache( MWTimestamp::convert( TS_MW, time() + 10000 ) );
+ $this->page->clear();
+
+ $this->assertNull( $cache->getMetadata( $this->page, ParserCache::USE_CURRENT_ONLY ) );
+ $this->assertFalse( $cache->getKey( $this->page,
+ ParserOptions::newFromAnon(), ParserCache::USE_CURRENT_ONLY ) );
+ $metadataFromCache = $cache->getMetadata( $this->page, ParserCache::USE_EXPIRED );
+ $this->assertNotFalse( $cache->getKey( $this->page,
+ ParserOptions::newFromAnon(), ParserCache::USE_EXPIRED ) );
+ $this->assertNotNull( $metadataFromCache );
+ $this->assertSame( $this->getDummyUsedOptions(), $metadataFromCache->getUsedOptions() );
+ $this->assertSame( 4242, $metadataFromCache->getCacheExpiry() );
+ $this->assertSame( $this->page->getRevisionRecord()->getId(),
+ $metadataFromCache->getCacheRevisionId() );
+ $this->assertSame( $this->cacheTime, $metadataFromCache->getCacheTime() );
+ }
+
+ /**
+ * @covers ParserCache::getMetadata
+ * @covers ParserCache::getKey
+ */
+ public function testGetMetadataOutdated() {
+ $cache = $this->createParserCache();
+ $parserOutput = $this->createDummyParserOutput();
+ $cache->save( $parserOutput, $this->page, ParserOptions::newFromAnon(), $this->cacheTime );
+ $this->editPage( $this->page->getTitle()->getDBkey(), 'Edit!' );
+ $this->page->clear();
+
+ $this->assertNull( $cache->getMetadata( $this->page, ParserCache::USE_CURRENT_ONLY ) );
+ $this->assertFalse( $cache->getKey( $this->page,
+ ParserOptions::newFromAnon(), ParserCache::USE_CURRENT_ONLY ) );
+ $this->assertNull( $cache->getMetadata( $this->page, ParserCache::USE_EXPIRED ) );
+ $this->assertFalse( $cache->getKey( $this->page,
+ ParserOptions::newFromAnon(), ParserCache::USE_EXPIRED ) );
+ $metadataFromCache = $cache->getMetadata( $this->page, ParserCache::USE_OUTDATED );
+ $this->assertNotFalse( $cache->getKey( $this->page,
+ ParserOptions::newFromAnon(), ParserCache::USE_OUTDATED ) );
+ $this->assertSame( $this->getDummyUsedOptions(), $metadataFromCache->getUsedOptions() );
+ $this->assertSame( 4242, $metadataFromCache->getCacheExpiry() );
+ $this->assertNotSame( $this->page->getRevisionRecord()->getId(),
+ $metadataFromCache->getCacheRevisionId() );
+ $this->assertSame( $this->cacheTime, $metadataFromCache->getCacheTime() );
+ }
+
+ /**
+ * @covers ParserCache::makeParserOutputKey
+ */
+ public function testMakeParserOutputKey() {
+ $cache = $this->createParserCache();
+
+ $options1 = ParserOptions::newFromAnon();
+ $options1->setOption( $this->getDummyUsedOptions()[0], 'value1' );
+ $key1 = $cache->makeParserOutputKey( $this->page, $options1, $this->getDummyUsedOptions() );
+ $this->assertNotNull( $key1 );
+
+ $options2 = ParserOptions::newFromAnon();
+ $options2->setOption( $this->getDummyUsedOptions()[0], 'value2' );
+ $key2 = $cache->makeParserOutputKey( $this->page, $options2, $this->getDummyUsedOptions() );
+ $this->assertNotNull( $key2 );
+ $this->assertNotSame( $key1, $key2 );
+ }
+
+ /*
* Test that fetching without storing first returns false.
* @covers ParserCache::get
*/