2020-09-25 20:02:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
|
|
|
use MediaWiki\Json\JsonCodec;
|
2021-03-24 14:05:44 +00:00
|
|
|
use MediaWiki\Page\WikiPageFactory;
|
2020-09-25 20:02:03 +00:00
|
|
|
use MediaWiki\Parser\ParserCacheFactory;
|
2020-12-04 15:28:25 +00:00
|
|
|
use MediaWiki\Parser\RevisionOutputCache;
|
|
|
|
|
use Psr\Log\NullLogger;
|
2020-09-25 20:02:03 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Parser\ParserCacheFactory
|
|
|
|
|
*/
|
|
|
|
|
class ParserCacheFactoryTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
/**
|
|
|
|
|
* @return ParserCacheFactory
|
|
|
|
|
*/
|
|
|
|
|
private function newParserCacheFactory() {
|
|
|
|
|
$options = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
|
|
|
|
|
'ParserCacheUseJson' => true,
|
|
|
|
|
'CacheEpoch' => '20200202112233',
|
|
|
|
|
'OldRevisionParserCacheExpireTime' => 60,
|
|
|
|
|
] );
|
2020-09-25 20:02:03 +00:00
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
return new ParserCacheFactory(
|
|
|
|
|
new HashBagOStuff(),
|
|
|
|
|
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
|
|
|
|
|
$this->createHookContainer(),
|
|
|
|
|
new JsonCodec(),
|
|
|
|
|
new NullStatsdDataFactory(),
|
|
|
|
|
new NullLogger(),
|
2021-03-24 14:05:44 +00:00
|
|
|
$options,
|
|
|
|
|
$this->createNoOpMock( TitleFactory::class ),
|
|
|
|
|
$this->createNoOpMock( WikiPageFactory::class )
|
2020-12-04 15:28:25 +00:00
|
|
|
);
|
2020-09-25 20:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
public function testGetParserCache() {
|
|
|
|
|
$factory = $this->newParserCacheFactory();
|
|
|
|
|
|
|
|
|
|
$a = $factory->getParserCache( 'test' );
|
|
|
|
|
$this->assertInstanceOf( ParserCache::class, $a );
|
|
|
|
|
|
|
|
|
|
$b = $factory->getParserCache( 'test' );
|
|
|
|
|
$this->assertSame( $a, $b );
|
2020-09-25 20:02:03 +00:00
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
$c = $factory->getParserCache( 'xyzzy' );
|
|
|
|
|
$this->assertNotSame( $a, $c );
|
2020-09-25 20:02:03 +00:00
|
|
|
}
|
2020-12-07 15:35:18 +00:00
|
|
|
|
2020-12-04 15:28:25 +00:00
|
|
|
public function testGetRevisionOutputCache() {
|
|
|
|
|
$factory = $this->newParserCacheFactory();
|
|
|
|
|
|
|
|
|
|
$a = $factory->getRevisionOutputCache( 'test' );
|
|
|
|
|
$this->assertInstanceOf( RevisionOutputCache::class, $a );
|
|
|
|
|
|
|
|
|
|
$b = $factory->getRevisionOutputCache( 'test' );
|
|
|
|
|
$this->assertSame( $a, $b );
|
|
|
|
|
|
|
|
|
|
$c = $factory->getRevisionOutputCache( 'xyzzy' );
|
|
|
|
|
$this->assertNotSame( $a, $c );
|
2020-12-07 15:35:18 +00:00
|
|
|
}
|
2020-12-04 15:28:25 +00:00
|
|
|
|
2020-09-25 20:02:03 +00:00
|
|
|
}
|