namespace Test;
+use OC\CapabilitiesManager;
+use OCP\AppFramework\QueryException;
+use OCP\Capabilities\ICapability;
+use OCP\ILogger;
+
class CapabilitiesManagerTest extends TestCase {
+ /** @var CapabilitiesManager */
+ private $manager;
+
+ /** @var ILogger */
+ private $logger;
+
+ public function setUp() {
+ $this->logger = $this->getMockBuilder('OCP\ILogger')->getMock();
+ $this->manager = new CapabilitiesManager($this->logger);
+ }
+
/**
* Test no capabilities
*/
public function testNoCapabilities() {
- $manager = new \OC\CapabilitiesManager();
- $res = $manager->getCapabilities();
+ $res = $this->manager->getCapabilities();
$this->assertEmpty($res);
}
* Test a valid capabilitie
*/
public function testValidCapability() {
- $manager = new \OC\CapabilitiesManager();
-
- $manager->registerCapability(function() {
+ $this->manager->registerCapability(function() {
return new SimpleCapability();
});
- $res = $manager->getCapabilities();
+ $res = $this->manager->getCapabilities();
$this->assertEquals(['foo' => 1], $res);
}
* @expectedExceptionMessage The given Capability (Test\NoCapability) does not implement the ICapability interface
*/
public function testNoICapability() {
- $manager = new \OC\CapabilitiesManager();
-
- $manager->registerCapability(function() {
+ $this->manager->registerCapability(function() {
return new NoCapability();
});
- $res = $manager->getCapabilities();
+ $res = $this->manager->getCapabilities();
$this->assertEquals([], $res);
}
* Test a bunch of merged Capabilities
*/
public function testMergedCapabilities() {
- $manager = new \OC\CapabilitiesManager();
-
- $manager->registerCapability(function() {
+ $this->manager->registerCapability(function() {
return new SimpleCapability();
});
- $manager->registerCapability(function() {
+ $this->manager->registerCapability(function() {
return new SimpleCapability2();
});
- $manager->registerCapability(function() {
+ $this->manager->registerCapability(function() {
return new SimpleCapability3();
});
- $res = $manager->getCapabilities();
+ $res = $this->manager->getCapabilities();
$expected = [
'foo' => 1,
'bar' => [
* Test deep identical capabilities
*/
public function testDeepIdenticalCapabilities() {
- $manager = new \OC\CapabilitiesManager();
-
- $manager->registerCapability(function() {
+ $this->manager->registerCapability(function() {
return new DeepCapability();
});
- $manager->registerCapability(function() {
+ $this->manager->registerCapability(function() {
return new DeepCapability();
});
- $res = $manager->getCapabilities();
+ $res = $this->manager->getCapabilities();
$expected = [
'foo' => [
'bar' => [
$this->assertEquals($expected, $res);
}
+
+ public function testInvalidCapability() {
+ $this->manager->registerCapability(function () {
+ throw new QueryException();
+ });
+
+ $this->logger->expects($this->once())
+ ->method('error');
+
+ $res = $this->manager->getCapabilities();
+
+ $this->assertEquals([], $res);
+ }
}
-class SimpleCapability implements \OCP\Capabilities\ICapability {
+class SimpleCapability implements ICapability {
public function getCapabilities() {
return [
'foo' => 1
}
}
-class SimpleCapability2 implements \OCP\Capabilities\ICapability {
+class SimpleCapability2 implements ICapability {
public function getCapabilities() {
return [
'bar' => ['x' => 1]
}
}
-class SimpleCapability3 implements \OCP\Capabilities\ICapability {
+class SimpleCapability3 implements ICapability {
public function getCapabilities() {
return [
'bar' => ['y' => 2]
}
}
-class DeepCapability implements \OCP\Capabilities\ICapability {
+class DeepCapability implements ICapability {
public function getCapabilities() {
return [
'foo' => [
];
}
}
-