aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/parser/ParserCacheFactoryTest.php
blob: 7b0bcf06d67ad60558857202fd4a739abf72900c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

namespace MediaWiki\Tests\Parser;

use MediaWiki\Config\ServiceOptions;
use MediaWiki\Json\JsonCodec;
use MediaWiki\MainConfigNames;
use MediaWiki\MainConfigSchema;
use MediaWiki\Page\WikiPageFactory;
use MediaWiki\Parser\ParserCacheFactory;
use MediaWiki\Parser\RevisionOutputCache;
use MediaWiki\Title\TitleFactory;
use MediaWikiUnitTestCase;
use ParserCache;
use Psr\Log\NullLogger;
use Wikimedia\ObjectCache\HashBagOStuff;
use Wikimedia\ObjectCache\WANObjectCache;
use Wikimedia\Stats\StatsFactory;
use Wikimedia\UUID\GlobalIdGenerator;

/**
 * @covers \MediaWiki\Parser\ParserCacheFactory
 */
class ParserCacheFactoryTest extends MediaWikiUnitTestCase {

	/**
	 * @return ParserCacheFactory
	 */
	private function newParserCacheFactory() {
		$options = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
			MainConfigNames::CacheEpoch => '20200202112233',
			MainConfigNames::OldRevisionParserCacheExpireTime => 60,
			MainConfigNames::ParserCacheFilterConfig
				=> MainConfigSchema::getDefaultValue( MainConfigNames::ParserCacheFilterConfig ),
		] );

		return new ParserCacheFactory(
			new HashBagOStuff(),
			new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
			$this->createHookContainer(),
			new JsonCodec(),
			StatsFactory::newNull(),
			new NullLogger(),
			$options,
			$this->createNoOpMock( TitleFactory::class ),
			$this->createNoOpMock( WikiPageFactory::class ),
			$this->createNoOpMock( GlobalIdGenerator::class )
		);
	}

	public function testGetParserCache() {
		$factory = $this->newParserCacheFactory();

		$a = $factory->getParserCache( 'test' );
		$this->assertInstanceOf( ParserCache::class, $a );

		$b = $factory->getParserCache( 'test' );
		$this->assertSame( $a, $b );

		$c = $factory->getParserCache( 'xyzzy' );
		$this->assertNotSame( $a, $c );
	}

	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 );
	}

}