aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/integration/includes/filerepo/LocalAndForeignDBRepoTest.php
blob: f1538f90ae51a3e749ca9f1d0bd78045cd4f7066 (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
78
79
80
81
82
83
84
85
86
87
88
89
<?php

use MediaWiki\WikiMap\WikiMap;

class LocalAndForeignDBRepoTest extends MediaWikiIntegrationTestCase {
	/**
	 * @covers \LocalRepo::getSharedCacheKey
	 * @covers \ForeignDBViaLBRepo::getSharedCacheKey
	 */
	public function testsSharedCacheKey() {
		$wikiId = WikiMap::getCurrentWikiDbDomain()->getId();
		$wanCache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
		$localRepo = new LocalRepo( [
			'name' => 'local',
			'backend' => 'local-backend',
			'wanCache' => $wanCache
		] );
		$foreignRepo = new ForeignDBViaLBRepo( [
			'name' => 'local',
			'backend' => 'local-backend',
			'wiki' => $wikiId,
			'hasSharedCache' => true,
			'wanCache' => $wanCache
		] );
		$foreignRepo2 = new ForeignDBViaLBRepo( [
			'name' => 'local',
			'backend' => 'local-backend',
			'wiki' => 'weirdoutside-domain',
			'hasSharedCache' => true,
			'wanCache' => $wanCache
		] );

		$sharedKeyForLocal = $localRepo->getSharedCacheKey( 'class', 93 );
		$sharedKeyForForeign = $foreignRepo->getSharedCacheKey( 'class', 93 );
		$sharedKeyForForiegn2 = $foreignRepo2->getSharedCacheKey( 'class', 93 );

		$this->assertSame(
			$wanCache->makeGlobalKey( 'filerepo-class', $wikiId, 93 ),
			$sharedKeyForLocal,
			"Shared key (repo is on local domain)"
		);
		$this->assertSame(
			$sharedKeyForLocal,
			$sharedKeyForForeign,
			"Shared key (repo is on foreign domain)"
		);

		$this->assertSame(
			$wanCache->makeGlobalKey( 'filerepo-class', 'weirdoutside-domain', 93 ),
			$sharedKeyForForiegn2,
			"Shared key (repo is on a different foreign domain)"
		);
	}

	/**
	 * @covers \LocalRepo::getLocalCacheKey
	 * @covers \ForeignDBViaLBRepo::getLocalCacheKey
	 */
	public function testsLocalCacheKey() {
		$wikiId = WikiMap::getCurrentWikiDbDomain()->getId();
		$wanCache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
		$localRepo = new LocalRepo( [
			'name' => 'local',
			'backend' => 'local-backend',
			'wanCache' => $wanCache
		] );
		$foreignRepo = new ForeignDBViaLBRepo( [
			'name' => 'local',
			'backend' => 'local-backend',
			'wiki' => $wikiId,
			'hasSharedCache' => true,
			'wanCache' => $wanCache
		] );

		$nonsharedKeyForLocal = $localRepo->getLocalCacheKey( 'class', 93 );
		$nonsharedKeyForForeign = $foreignRepo->getLocalCacheKey( 'class', 93 );

		$this->assertSame(
			$wanCache->makeKey( 'filerepo-class', 'local', 93 ),
			$nonsharedKeyForLocal,
			"Non-shared key (repo is on local domain)"
		);
		$this->assertSame(
			$wanCache->makeKey( 'filerepo-class', 'local', 93 ),
			$nonsharedKeyForForeign,
			"Non-shared key (repo is on local domain)"
		);
	}
}