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