Browse Source

add method to check if a share provider for a given type is loaded

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
pull/657/head
Bjoern Schiessle 10 years ago
parent
commit
318160647a
No known key found for this signature in database GPG Key ID: 2378A753E2BF04F6
  1. 14
      lib/private/Share20/Manager.php
  2. 8
      lib/public/Share/IManager.php
  3. 40
      tests/lib/Share20/ManagerTest.php

14
lib/private/Share20/Manager.php

@ -30,6 +30,7 @@ namespace OC\Share20;
use OC\Cache\CappedMemoryCache;
use OC\Files\Mount\MoveableMount;
use OC\HintException;
use OC\Share20\Exception\ProviderException;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@ -1291,4 +1292,17 @@ class Manager implements IManager {
return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
}
/**
* @inheritdoc
*/
public function shareProviderExists($shareType) {
try {
$this->factory->getProviderForType($shareType);
} catch (ProviderException $e) {
return false;
}
return true;
}
}

8
lib/public/Share/IManager.php

@ -286,4 +286,12 @@ interface IManager {
*/
public function outgoingServer2ServerSharesAllowed();
/**
* Check if a given share provider exists
* @param int $shareType
* @return bool
* @since 9.2.0
*/
public function shareProviderExists($shareType);
}

40
tests/lib/Share20/ManagerTest.php

@ -2530,6 +2530,46 @@ class ManagerTest extends \Test\TestCase {
$this->manager->moveShare($share, 'recipient');
}
/**
* @dataProvider dataTestShareProviderExists
*/
public function testShareProviderExists($shareType, $expected) {
$factory = $this->getMockBuilder('OCP\Share\IProviderFactory')->getMock();
$factory->expects($this->any())->method('getProviderForType')
->willReturnCallback(function ($id) {
if ($id === \OCP\Share::SHARE_TYPE_USER) {
return true;
}
throw new Exception\ProviderException();
});
$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$factory,
$this->userManager,
$this->rootFolder,
$this->eventDispatcher
);
$this->assertSame($expected,
$manager->shareProviderExists($shareType)
);
}
public function dataTestShareProviderExists() {
return [
[\OCP\Share::SHARE_TYPE_USER, true],
[42, false],
];
}
public function testGetSharesInFolder() {
$factory = new DummyFactory2($this->createMock(IServerContainer::class));

Loading…
Cancel
Save