aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/cache/BacklinkCacheFactoryTest.php
blob: 69377d8ab12365e4b67c4b48c644d3ef63162f20 (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
<?php

use MediaWiki\Cache\BacklinkCacheFactory;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Linker\LinksMigration;
use MediaWiki\Page\PageReferenceValue;
use Wikimedia\Rdbms\IConnectionProvider;

/**
 * @group Cache
 */
class BacklinkCacheFactoryTest extends MediaWikiUnitTestCase {

	/**
	 * @covers \MediaWiki\Cache\BacklinkCacheFactory::getBacklinkCache
	 */
	public function testGetBacklinkCache() {
		$wanCache = new WANObjectCache( [ 'cache' => new EmptyBagOStuff() ] );
		$dbProvider = $this->createMock( IConnectionProvider::class );
		$page = PageReferenceValue::localReference( NS_CATEGORY, "kittens" );
		$factory = new BacklinkCacheFactory(
			$this->createMock( ServiceOptions::class ),
			$this->createMock( LinksMigration::class ),
			$wanCache,
			$this->createHookContainer(),
			$dbProvider
		);
		$cache = $factory->getBacklinkCache( $page );
		$this->assertTrue( $cache->getPage()->isSamePageAs( $page ) );

		$cache2 = $factory->getBacklinkCache( $page );
		$this->assertSame( $cache, $cache2 );

		$page2 = PageReferenceValue::localReference( NS_CATEGORY, "doggos" );
		$cache2 = $factory->getBacklinkCache( $page2 );
		$this->assertNotSame( $cache, $cache2 );
		$this->assertTrue( $cache2->getPage()->isSamePageAs( $page2 ) );
	}

}