2019-08-13 08:52:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2024-05-20 15:25:13 +00:00
|
|
|
use MediaWiki\FileBackend\FileBackendGroup;
|
2019-08-13 08:52:13 +00:00
|
|
|
use MediaWiki\FileBackend\FSFile\TempFSFileFactory;
|
|
|
|
|
use MediaWiki\FileBackend\LockManager\LockManagerGroupFactory;
|
2022-06-29 22:34:37 +00:00
|
|
|
use MediaWiki\Tests\Unit\DummyServicesTrait;
|
2024-09-27 18:21:33 +00:00
|
|
|
use Wikimedia\Mime\MimeAnalyzer;
|
2024-07-09 13:37:44 +00:00
|
|
|
use Wikimedia\ObjectCache\BagOStuff;
|
|
|
|
|
use Wikimedia\ObjectCache\EmptyBagOStuff;
|
2024-09-27 18:13:02 +00:00
|
|
|
use Wikimedia\ObjectCache\WANObjectCache;
|
2019-08-13 08:52:13 +00:00
|
|
|
|
|
|
|
|
/**
|
2024-05-20 15:25:13 +00:00
|
|
|
* @coversDefaultClass \MediaWiki\FileBackend\FileBackendGroup
|
2019-08-13 08:52:13 +00:00
|
|
|
*/
|
|
|
|
|
class FileBackendGroupTest extends MediaWikiUnitTestCase {
|
2022-06-29 22:34:37 +00:00
|
|
|
use DummyServicesTrait;
|
2019-08-13 08:52:13 +00:00
|
|
|
use FileBackendGroupTestTrait;
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2020-03-16 18:07:56 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
// This config var is not yet dependency-injected.
|
|
|
|
|
// FileBackendGroup has a default option 'profiler', that holds a closure
|
|
|
|
|
// that calls Profiler::instance(), which doesn't use service wiring yet.
|
|
|
|
|
// Without this, the variable would be undefined there.
|
|
|
|
|
// TODO: Remove this once Profiler uses service wiring and is injected
|
|
|
|
|
// into FileBackendGroup.
|
|
|
|
|
$GLOBALS['wgProfiler'] = [];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 08:52:13 +00:00
|
|
|
private static function getWikiID() {
|
|
|
|
|
return 'mywiki';
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
private function getLocalServerCache(): BagOStuff {
|
2019-08-13 08:52:13 +00:00
|
|
|
if ( !$this->srvCache ) {
|
|
|
|
|
$this->srvCache = new EmptyBagOStuff;
|
|
|
|
|
}
|
|
|
|
|
return $this->srvCache;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
private function getWANObjectCache(): WANObjectCache {
|
2019-08-13 08:52:13 +00:00
|
|
|
if ( !$this->wanCache ) {
|
2022-07-18 08:39:00 +00:00
|
|
|
$this->wanCache = $this->createNoOpMock( WANObjectCache::class );
|
2019-08-13 08:52:13 +00:00
|
|
|
}
|
|
|
|
|
return $this->wanCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $domain Expected argument that LockManagerGroupFactory::getLockManagerGroup
|
|
|
|
|
* will receive
|
2021-01-16 19:44:17 +00:00
|
|
|
* @return LockManagerGroupFactory
|
2019-08-13 08:52:13 +00:00
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
private function getLockManagerGroupFactory( $domain = 'mywiki' ): LockManagerGroupFactory {
|
2019-08-13 08:52:13 +00:00
|
|
|
if ( !$this->lmgFactory ) {
|
2022-07-18 08:39:00 +00:00
|
|
|
$mockLmg = $this->createNoOpMock( LockManagerGroup::class, [ 'get' ] );
|
2019-08-13 08:52:13 +00:00
|
|
|
$mockLmg->method( 'get' )->with( 'fsLockManager' )->willReturn( 'string lock manager' );
|
|
|
|
|
|
2022-07-18 08:39:00 +00:00
|
|
|
$this->lmgFactory = $this->createNoOpMock( LockManagerGroupFactory::class,
|
|
|
|
|
[ 'getLockManagerGroup' ] );
|
2019-08-13 08:52:13 +00:00
|
|
|
$this->lmgFactory->method( 'getLockManagerGroup' )->with( $domain )
|
|
|
|
|
->willReturn( $mockLmg );
|
|
|
|
|
}
|
|
|
|
|
return $this->lmgFactory;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
private function getTempFSFileFactory(): TempFSFileFactory {
|
2019-08-13 08:52:13 +00:00
|
|
|
if ( !$this->tmpFileFactory ) {
|
2022-07-18 08:39:00 +00:00
|
|
|
$this->tmpFileFactory = $this->createNoOpMock( TempFSFileFactory::class );
|
2019-08-13 08:52:13 +00:00
|
|
|
}
|
|
|
|
|
return $this->tmpFileFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $options Dictionary to use as a source for ServiceOptions before defaults, plus
|
|
|
|
|
* the following options are available to override other arguments:
|
2023-09-11 18:39:11 +00:00
|
|
|
* * 'readOnlyMode'
|
2019-08-13 08:52:13 +00:00
|
|
|
* * 'lmgFactory'
|
|
|
|
|
* * 'mimeAnalyzer'
|
|
|
|
|
* * 'tmpFileFactory'
|
2021-01-16 19:44:17 +00:00
|
|
|
* @return FileBackendGroup
|
2019-08-13 08:52:13 +00:00
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
private function newObj( array $options = [] ): FileBackendGroup {
|
2019-08-13 08:52:13 +00:00
|
|
|
return new FileBackendGroup(
|
|
|
|
|
new ServiceOptions(
|
|
|
|
|
FileBackendGroup::CONSTRUCTOR_OPTIONS, $options, self::getDefaultOptions() ),
|
2023-09-11 18:39:11 +00:00
|
|
|
$this->getDummyReadOnlyMode( $options['readOnlyMode'] ?? false ),
|
2019-08-13 08:52:13 +00:00
|
|
|
$this->getLocalServerCache(),
|
|
|
|
|
$this->getWANObjectCache(),
|
2022-07-18 08:39:00 +00:00
|
|
|
$options['mimeAnalyzer'] ?? $this->createNoOpMock( MimeAnalyzer::class ),
|
2019-08-13 08:52:13 +00:00
|
|
|
$options['lmgFactory'] ?? $this->getLockManagerGroupFactory(),
|
2019-10-23 13:34:53 +00:00
|
|
|
$options['tmpFileFactory'] ?? $this->getTempFSFileFactory(),
|
2022-06-29 22:34:37 +00:00
|
|
|
$this->getDummyObjectFactory()
|
2019-08-13 08:52:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|