2 class RepoGroupTest
extends MediaWikiTestCase
{
4 function testHasForeignRepoNegative() {
5 $this->setMwGlobals( 'wgForeignFileRepos', [] );
6 RepoGroup
::destroySingleton();
7 FileBackendGroup
::destroySingleton();
8 $this->assertFalse( RepoGroup
::singleton()->hasForeignRepos() );
11 function testHasForeignRepoPositive() {
12 $this->setUpForeignRepo();
13 $this->assertTrue( RepoGroup
::singleton()->hasForeignRepos() );
16 function testForEachForeignRepo() {
17 $this->setUpForeignRepo();
18 $fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
19 $fakeCallback->expects( $this->once() )->method( 'callback' );
20 RepoGroup
::singleton()->forEachForeignRepo(
21 [ $fakeCallback, 'callback' ], [ [] ] );
24 function testForEachForeignRepoNone() {
25 $this->setMwGlobals( 'wgForeignFileRepos', [] );
26 RepoGroup
::destroySingleton();
27 FileBackendGroup
::destroySingleton();
28 $fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
29 $fakeCallback->expects( $this->never() )->method( 'callback' );
30 RepoGroup
::singleton()->forEachForeignRepo(
31 [ $fakeCallback, 'callback' ], [ [] ] );
34 private function setUpForeignRepo() {
35 global $wgUploadDirectory;
36 $this->setMwGlobals( 'wgForeignFileRepos', [ [
37 'class' => 'ForeignAPIRepo',
38 'name' => 'wikimediacommons',
39 'backend' => 'wikimediacommons-backend',
40 'apibase' => 'https://commons.wikimedia.org/w/api.php',
42 'fetchDescription' => true,
43 'descriptionCacheExpiry' => 43200,
44 'apiThumbCacheExpiry' => 86400,
45 'directory' => $wgUploadDirectory
47 RepoGroup
::destroySingleton();
48 FileBackendGroup
::destroySingleton();
53 * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
55 class RepoGroupTestHelper
{
56 function callback( FileRepo
$repo, array $foo ) {