| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Storage; |
| 4 |
|
| 5 |
use MediaWiki\Logger\LoggerFactory; |
| 6 |
use MediaWiki\Storage\NameTableStore; |
| 7 |
use MediaWiki\Storage\NameTableStoreFactory; |
| 8 |
use MediaWikiIntegrationTestCase; |
| 9 |
use PHPUnit\Framework\MockObject\MockObject; |
| 10 |
use Wikimedia\Rdbms\ILBFactory; |
| 11 |
use Wikimedia\Rdbms\ILoadBalancer; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class NameTableStoreFactoryTest extends MediaWikiIntegrationTestCase { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
private function getMockLoadBalancer( $localDomain ) { |
| 23 |
$mock = $this->createMock( ILoadBalancer::class ); |
| 24 |
|
| 25 |
$mock->method( 'getLocalDomainID' ) |
| 26 |
->willReturn( $localDomain ); |
| 27 |
|
| 28 |
return $mock; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
private function getMockLoadBalancerFactory( $expectedWiki ) { |
| 36 |
$mock = $this->createMock( ILBFactory::class ); |
| 37 |
|
| 38 |
$lbFactory = $this->getServiceContainer()->getDBLoadBalancerFactory(); |
| 39 |
$localDomain = $lbFactory->getLocalDomainID(); |
| 40 |
|
| 41 |
$mock->method( 'getLocalDomainID' )->willReturn( $localDomain ); |
| 42 |
|
| 43 |
$mock->expects( $this->once() ) |
| 44 |
->method( 'getMainLB' ) |
| 45 |
->with( $expectedWiki ) |
| 46 |
->willReturnCallback( function ( $domain ) use ( $localDomain ) { |
| 47 |
return $this->getMockLoadBalancer( $localDomain ); |
| 48 |
} ); |
| 49 |
|
| 50 |
return $mock; |
| 51 |
} |
| 52 |
|
| 53 |
public static function provideTestGet() { |
| 54 |
return [ |
| 55 |
[ |
| 56 |
'change_tag_def', |
| 57 |
false, |
| 58 |
false, |
| 59 |
], |
| 60 |
[ |
| 61 |
'content_models', |
| 62 |
false, |
| 63 |
false, |
| 64 |
], |
| 65 |
[ |
| 66 |
'slot_roles', |
| 67 |
false, |
| 68 |
false, |
| 69 |
], |
| 70 |
[ |
| 71 |
'change_tag_def', |
| 72 |
'test7245', |
| 73 |
'test7245', |
| 74 |
], |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public function testGet( $tableName, $wiki, $expectedWiki ) { |
| 80 |
$services = $this->getServiceContainer(); |
| 81 |
$wiki2 = ( $wiki === false ) |
| 82 |
? $services->getDBLoadBalancerFactory()->getLocalDomainID() |
| 83 |
: $wiki; |
| 84 |
$names = new NameTableStoreFactory( |
| 85 |
$this->getMockLoadBalancerFactory( $expectedWiki ), |
| 86 |
$services->getMainWANObjectCache(), |
| 87 |
LoggerFactory::getInstance( 'NameTableStoreFactory' ) |
| 88 |
); |
| 89 |
|
| 90 |
$table = $names->get( $tableName, $wiki ); |
| 91 |
$table2 = $names->get( $tableName, $wiki2 ); |
| 92 |
$this->assertSame( $table, $table2 ); |
| 93 |
$this->assertInstanceOf( NameTableStore::class, $table ); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public function testIntegratedGetChangeTagDef() { |
| 102 |
$services = $this->getServiceContainer(); |
| 103 |
$factory = $services->getNameTableStoreFactory(); |
| 104 |
$store = $factory->getChangeTagDef(); |
| 105 |
$this->assertIsArray( $store->getMap() ); |
| 106 |
} |
| 107 |
|
| 108 |
public function testIntegratedGetContentModels() { |
| 109 |
$services = $this->getServiceContainer(); |
| 110 |
$factory = $services->getNameTableStoreFactory(); |
| 111 |
$store = $factory->getContentModels(); |
| 112 |
$this->assertIsArray( $store->getMap() ); |
| 113 |
} |
| 114 |
|
| 115 |
public function testIntegratedGetSlotRoles() { |
| 116 |
$services = $this->getServiceContainer(); |
| 117 |
$factory = $services->getNameTableStoreFactory(); |
| 118 |
$store = $factory->getSlotRoles(); |
| 119 |
$this->assertIsArray( $store->getMap() ); |
| 120 |
} |
| 121 |
} |