Merge "Make Special:ChangeContentModel field labels consistently use colons"
[lhc/web/wiklou.git] / tests / phpunit / includes / filerepo / RepoGroupTest.php
1 <?php
2
3 /**
4 * @covers RepoGroup
5 */
6 class RepoGroupTest extends MediaWikiTestCase {
7
8 function testHasForeignRepoNegative() {
9 $this->setMwGlobals( 'wgForeignFileRepos', [] );
10 FileBackendGroup::destroySingleton();
11 $this->assertFalse( RepoGroup::singleton()->hasForeignRepos() );
12 }
13
14 function testHasForeignRepoPositive() {
15 $this->setUpForeignRepo();
16 $this->assertTrue( RepoGroup::singleton()->hasForeignRepos() );
17 }
18
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' ], [ [] ] );
25 }
26
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' ], [ [] ] );
34 }
35
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',
43 'hashLevels' => 2,
44 'fetchDescription' => true,
45 'descriptionCacheExpiry' => 43200,
46 'apiThumbCacheExpiry' => 86400,
47 'directory' => $wgUploadDirectory
48 ] ] );
49 FileBackendGroup::destroySingleton();
50 }
51 }
52
53 /**
54 * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
55 */
56 class RepoGroupTestHelper {
57 function callback( FileRepo $repo, array $foo ) {
58 return true;
59 }
60 }