summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin McCorkell <robin@mccorkell.me.uk>2016-05-11 21:24:53 +0100
committerRobin McCorkell <robin@mccorkell.me.uk>2016-05-11 21:24:53 +0100
commit8f58b89c3f01c31cc7b6c59830741af048559e2e (patch)
treeaa0eb34681d799a2e4d1ff38a495ce96a3d74fff
parent711bc7469ae3261e3813a82e3807691ec3904098 (diff)
downloadnextcloud-server-8f58b89c3f01c31cc7b6c59830741af048559e2e.tar.gz
nextcloud-server-8f58b89c3f01c31cc7b6c59830741af048559e2e.zip
Add tests for backend/auth mechanism providers
-rw-r--r--apps/files_external/tests/service/backendservicetest.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/apps/files_external/tests/service/backendservicetest.php b/apps/files_external/tests/service/backendservicetest.php
index 8621c98b9b7..ba9a1f533f2 100644
--- a/apps/files_external/tests/service/backendservicetest.php
+++ b/apps/files_external/tests/service/backendservicetest.php
@@ -49,6 +49,20 @@ class BackendServiceTest extends \Test\TestCase {
return $backend;
}
+ /**
+ * @param string $class
+ *
+ * @return \OCA\Files_External\Lib\Auth\AuthMechanism
+ */
+ protected function getAuthMechanismMock($class) {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend->method('getIdentifier')->will($this->returnValue('identifier:'.$class));
+ $backend->method('getIdentifierAliases')->will($this->returnValue(['identifier:'.$class]));
+ return $backend;
+ }
+
public function testRegisterBackend() {
$service = new BackendService($this->config, $this->l10n);
@@ -76,6 +90,68 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertArrayNotHasKey('identifier_alias', $backends);
}
+ public function testBackendProvider() {
+ $service = new BackendService($this->config, $this->l10n);
+
+ $backend1 = $this->getBackendMock('\Foo\Bar');
+ $backend2 = $this->getBackendMock('\Bar\Foo');
+
+ $providerMock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider');
+ $providerMock->expects($this->once())
+ ->method('getBackends')
+ ->willReturn([$backend1, $backend2]);
+ $service->registerBackendProvider($providerMock);
+
+ $this->assertEquals($backend1, $service->getBackend('identifier:\Foo\Bar'));
+ $this->assertEquals($backend2, $service->getBackend('identifier:\Bar\Foo'));
+
+ $this->assertCount(2, $service->getBackends());
+ }
+
+ public function testAuthMechanismProvider() {
+ $service = new BackendService($this->config, $this->l10n);
+
+ $backend1 = $this->getAuthMechanismMock('\Foo\Bar');
+ $backend2 = $this->getAuthMechanismMock('\Bar\Foo');
+
+ $providerMock = $this->getMock('\OCA\Files_External\Lib\Config\IAuthMechanismProvider');
+ $providerMock->expects($this->once())
+ ->method('getAuthMechanisms')
+ ->willReturn([$backend1, $backend2]);
+ $service->registerAuthMechanismProvider($providerMock);
+
+ $this->assertEquals($backend1, $service->getAuthMechanism('identifier:\Foo\Bar'));
+ $this->assertEquals($backend2, $service->getAuthMechanism('identifier:\Bar\Foo'));
+
+ $this->assertCount(2, $service->getAuthMechanisms());
+ }
+
+ public function testMultipleBackendProviders() {
+ $service = new BackendService($this->config, $this->l10n);
+
+ $backend1a = $this->getBackendMock('\Foo\Bar');
+ $backend1b = $this->getBackendMock('\Bar\Foo');
+
+ $backend2 = $this->getBackendMock('\Dead\Beef');
+
+ $provider1Mock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider');
+ $provider1Mock->expects($this->once())
+ ->method('getBackends')
+ ->willReturn([$backend1a, $backend1b]);
+ $service->registerBackendProvider($provider1Mock);
+ $provider2Mock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider');
+ $provider2Mock->expects($this->once())
+ ->method('getBackends')
+ ->willReturn([$backend2]);
+ $service->registerBackendProvider($provider2Mock);
+
+ $this->assertEquals($backend1a, $service->getBackend('identifier:\Foo\Bar'));
+ $this->assertEquals($backend1b, $service->getBackend('identifier:\Bar\Foo'));
+ $this->assertEquals($backend2, $service->getBackend('identifier:\Dead\Beef'));
+
+ $this->assertCount(3, $service->getBackends());
+ }
+
public function testUserMountingBackends() {
$this->config->expects($this->exactly(2))
->method('getAppValue')