Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / filerepo / RepoGroupTest.php
blob2a4be946716487a95ebf8d718eebdda3bc83ec24
1 <?php
3 use MediaWiki\MainConfigNames;
5 /**
6 * @covers \RepoGroup
7 */
8 class RepoGroupTest extends MediaWikiIntegrationTestCase {
10 public function testHasForeignRepoNegative() {
11 $this->overrideConfigValue( MainConfigNames::ForeignFileRepos, [] );
12 $this->assertFalse( $this->getServiceContainer()->getRepoGroup()->hasForeignRepos() );
15 public function testHasForeignRepoPositive() {
16 $this->setUpForeignRepo();
17 $this->assertTrue( $this->getServiceContainer()->getRepoGroup()->hasForeignRepos() );
20 public function testForEachForeignRepo() {
21 $this->setUpForeignRepo();
22 $fakeCallback = $this->createMock( RepoGroupTestHelper::class );
23 $fakeCallback->expects( $this->once() )->method( 'callback' );
24 $this->getServiceContainer()->getRepoGroup()->forEachForeignRepo(
25 [ $fakeCallback, 'callback' ], [ [] ] );
28 public function testForEachForeignRepoNone() {
29 $this->overrideConfigValue( MainConfigNames::ForeignFileRepos, [] );
30 $fakeCallback = $this->createMock( RepoGroupTestHelper::class );
31 $fakeCallback->expects( $this->never() )->method( 'callback' );
32 $this->getServiceContainer()->getRepoGroup()->forEachForeignRepo(
33 [ $fakeCallback, 'callback' ], [ [] ] );
36 private function setUpForeignRepo() {
37 global $wgUploadDirectory;
38 $this->overrideConfigValue( MainConfigNames::ForeignFileRepos, [ [
39 'class' => ForeignAPIRepo::class,
40 'name' => 'wikimediacommons',
41 'backend' => 'wikimediacommons-backend',
42 'apibase' => 'https://commons.wikimedia.org/w/api.php',
43 'hashLevels' => 2,
44 'fetchDescription' => true,
45 'descriptionCacheExpiry' => 43200,
46 'apiThumbCacheExpiry' => 86400,
47 'directory' => $wgUploadDirectory
48 ] ] );
52 /**
53 * Quick helper class to use as a mock callback for RepoGroup::forEachForeignRepo.
55 class RepoGroupTestHelper {
56 public function callback( FileRepo $repo, array $foo ) {
57 return true;