| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
class RepoGroupTest extends MediaWikiIntegrationTestCase { |
| 9 |
|
| 10 |
public function testHasForeignRepoNegative() { |
| 11 |
$this->overrideConfigValue( MainConfigNames::ForeignFileRepos, [] ); |
| 12 |
$this->assertFalse( $this->getServiceContainer()->getRepoGroup()->hasForeignRepos() ); |
| 13 |
} |
| 14 |
|
| 15 |
public function testHasForeignRepoPositive() { |
| 16 |
$this->setUpForeignRepo(); |
| 17 |
$this->assertTrue( $this->getServiceContainer()->getRepoGroup()->hasForeignRepos() ); |
| 18 |
} |
| 19 |
|
| 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' ], [ [] ] ); |
| 26 |
} |
| 27 |
|
| 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' ], [ [] ] ); |
| 34 |
} |
| 35 |
|
| 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 |
] ] ); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
class RepoGroupTestHelper { |
| 56 |
public function callback( FileRepo $repo, array $foo ) { |
| 57 |
return true; |
| 58 |
} |
| 59 |
} |