summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-02-08 15:06:38 +0100
committerRobin Appelman <robin@icewind.nl>2017-02-08 15:17:03 +0100
commitae66cf8d3713e6ed84396a23b506a7252b5860bc (patch)
treeb2557fa2b61541f61ce2882a50b6ede45943c73d
parent976cff780b44c8fbe93d4fb588ff2c8fe36b1963 (diff)
downloadnextcloud-server-ae66cf8d3713e6ed84396a23b506a7252b5860bc.tar.gz
nextcloud-server-ae66cf8d3713e6ed84396a23b506a7252b5860bc.zip
add tests
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/Federation/CloudIdManager.php2
-rw-r--r--tests/lib/Federation/CloudIdManagerTest.php99
-rw-r--r--tests/lib/Federation/CloudIdTest.php46
3 files changed, 146 insertions, 1 deletions
diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php
index d5d4e7f34cc..0df8f080d2d 100644
--- a/lib/private/Federation/CloudIdManager.php
+++ b/lib/private/Federation/CloudIdManager.php
@@ -105,4 +105,4 @@ class CloudIdManager implements ICloudIdManager {
public function isValidCloudId($cloudId) {
return strpos($cloudId, '@') !== false;
}
-} \ No newline at end of file
+}
diff --git a/tests/lib/Federation/CloudIdManagerTest.php b/tests/lib/Federation/CloudIdManagerTest.php
new file mode 100644
index 00000000000..3f1cfabe202
--- /dev/null
+++ b/tests/lib/Federation/CloudIdManagerTest.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Federation;
+
+use OC\Federation\CloudIdManager;
+use Test\TestCase;
+
+class CloudIdManagerTest extends TestCase {
+ /** @var CloudIdManager */
+ private $cloudIdManager;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->cloudIdManager = new CloudIdManager();
+ }
+
+ public function cloudIdProvider() {
+ return [
+ ['test@example.com', 'test', 'example.com'],
+ ['test@example.com/cloud', 'test', 'example.com/cloud'],
+ ['test@example.com/cloud/', 'test', 'example.com/cloud'],
+ ['test@example.com/cloud/index.php', 'test', 'example.com/cloud'],
+ ['test@example.com@example.com', 'test@example.com', 'example.com'],
+ ['test@example.com@example.com', 'test@example.com', 'example.com'],
+ ];
+ }
+
+ /**
+ * @dataProvider cloudIdProvider
+ *
+ * @param string $cloudId
+ * @param string $user
+ * @param string $remote
+ */
+ public function testResolveCloudId($cloudId, $user, $remote) {
+ $cloudId = $this->cloudIdManager->resolveCloudId($cloudId);
+
+ $this->assertEquals($user, $cloudId->getUser());
+ $this->assertEquals($remote, $cloudId->getRemote());
+ }
+
+ public function invalidCloudIdProvider() {
+ return [
+ ['example.com'],
+ ['test:foo@example.com'],
+ ['test/foo@example.com']
+ ];
+ }
+
+ /**
+ * @dataProvider invalidCloudIdProvider
+ *
+ * @param string $cloudId
+ *
+ * @expectedException \InvalidArgumentException
+ */
+ public function testInvalidCloudId($cloudId) {
+ $this->cloudIdManager->resolveCloudId($cloudId);
+ }
+
+ public function getCloudIdProvider() {
+ return [
+ ['test', 'example.com', 'test@example.com'],
+ ['test@example.com', 'example.com', 'test@example.com@example.com'],
+ ];
+ }
+
+ /**
+ * @dataProvider getCloudIdProvider
+ *
+ * @param string $user
+ * @param string $remote
+ * @param string $id
+ */
+ public function testGetCloudId($user, $remote, $id) {
+ $cloudId = $this->cloudIdManager->getCloudId($user, $remote);
+
+ $this->assertEquals($id, $cloudId->getId());
+ }
+}
diff --git a/tests/lib/Federation/CloudIdTest.php b/tests/lib/Federation/CloudIdTest.php
new file mode 100644
index 00000000000..7a6e841fb34
--- /dev/null
+++ b/tests/lib/Federation/CloudIdTest.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Federation;
+
+use OC\Federation\CloudId;
+use Test\TestCase;
+
+class CloudIdTest extends TestCase {
+ public function testGetDisplayCloudIdProvider() {
+ return [
+ ['test@example.com', 'test@example.com'],
+ ['test@http://example.com', 'test@example.com'],
+ ['test@https://example.com', 'test@example.com'],
+ ];
+ }
+
+ /**
+ * @dataProvider testGetDisplayCloudIdProvider
+ *
+ * @param string $id
+ * @param string $display
+ */
+ public function testGetDisplayCloudId($id, $display) {
+ $cloudId = new CloudId($id, '', '');
+ $this->assertEquals($display, $cloudId->getDisplayId());
+ }
+}