Merge "Add tests for OutputPage::makeResourceLoaderLink()"
[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', array() );
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->getMock( 'RepoGroupTestHelper' );
19 $fakeCallback->expects( $this->once() )->method( 'callback' );
20 RepoGroup::singleton()->forEachForeignRepo( array( $fakeCallback, 'callback' ), array( array() ) );
21 }
22
23 function testForEachForeignRepoNone() {
24 $this->setMWGlobals( 'wgForeignFileRepos', array() );
25 RepoGroup::destroySingleton();
26 FileBackendGroup::destroySingleton();
27 $fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
28 $fakeCallback->expects( $this->never() )->method( 'callback' );
29 RepoGroup::singleton()->forEachForeignRepo( array( $fakeCallback, 'callback' ), array( array() ) );
30 }
31
32 private function setUpForeignRepo() {
33 global $wgUploadDirectory;
34 $this->setMWGlobals( 'wgForeignFileRepos', array( array(
35 'class' => 'ForeignAPIRepo',
36 'name' => 'wikimediacommons',
37 'backend' => 'wikimediacommons-backend',
38 'apibase' => 'https://commons.wikimedia.org/w/api.php',
39 'hashLevels' => 2,
40 'fetchDescription' => true,
41 'descriptionCacheExpiry' => 43200,
42 'apiThumbCacheExpiry' => 86400,
43 'directory' => $wgUploadDirectory
44 ) ) );
45 RepoGroup::destroySingleton();
46 FileBackendGroup::destroySingleton();
47 }
48 }
49
50 /**
51 * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
52 */
53 class RepoGroupTestHelper {
54 function callback( FileRepo $repo, array $foo ) {
55 return true;
56 }
57 }