aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests/Backend
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-05-13 11:42:01 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2016-05-24 08:41:21 +0200
commit6ea54e73e82fb02bb6bfa3a189a861f90c00d105 (patch)
tree5ba453b1469a326cd0b216e771debb2972ace172 /apps/files_external/tests/Backend
parent6d7a1b9bd42637bd3cd1b1307082f010ab8b11ba (diff)
downloadnextcloud-server-6ea54e73e82fb02bb6bfa3a189a861f90c00d105.tar.gz
nextcloud-server-6ea54e73e82fb02bb6bfa3a189a861f90c00d105.zip
Move Lib\Backend to PSR-4
Diffstat (limited to 'apps/files_external/tests/Backend')
-rw-r--r--apps/files_external/tests/Backend/BackendTest.php89
-rw-r--r--apps/files_external/tests/Backend/LegacyBackendTest.php113
2 files changed, 202 insertions, 0 deletions
diff --git a/apps/files_external/tests/Backend/BackendTest.php b/apps/files_external/tests/Backend/BackendTest.php
new file mode 100644
index 00000000000..50f6d975bf0
--- /dev/null
+++ b/apps/files_external/tests/Backend/BackendTest.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Tests\Backend;
+
+use \OCA\Files_External\Lib\Backend\Backend;
+
+class BackendTest extends \Test\TestCase {
+
+ public function testJsonSerialization() {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->setMethods(['jsonSerializeDefinition'])
+ ->getMock();
+ $backend->expects($this->once())
+ ->method('jsonSerializeDefinition')
+ ->willReturn(['foo' => 'bar', 'name' => 'abc']);
+
+ $backend->setPriority(57);
+ $backend->addAuthScheme('foopass');
+ $backend->addAuthScheme('barauth');
+
+ $json = $backend->jsonSerialize();
+ $this->assertEquals('bar', $json['foo']);
+ $this->assertEquals('abc', $json['name']);
+ $this->assertEquals($json['name'], $json['backend']);
+ $this->assertEquals(57, $json['priority']);
+
+ $this->assertContains('foopass', $json['authSchemes']);
+ $this->assertContains('barauth', $json['authSchemes']);
+ }
+
+ public function validateStorageProvider() {
+ return [
+ [true, true],
+ [false, false],
+ ];
+ }
+
+ /**
+ * @dataProvider validateStorageProvider
+ */
+ public function testValidateStorage($expectedSuccess, $definitionSuccess) {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->setMethods(['validateStorageDefinition'])
+ ->getMock();
+ $backend->expects($this->atMost(1))
+ ->method('validateStorageDefinition')
+ ->willReturn($definitionSuccess);
+
+ $storageConfig = $this->getMockBuilder('\OCA\Files_External\Lib\StorageConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->assertEquals($expectedSuccess, $backend->validateStorage($storageConfig));
+ }
+
+ public function testLegacyAuthMechanismCallback() {
+ $backend = new Backend();
+ $backend->setLegacyAuthMechanismCallback(function(array $params) {
+ if (isset($params['ping'])) {
+ return 'pong';
+ }
+ return 'foobar';
+ });
+
+ $this->assertEquals('pong', $backend->getLegacyAuthMechanism(['ping' => true]));
+ $this->assertEquals('foobar', $backend->getLegacyAuthMechanism(['other' => true]));
+ $this->assertEquals('foobar', $backend->getLegacyAuthMechanism());
+ }
+
+}
diff --git a/apps/files_external/tests/Backend/LegacyBackendTest.php b/apps/files_external/tests/Backend/LegacyBackendTest.php
new file mode 100644
index 00000000000..465b79a6be6
--- /dev/null
+++ b/apps/files_external/tests/Backend/LegacyBackendTest.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Tests\Backend;
+
+use \OCA\Files_External\Lib\Backend\LegacyBackend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\MissingDependency;
+
+class LegacyBackendTest extends \Test\TestCase {
+
+ /**
+ * @return MissingDependency[]
+ */
+ public static function checkDependencies() {
+ return [
+ (new MissingDependency('abc'))->setMessage('foobar')
+ ];
+ }
+
+ public function testConstructor() {
+ $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest';
+ $definition = [
+ 'configuration' => [
+ 'textfield' => 'Text field',
+ 'passwordfield' => '*Password field',
+ 'checkbox' => '!Checkbox',
+ 'hiddenfield' => '#Hidden field',
+ 'optionaltext' => '&Optional text field',
+ 'optionalpassword' => '&*Optional password field',
+ ],
+ 'backend' => 'Backend text',
+ 'priority' => 123,
+ 'custom' => 'foo/bar.js',
+ 'has_dependencies' => true,
+ ];
+
+ $backend = new LegacyBackend($class, $definition, $auth);
+
+ $this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass());
+ $this->assertEquals('Backend text', $backend->getText());
+ $this->assertEquals(123, $backend->getPriority());
+ $this->assertContains('foo/bar.js', $backend->getCustomJs());
+ $this->assertArrayHasKey('builtin', $backend->getAuthSchemes());
+ $this->assertEquals($auth, $backend->getLegacyAuthMechanism());
+
+ $dependencies = $backend->checkDependencies();
+ $this->assertCount(1, $dependencies);
+ $this->assertEquals('abc', $dependencies[0]->getDependency());
+ $this->assertEquals('foobar', $dependencies[0]->getMessage());
+
+ $parameters = $backend->getParameters();
+ $this->assertEquals('Text field', $parameters['textfield']->getText());
+ $this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['textfield']->getType());
+ $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['textfield']->getFlags());
+ $this->assertEquals('Password field', $parameters['passwordfield']->getText());
+ $this->assertEquals(DefinitionParameter::VALUE_PASSWORD, $parameters['passwordfield']->getType());
+ $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['passwordfield']->getFlags());
+ $this->assertEquals('Checkbox', $parameters['checkbox']->getText());
+ $this->assertEquals(DefinitionParameter::VALUE_BOOLEAN, $parameters['checkbox']->getType());
+ $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['checkbox']->getFlags());
+ $this->assertEquals('Hidden field', $parameters['hiddenfield']->getText());
+ $this->assertEquals(DefinitionParameter::VALUE_HIDDEN, $parameters['hiddenfield']->getType());
+ $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['hiddenfield']->getFlags());
+ $this->assertEquals('Optional text field', $parameters['optionaltext']->getText());
+ $this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['optionaltext']->getType());
+ $this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionaltext']->getFlags());
+ $this->assertEquals('Optional password field', $parameters['optionalpassword']->getText());
+ $this->assertEquals(DefinitionParameter::VALUE_PASSWORD, $parameters['optionalpassword']->getType());
+ $this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionalpassword']->getFlags());
+ }
+
+ public function testNoDependencies() {
+ $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest';
+ $definition = [
+ 'configuration' => [
+ ],
+ 'backend' => 'Backend text',
+ ];
+
+ $backend = new LegacyBackend($class, $definition, $auth);
+
+ $dependencies = $backend->checkDependencies();
+ $this->assertCount(0, $dependencies);
+ }
+
+}