2014-07-03 06:12:27 +00:00
|
|
|
<?php
|
2017-12-25 04:05:41 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers RepoGroup
|
|
|
|
|
*/
|
2014-07-03 06:12:27 +00:00
|
|
|
class RepoGroupTest extends MediaWikiTestCase {
|
|
|
|
|
|
2019-10-09 18:24:07 +00:00
|
|
|
public function testHasForeignRepoNegative() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( 'wgForeignFileRepos', [] );
|
2014-07-03 06:12:27 +00:00
|
|
|
$this->assertFalse( RepoGroup::singleton()->hasForeignRepos() );
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 18:24:07 +00:00
|
|
|
public function testHasForeignRepoPositive() {
|
2014-07-03 06:12:27 +00:00
|
|
|
$this->setUpForeignRepo();
|
|
|
|
|
$this->assertTrue( RepoGroup::singleton()->hasForeignRepos() );
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 18:24:07 +00:00
|
|
|
public function testForEachForeignRepo() {
|
2014-07-03 06:12:27 +00:00
|
|
|
$this->setUpForeignRepo();
|
2018-01-13 00:02:09 +00:00
|
|
|
$fakeCallback = $this->createMock( RepoGroupTestHelper::class );
|
2014-07-03 06:12:27 +00:00
|
|
|
$fakeCallback->expects( $this->once() )->method( 'callback' );
|
2014-07-24 17:03:17 +00:00
|
|
|
RepoGroup::singleton()->forEachForeignRepo(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $fakeCallback, 'callback' ], [ [] ] );
|
2014-07-03 06:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-09 18:24:07 +00:00
|
|
|
public function testForEachForeignRepoNone() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( 'wgForeignFileRepos', [] );
|
2018-01-13 00:02:09 +00:00
|
|
|
$fakeCallback = $this->createMock( RepoGroupTestHelper::class );
|
2014-07-03 06:12:27 +00:00
|
|
|
$fakeCallback->expects( $this->never() )->method( 'callback' );
|
2014-07-24 17:03:17 +00:00
|
|
|
RepoGroup::singleton()->forEachForeignRepo(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $fakeCallback, 'callback' ], [ [] ] );
|
2014-07-03 06:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function setUpForeignRepo() {
|
|
|
|
|
global $wgUploadDirectory;
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( 'wgForeignFileRepos', [ [
|
2018-01-13 00:02:09 +00:00
|
|
|
'class' => ForeignAPIRepo::class,
|
2014-07-03 06:12:27 +00:00
|
|
|
'name' => 'wikimediacommons',
|
|
|
|
|
'backend' => 'wikimediacommons-backend',
|
|
|
|
|
'apibase' => 'https://commons.wikimedia.org/w/api.php',
|
|
|
|
|
'hashLevels' => 2,
|
|
|
|
|
'fetchDescription' => true,
|
|
|
|
|
'descriptionCacheExpiry' => 43200,
|
|
|
|
|
'apiThumbCacheExpiry' => 86400,
|
|
|
|
|
'directory' => $wgUploadDirectory
|
2016-02-17 09:09:32 +00:00
|
|
|
] ] );
|
2014-07-03 06:12:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
|
|
|
|
|
*/
|
|
|
|
|
class RepoGroupTestHelper {
|
2019-10-09 18:24:07 +00:00
|
|
|
public function callback( FileRepo $repo, array $foo ) {
|
2014-07-03 06:12:27 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|