| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\FileBackend\FileBackendGroup; |
| 4 |
use MediaWiki\FileBackend\LockManager\LockManagerGroupFactory; |
| 5 |
use MediaWiki\MainConfigNames; |
| 6 |
use MediaWiki\Tests\Unit\DummyServicesTrait; |
| 7 |
use MediaWiki\WikiMap\WikiMap; |
| 8 |
use Wikimedia\ObjectCache\EmptyBagOStuff; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class FileBackendGroupIntegrationTest extends MediaWikiIntegrationTestCase { |
| 14 |
use FileBackendGroupTestTrait; |
| 15 |
use DummyServicesTrait; |
| 16 |
|
| 17 |
private static function getWikiID() { |
| 18 |
return WikiMap::getCurrentWikiId(); |
| 19 |
} |
| 20 |
|
| 21 |
private function getLockManagerGroupFactory( $domain ): LockManagerGroupFactory { |
| 22 |
return $this->getServiceContainer()->getLockManagerGroupFactory(); |
| 23 |
} |
| 24 |
|
| 25 |
private function newObj( array $options = [] ): FileBackendGroup { |
| 26 |
$globals = [ |
| 27 |
MainConfigNames::DirectoryMode, |
| 28 |
MainConfigNames::FileBackends, |
| 29 |
MainConfigNames::ForeignFileRepos, |
| 30 |
MainConfigNames::LocalFileRepo, |
| 31 |
]; |
| 32 |
foreach ( $globals as $global ) { |
| 33 |
$this->overrideConfigValue( |
| 34 |
$global, $options[$global] ?? self::getDefaultOptions()[$global] ); |
| 35 |
} |
| 36 |
|
| 37 |
$serviceMembers = [ |
| 38 |
'readOnlyMode' => 'ReadOnlyMode', |
| 39 |
'srvCache' => 'LocalServerObjectCache', |
| 40 |
'wanCache' => 'MainWANObjectCache', |
| 41 |
'mimeAnalyzer' => 'MimeAnalyzer', |
| 42 |
'lmgFactory' => 'LockManagerGroupFactory', |
| 43 |
'tmpFileFactory' => 'TempFSFileFactory', |
| 44 |
]; |
| 45 |
|
| 46 |
foreach ( $serviceMembers as $key => $name ) { |
| 47 |
if ( isset( $options[$key] ) ) { |
| 48 |
if ( $key === 'readOnlyMode' ) { |
| 49 |
$this->setService( $name, $this->getDummyReadOnlyMode( $options[$key] ) ); |
| 50 |
} else { |
| 51 |
$this->setService( $name, $options[$key] ); |
| 52 |
} |
| 53 |
|
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
$this->assertSame( [], |
| 58 |
array_diff( array_keys( $options ), $globals, array_keys( $serviceMembers ) ) ); |
| 59 |
|
| 60 |
$services = $this->getServiceContainer(); |
| 61 |
|
| 62 |
$obj = $services->getFileBackendGroup(); |
| 63 |
|
| 64 |
foreach ( $serviceMembers as $key => $name ) { |
| 65 |
if ( $key === 'readOnlyMode' || $key === 'mimeAnalyzer' ) { |
| 66 |
continue; |
| 67 |
} |
| 68 |
$this->$key = $services->getService( $name ); |
| 69 |
if ( $key === 'srvCache' && $this->$key instanceof EmptyBagOStuff ) { |
| 70 |
|
| 71 |
|
| 72 |
$this->srvCache = null; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
return $obj; |
| 77 |
} |
| 78 |
} |