Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / filerepo / RepoGroupTest.php
blob25c6e9520d862551f3250a102fad012e3d3636af
1 <?php
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',
41 'hashLevels' => 2,
42 'fetchDescription' => true,
43 'descriptionCacheExpiry' => 43200,
44 'apiThumbCacheExpiry' => 86400,
45 'directory' => $wgUploadDirectory
46 ] ] );
47 RepoGroup::destroySingleton();
48 FileBackendGroup::destroySingleton();
52 /**
53 * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
55 class RepoGroupTestHelper {
56 function callback( FileRepo $repo, array $foo ) {
57 return true;