Merge "HTML escape parameter 'text' of hook 'SkinEditSectionLinks'"
[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 $this->overrideMwServices();
11 FileBackendGroup::destroySingleton();
12 $this->assertFalse( RepoGroup::singleton()->hasForeignRepos() );
13 }
14
15 function testHasForeignRepoPositive() {
16 $this->setUpForeignRepo();
17 $this->assertTrue( RepoGroup::singleton()->hasForeignRepos() );
18 }
19
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' ], [ [] ] );
26 }
27
28 function testForEachForeignRepoNone() {
29 $this->setMwGlobals( 'wgForeignFileRepos', [] );
30 $this->overrideMwServices();
31 FileBackendGroup::destroySingleton();
32 $fakeCallback = $this->createMock( RepoGroupTestHelper::class );
33 $fakeCallback->expects( $this->never() )->method( 'callback' );
34 RepoGroup::singleton()->forEachForeignRepo(
35 [ $fakeCallback, 'callback' ], [ [] ] );
36 }
37
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',
45 'hashLevels' => 2,
46 'fetchDescription' => true,
47 'descriptionCacheExpiry' => 43200,
48 'apiThumbCacheExpiry' => 86400,
49 'directory' => $wgUploadDirectory
50 ] ] );
51 $this->overrideMwServices();
52 FileBackendGroup::destroySingleton();
53 }
54 }
55
56 /**
57 * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
58 */
59 class RepoGroupTestHelper {
60 function callback( FileRepo $repo, array $foo ) {
61 return true;
62 }
63 }