MediaWiki  REL1_24
RepoGroupTest.php
Go to the documentation of this file.
00001 <?php
00002 class RepoGroupTest extends MediaWikiTestCase {
00003 
00004     function testHasForeignRepoNegative() {
00005         $this->setMwGlobals( 'wgForeignFileRepos', array() );
00006         RepoGroup::destroySingleton();
00007         FileBackendGroup::destroySingleton();
00008         $this->assertFalse( RepoGroup::singleton()->hasForeignRepos() );
00009     }
00010 
00011     function testHasForeignRepoPositive() {
00012         $this->setUpForeignRepo();
00013         $this->assertTrue( RepoGroup::singleton()->hasForeignRepos() );
00014     }
00015 
00016     function testForEachForeignRepo() {
00017         $this->setUpForeignRepo();
00018         $fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
00019         $fakeCallback->expects( $this->once() )->method( 'callback' );
00020         RepoGroup::singleton()->forEachForeignRepo(
00021             array( $fakeCallback, 'callback' ), array( array() ) );
00022     }
00023 
00024     function testForEachForeignRepoNone() {
00025         $this->setMwGlobals( 'wgForeignFileRepos', array() );
00026         RepoGroup::destroySingleton();
00027         FileBackendGroup::destroySingleton();
00028         $fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
00029         $fakeCallback->expects( $this->never() )->method( 'callback' );
00030         RepoGroup::singleton()->forEachForeignRepo(
00031             array( $fakeCallback, 'callback' ), array( array() ) );
00032     }
00033 
00034     private function setUpForeignRepo() {
00035         global $wgUploadDirectory;
00036         $this->setMwGlobals( 'wgForeignFileRepos', array( array(
00037             'class' => 'ForeignAPIRepo',
00038             'name' => 'wikimediacommons',
00039             'backend' => 'wikimediacommons-backend',
00040             'apibase' => 'https://commons.wikimedia.org/w/api.php',
00041             'hashLevels' => 2,
00042             'fetchDescription' => true,
00043             'descriptionCacheExpiry' => 43200,
00044             'apiThumbCacheExpiry' => 86400,
00045             'directory' => $wgUploadDirectory
00046         ) ) );
00047         RepoGroup::destroySingleton();
00048         FileBackendGroup::destroySingleton();
00049     }
00050 }
00051 
00055 class RepoGroupTestHelper {
00056     function callback( FileRepo $repo, array $foo ) {
00057         return true;
00058     }
00059 }