wiki.techinc.nl/tests/phpunit/includes/filerepo/RepoGroupTest.php
addshore 959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00

59 lines
1.7 KiB
PHP

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