6 class RepoGroupTest
extends MediaWikiTestCase
{
8 function testHasForeignRepoNegative() {
9 $this->setMwGlobals( 'wgForeignFileRepos', [] );
10 FileBackendGroup
::destroySingleton();
11 $this->assertFalse( RepoGroup
::singleton()->hasForeignRepos() );
14 function testHasForeignRepoPositive() {
15 $this->setUpForeignRepo();
16 $this->assertTrue( RepoGroup
::singleton()->hasForeignRepos() );
19 function testForEachForeignRepo() {
20 $this->setUpForeignRepo();
21 $fakeCallback = $this->createMock( RepoGroupTestHelper
::class );
22 $fakeCallback->expects( $this->once() )->method( 'callback' );
23 RepoGroup
::singleton()->forEachForeignRepo(
24 [ $fakeCallback, 'callback' ], [ [] ] );
27 function testForEachForeignRepoNone() {
28 $this->setMwGlobals( 'wgForeignFileRepos', [] );
29 FileBackendGroup
::destroySingleton();
30 $fakeCallback = $this->createMock( RepoGroupTestHelper
::class );
31 $fakeCallback->expects( $this->never() )->method( 'callback' );
32 RepoGroup
::singleton()->forEachForeignRepo(
33 [ $fakeCallback, 'callback' ], [ [] ] );
36 private function setUpForeignRepo() {
37 global $wgUploadDirectory;
38 $this->setMwGlobals( 'wgForeignFileRepos', [ [
39 'class' => ForeignAPIRepo
::class,
40 'name' => 'wikimediacommons',
41 'backend' => 'wikimediacommons-backend',
42 'apibase' => 'https://commons.wikimedia.org/w/api.php',
44 'fetchDescription' => true,
45 'descriptionCacheExpiry' => 43200,
46 'apiThumbCacheExpiry' => 86400,
47 'directory' => $wgUploadDirectory
49 FileBackendGroup
::destroySingleton();
54 * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
56 class RepoGroupTestHelper
{
57 function callback( FileRepo
$repo, array $foo ) {