summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/Core/Controller/OCSControllerTest.php35
-rw-r--r--tests/lib/CapabilitiesManagerTest.php28
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/Core/Controller/OCSControllerTest.php b/tests/Core/Controller/OCSControllerTest.php
index e6066a80142..9d0a3dae118 100644
--- a/tests/Core/Controller/OCSControllerTest.php
+++ b/tests/Core/Controller/OCSControllerTest.php
@@ -85,6 +85,9 @@ class OCSControllerTest extends TestCase {
}
public function testGetCapabilities() {
+ $this->userSession->expects($this->once())
+ ->method('isLoggedIn')
+ ->willReturn(true);
list($major, $minor, $micro) = \OCP\Util::getVersion();
$result = [];
@@ -112,6 +115,38 @@ class OCSControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->getCapabilities());
}
+ public function testGetCapabilitiesPublic() {
+ $this->userSession->expects($this->once())
+ ->method('isLoggedIn')
+ ->willReturn(false);
+ list($major, $minor, $micro) = \OCP\Util::getVersion();
+
+ $result = [];
+ $result['version'] = array(
+ 'major' => $major,
+ 'minor' => $minor,
+ 'micro' => $micro,
+ 'string' => \OC_Util::getVersionString(),
+ 'edition' => '',
+ );
+
+ $capabilities = [
+ 'foo' => 'bar',
+ 'a' => [
+ 'b' => true,
+ 'c' => 11,
+ ]
+ ];
+ $this->capabilitiesManager->method('getCapabilities')
+ ->with(true)
+ ->willReturn($capabilities);
+
+ $result['capabilities'] = $capabilities;
+
+ $expected = new DataResponse($result);
+ $this->assertEquals($expected, $this->controller->getCapabilities());
+ }
+
public function testPersonCheckValid() {
$this->userManager->method('checkPassword')
->with(
diff --git a/tests/lib/CapabilitiesManagerTest.php b/tests/lib/CapabilitiesManagerTest.php
index 75fbdb8d89f..139940eb306 100644
--- a/tests/lib/CapabilitiesManagerTest.php
+++ b/tests/lib/CapabilitiesManagerTest.php
@@ -24,6 +24,7 @@ namespace Test;
use OC\CapabilitiesManager;
use OCP\AppFramework\QueryException;
use OCP\Capabilities\ICapability;
+use OCP\Capabilities\IPublicCapability;
use OCP\ILogger;
class CapabilitiesManagerTest extends TestCase {
@@ -35,6 +36,7 @@ class CapabilitiesManagerTest extends TestCase {
private $logger;
public function setUp() {
+ parent::setUp();
$this->logger = $this->getMockBuilder('OCP\ILogger')->getMock();
$this->manager = new CapabilitiesManager($this->logger);
}
@@ -60,6 +62,24 @@ class CapabilitiesManagerTest extends TestCase {
}
/**
+ * Test a public capabilitie
+ */
+ public function testPublicCapability() {
+ $this->manager->registerCapability(function() {
+ return new PublicSimpleCapability1();
+ });
+ $this->manager->registerCapability(function() {
+ return new SimpleCapability2();
+ });
+ $this->manager->registerCapability(function() {
+ return new SimpleCapability3();
+ });
+
+ $res = $this->manager->getCapabilities(true);
+ $this->assertEquals(['foo' => 1], $res);
+ }
+
+ /**
* Test that we need something that implents ICapability
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The given Capability (Test\NoCapability) does not implement the ICapability interface
@@ -160,6 +180,14 @@ class SimpleCapability3 implements ICapability {
}
}
+class PublicSimpleCapability1 implements IPublicCapability {
+ public function getCapabilities() {
+ return [
+ 'foo' => 1
+ ];
+ }
+}
+
class NoCapability {
public function getCapabilities() {
return [