2 class RepoGroupTest
extends MediaWikiTestCase
{
4 function testHasForeignRepoNegative() {
5 $this->setMWGlobals( 'wgForeignFileRepos', array() );
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( array( $fakeCallback, 'callback' ), array( array() ) );
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() ) );
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',
40 'fetchDescription' => true,
41 'descriptionCacheExpiry' => 43200,
42 'apiThumbCacheExpiry' => 86400,
43 'directory' => $wgUploadDirectory
45 RepoGroup
::destroySingleton();
46 FileBackendGroup
::destroySingleton();
51 * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
53 class RepoGroupTestHelper
{
54 function callback( FileRepo
$repo, array $foo ) {