summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/filerepo/RepoGroupTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/tests/phpunit/includes/filerepo/RepoGroupTest.php')
-rw-r--r--www/wiki/tests/phpunit/includes/filerepo/RepoGroupTest.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/filerepo/RepoGroupTest.php b/www/wiki/tests/phpunit/includes/filerepo/RepoGroupTest.php
new file mode 100644
index 00000000..5a343f65
--- /dev/null
+++ b/www/wiki/tests/phpunit/includes/filerepo/RepoGroupTest.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * @covers RepoGroup
+ */
+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->createMock( RepoGroupTestHelper::class );
+ $fakeCallback->expects( $this->once() )->method( 'callback' );
+ RepoGroup::singleton()->forEachForeignRepo(
+ [ $fakeCallback, 'callback' ], [ [] ] );
+ }
+
+ function testForEachForeignRepoNone() {
+ $this->setMwGlobals( 'wgForeignFileRepos', [] );
+ RepoGroup::destroySingleton();
+ FileBackendGroup::destroySingleton();
+ $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
+ ] ] );
+ 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;
+ }
+}