82ff12e3e3442badef66b34626d56922cd157c58
[lhc/web/wiklou.git] / tests / phpunit / includes / filerepo / RepoGroupTest.php
1 <?php
2 class RepoGroupTest extends MediaWikiTestCase {
3
4 function testHasForeignRepoNegative() {
5 $this->setMwGlobals( 'wgForeignFileRepos', [] );
6 RepoGroup::destroySingleton();
7 FileBackendGroup::destroySingleton();
8 $this->assertFalse( RepoGroup::singleton()->hasForeignRepos() );
9 }
10
11 function testHasForeignRepoPositive() {
12 $this->setUpForeignRepo();
13 $this->assertTrue( RepoGroup::singleton()->hasForeignRepos() );
14 }
15
16 function testForEachForeignRepo() {
17 $this->setUpForeignRepo();
18 $fakeCallback = $this->createMock( 'RepoGroupTestHelper' );
19 $fakeCallback->expects( $this->once() )->method( 'callback' );
20 RepoGroup::singleton()->forEachForeignRepo(
21 [ $fakeCallback, 'callback' ], [ [] ] );
22 }
23
24 function testForEachForeignRepoNone() {
25 $this->setMwGlobals( 'wgForeignFileRepos', [] );
26 RepoGroup::destroySingleton();
27 FileBackendGroup::destroySingleton();
28 $fakeCallback = $this->createMock( 'RepoGroupTestHelper' );
29 $fakeCallback->expects( $this->never() )->method( 'callback' );
30 RepoGroup::singleton()->forEachForeignRepo(
31 [ $fakeCallback, 'callback' ], [ [] ] );
32 }
33
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',
41 'hashLevels' => 2,
42 'fetchDescription' => true,
43 'descriptionCacheExpiry' => 43200,
44 'apiThumbCacheExpiry' => 86400,
45 'directory' => $wgUploadDirectory
46 ] ] );
47 RepoGroup::destroySingleton();
48 FileBackendGroup::destroySingleton();
49 }
50 }
51
52 /**
53 * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
54 */
55 class RepoGroupTestHelper {
56 function callback( FileRepo $repo, array $foo ) {
57 return true;
58 }
59 }