wiki.techinc.nl/tests/phpunit/includes/filerepo/RepoGroupTest.php
Kunal Mehta 6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00

59 lines
1.8 KiB
PHP

<?php
class RepoGroupTest extends MediaWikiTestCase {
function testHasForeignRepoNegative() {
$this->setMwGlobals( 'wgForeignFileRepos', [] );
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
$this->assertFalse( RepoGroup::singleton()->hasForeignRepos() );
}
function testHasForeignRepoPositive() {
$this->setUpForeignRepo();
$this->assertTrue( RepoGroup::singleton()->hasForeignRepos() );
}
function testForEachForeignRepo() {
$this->setUpForeignRepo();
$fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
$fakeCallback->expects( $this->once() )->method( 'callback' );
RepoGroup::singleton()->forEachForeignRepo(
[ $fakeCallback, 'callback' ], [ [] ] );
}
function testForEachForeignRepoNone() {
$this->setMwGlobals( 'wgForeignFileRepos', [] );
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
$fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
$fakeCallback->expects( $this->never() )->method( 'callback' );
RepoGroup::singleton()->forEachForeignRepo(
[ $fakeCallback, 'callback' ], [ [] ] );
}
private function setUpForeignRepo() {
global $wgUploadDirectory;
$this->setMwGlobals( 'wgForeignFileRepos', [ [
'class' => 'ForeignAPIRepo',
'name' => 'wikimediacommons',
'backend' => 'wikimediacommons-backend',
'apibase' => 'https://commons.wikimedia.org/w/api.php',
'hashLevels' => 2,
'fetchDescription' => true,
'descriptionCacheExpiry' => 43200,
'apiThumbCacheExpiry' => 86400,
'directory' => $wgUploadDirectory
] ] );
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
}
}
/**
* Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
*/
class RepoGroupTestHelper {
function callback( FileRepo $repo, array $foo ) {
return true;
}
}