| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Storage\Unit; |
| 4 |
|
| 5 |
use ExternalStoreAccess; |
| 6 |
use MediaWiki\Config\ServiceOptions; |
| 7 |
use MediaWiki\MainConfigNames; |
| 8 |
use MediaWiki\Storage\BlobStore; |
| 9 |
use MediaWiki\Storage\BlobStoreFactory; |
| 10 |
use MediaWiki\Storage\SqlBlobStore; |
| 11 |
use MediaWikiUnitTestCase; |
| 12 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 13 |
use Wikimedia\Rdbms\ILBFactory; |
| 14 |
use Wikimedia\Rdbms\ILoadBalancer; |
| 15 |
use Wikimedia\TestingAccessWrapper; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
class BlobStoreFactoryTest extends MediaWikiUnitTestCase { |
| 21 |
|
| 22 |
private function getBlobStoreFactory() { |
| 23 |
$lbFactory = $this->createMock( ILBFactory::class ); |
| 24 |
$lbFactory->method( 'getMainLB' )->willReturn( $this->createMock( ILoadBalancer::class ) ); |
| 25 |
$options = [ |
| 26 |
MainConfigNames::CompressRevisions => false, |
| 27 |
MainConfigNames::DefaultExternalStore => false, |
| 28 |
MainConfigNames::LegacyEncoding => false, |
| 29 |
MainConfigNames::RevisionCacheExpiry => 86400 * 7, |
| 30 |
]; |
| 31 |
return new BlobStoreFactory( |
| 32 |
$lbFactory, |
| 33 |
$this->createMock( ExternalStoreAccess::class ), |
| 34 |
$this->createMock( WANObjectCache::class ), |
| 35 |
new ServiceOptions( BlobStoreFactory::CONSTRUCTOR_OPTIONS, $options ) |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
public static function provideDbDomains() { |
| 40 |
yield [ false ]; |
| 41 |
yield [ 'someWiki' ]; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function testNewBlobStore( $dbDomain ) { |
| 48 |
$factory = $this->getBlobStoreFactory(); |
| 49 |
$store = $factory->newBlobStore( $dbDomain ); |
| 50 |
$this->assertInstanceOf( BlobStore::class, $store ); |
| 51 |
|
| 52 |
|
| 53 |
$wrapper = TestingAccessWrapper::newFromObject( $store ); |
| 54 |
$this->assertEquals( $dbDomain, $wrapper->dbDomain ); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public function testNewSqlBlobStore( $dbDomain ) { |
| 61 |
$factory = $this->getBlobStoreFactory(); |
| 62 |
$store = $factory->newSqlBlobStore( $dbDomain ); |
| 63 |
$this->assertInstanceOf( SqlBlobStore::class, $store ); |
| 64 |
|
| 65 |
$wrapper = TestingAccessWrapper::newFromObject( $store ); |
| 66 |
$this->assertEquals( $dbDomain, $wrapper->dbDomain ); |
| 67 |
} |
| 68 |
|
| 69 |
} |