Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Feb 8, 2017
1 parent 1c46e97 commit dfaf999
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/private/Federation/CloudIdManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ protected function fixRemoteURL($remote) {
public function isValidCloudId($cloudId) {
return strpos($cloudId, '@') !== false;
}
}
}
99 changes: 99 additions & 0 deletions tests/lib/Federation/CloudIdManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* @copyright Copyright (c) 2017 Robin Appelman <[email protected]>
*
* @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 [
['[email protected]', 'test', 'example.com'],
['[email protected]/cloud', 'test', 'example.com/cloud'],
['[email protected]/cloud/', 'test', 'example.com/cloud'],
['[email protected]/cloud/index.php', 'test', 'example.com/cloud'],
['[email protected]@example.com', '[email protected]', 'example.com'],
['[email protected]@example.com', '[email protected]', '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:[email protected]'],
['test/[email protected]']
];
}

/**
* @dataProvider invalidCloudIdProvider
*
* @param string $cloudId
*
* @expectedException \InvalidArgumentException
*/
public function testInvalidCloudId($cloudId) {
$this->cloudIdManager->resolveCloudId($cloudId);
}

public function getCloudIdProvider() {
return [
['test', 'example.com', '[email protected]'],
['[email protected]', 'example.com', '[email protected]@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());
}
}
46 changes: 46 additions & 0 deletions tests/lib/Federation/CloudIdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @copyright Copyright (c) 2017 Robin Appelman <[email protected]>
*
* @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 [
['[email protected]', '[email protected]'],
['test@http://example.com', '[email protected]'],
['test@https://example.com', '[email protected]'],
];
}

/**
* @dataProvider testGetDisplayCloudIdProvider
*
* @param string $id
* @param string $display
*/
public function testGetDisplayCloudId($id, $display) {
$cloudId = new CloudId($id, '', '');
$this->assertEquals($display, $cloudId->getDisplayId());
}
}

0 comments on commit dfaf999

Please sign in to comment.