Merge the two tests into one
This commit is contained in:
parent
7de15f3125
commit
8c33f05e93
|
@ -1,151 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @author Robin Appelman <icewind@owncloud.com>
|
|
||||||
*
|
|
||||||
* @copyright Copyright (c) 2015, 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_sharing\Tests\External;
|
|
||||||
|
|
||||||
use OC\Files\Storage\StorageFactory;
|
|
||||||
use OCA\Files_Sharing\Tests\TestCase;
|
|
||||||
|
|
||||||
class Manager extends TestCase {
|
|
||||||
private $uid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \OC\Files\Mount\Manager
|
|
||||||
*/
|
|
||||||
private $mountManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \OCA\Files_Sharing\External\Manager
|
|
||||||
*/
|
|
||||||
private $instance;
|
|
||||||
|
|
||||||
public function setUp() {
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->uid = $this->getUniqueID('user');
|
|
||||||
|
|
||||||
$this->mountManager = new \OC\Files\Mount\Manager();
|
|
||||||
$this->instance = new \OCA\Files_Sharing\External\Manager(
|
|
||||||
\OC::$server->getDatabaseConnection(),
|
|
||||||
$this->mountManager,
|
|
||||||
new StorageFactory(),
|
|
||||||
$this->getMockBuilder('\OC\HTTPHelper')->disableOriginalConstructor()->getMock(),
|
|
||||||
$this->uid
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown() {
|
|
||||||
$this->instance->removeUserShares($this->uid);
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getFullPath($path) {
|
|
||||||
return '/' . $this->uid . '/files' . $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function assertMount($mountPoint) {
|
|
||||||
$mountPoint = rtrim($mountPoint, '/');
|
|
||||||
$mount = $this->mountManager->find($this->getFullPath($mountPoint));
|
|
||||||
$this->assertInstanceOf('\OCP\Files\Mount\IMountPoint', $mount);
|
|
||||||
$this->assertEquals($this->getFullPath($mountPoint), rtrim($mount->getMountPoint(), '/'));
|
|
||||||
$storage = $mount->getStorage();
|
|
||||||
$this->assertInstanceOf('\OCA\Files_Sharing\External\Storage', $storage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function assertNotMount($mountPoint) {
|
|
||||||
$mountPoint = rtrim($mountPoint, '/');
|
|
||||||
$mount = $this->mountManager->find($this->getFullPath($mountPoint));
|
|
||||||
if ($mount) {
|
|
||||||
$this->assertInstanceOf('\OCP\Files\Mount\IMountPoint', $mount);
|
|
||||||
$this->assertNotEquals($this->getFullPath($mountPoint), rtrim($mount->getMountPoint(), '/'));
|
|
||||||
} else {
|
|
||||||
$this->assertNull($mount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAddBasic() {
|
|
||||||
$this->instance->addShare('http://example.com', 'foo', 'bar', 'example', 'me', true);
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertMount('/example');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAddBasicEmptyPassword() {
|
|
||||||
$this->instance->addShare('http://example.com', 'foo', '', 'example', 'me', true);
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertMount('/example');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAddNotAcceptedShare() {
|
|
||||||
$this->instance->addShare('http://example.com', 'foo', 'bar', 'example', 'me', false);
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertNotMount('/example');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAcceptMount() {
|
|
||||||
$this->instance->addShare('http://example.com', 'foo', 'bar', 'example', 'me', false);
|
|
||||||
$open = $this->instance->getOpenShares();
|
|
||||||
$this->assertCount(1, $open);
|
|
||||||
$this->instance->acceptShare($open[0]['id']);
|
|
||||||
$this->assertEquals([], $this->instance->getOpenShares());
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertMount('/example');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDeclineMount() {
|
|
||||||
$this->instance->addShare('http://example.com', 'foo', 'bar', 'example', 'me', false);
|
|
||||||
$open = $this->instance->getOpenShares();
|
|
||||||
$this->assertCount(1, $open);
|
|
||||||
$this->instance->declineShare($open[0]['id']);
|
|
||||||
$this->assertEquals([], $this->instance->getOpenShares());
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertNotMount('/example');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSetMountPoint() {
|
|
||||||
$this->instance->addShare('http://example.com', 'foo', 'bar', 'example', 'me', true);
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertMount('/example');
|
|
||||||
$this->instance->setMountPoint($this->getFullPath('/example'), $this->getFullPath('/renamed'));
|
|
||||||
$this->mountManager->clear();
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertMount('/renamed');
|
|
||||||
$this->assertNotMount('/example');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRemoveShare() {
|
|
||||||
$this->instance->addShare('http://example.com', 'foo', 'bar', 'example', 'me', true);
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertMount('/example');
|
|
||||||
$this->instance->removeShare($this->getFullPath('/example'));
|
|
||||||
$this->mountManager->clear();
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertNotMount('/example');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRemoveShareForUser() {
|
|
||||||
$this->instance->addShare('http://example.com', 'foo', 'bar', 'example', 'me', true);
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertMount('/example');
|
|
||||||
$this->instance->removeUserShares($this->uid);
|
|
||||||
$this->mountManager->clear();
|
|
||||||
\Test_Helper::invokePrivate($this->instance, 'setupMounts');
|
|
||||||
$this->assertNotMount('/example');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
namespace OCA\Files_Sharing\Tests\External;
|
namespace OCA\Files_Sharing\Tests\External;
|
||||||
|
|
||||||
|
use OC\Files\Storage\StorageFactory;
|
||||||
use OCA\Files_Sharing\Tests\TestCase;
|
use OCA\Files_Sharing\Tests\TestCase;
|
||||||
|
|
||||||
class ManagerTest extends TestCase {
|
class ManagerTest extends TestCase {
|
||||||
|
@ -29,16 +30,20 @@ class ManagerTest extends TestCase {
|
||||||
/** @var \OCA\Files_Sharing\External\Manager **/
|
/** @var \OCA\Files_Sharing\External\Manager **/
|
||||||
private $manager;
|
private $manager;
|
||||||
|
|
||||||
|
/** @var \OC\Files\Mount\Manager */
|
||||||
|
private $mountManager;
|
||||||
|
|
||||||
private $uid;
|
private $uid;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->uid = $this->getUniqueID('user');
|
$this->uid = $this->getUniqueID('user');
|
||||||
|
$this->mountManager = new \OC\Files\Mount\Manager();
|
||||||
$this->manager = new \OCA\Files_Sharing\External\Manager(
|
$this->manager = new \OCA\Files_Sharing\External\Manager(
|
||||||
\OC::$server->getDatabaseConnection(),
|
\OC::$server->getDatabaseConnection(),
|
||||||
$this->getMockBuilder('\OC\Files\Mount\Manager')->disableOriginalConstructor()->getMock(),
|
$this->mountManager,
|
||||||
$this->getMockBuilder('\OCP\Files\Storage\IStorageFactory')->disableOriginalConstructor()->getMock(),
|
new StorageFactory(),
|
||||||
$this->getMockBuilder('\OC\HTTPHelper')->disableOriginalConstructor()->getMock(),
|
$this->getMockBuilder('\OC\HTTPHelper')->disableOriginalConstructor()->getMock(),
|
||||||
$this->uid
|
$this->uid
|
||||||
);
|
);
|
||||||
|
@ -46,7 +51,7 @@ class ManagerTest extends TestCase {
|
||||||
|
|
||||||
public function testAddShare() {
|
public function testAddShare() {
|
||||||
$shareData1 = [
|
$shareData1 = [
|
||||||
'remote' => 'localhost',
|
'remote' => 'http://localhost',
|
||||||
'token' => 'token1',
|
'token' => 'token1',
|
||||||
'password' => '',
|
'password' => '',
|
||||||
'name' => '/SharedFolder',
|
'name' => '/SharedFolder',
|
||||||
|
@ -65,6 +70,10 @@ class ManagerTest extends TestCase {
|
||||||
$this->assertCount(1, $openShares);
|
$this->assertCount(1, $openShares);
|
||||||
$this->assertExternalShareEntry($shareData1, $openShares[0], 1, '{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
$this->assertExternalShareEntry($shareData1, $openShares[0], 1, '{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
||||||
|
|
||||||
|
\Test_Helper::invokePrivate($this->manager, 'setupMounts');
|
||||||
|
$this->assertNotMount('SharedFolder');
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
||||||
|
|
||||||
// Add a second share for "user" with the same name
|
// Add a second share for "user" with the same name
|
||||||
$this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData2));
|
$this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData2));
|
||||||
$openShares = $this->manager->getOpenShares();
|
$openShares = $this->manager->getOpenShares();
|
||||||
|
@ -73,6 +82,11 @@ class ManagerTest extends TestCase {
|
||||||
// New share falls back to "-1" appendix, because the name is already taken
|
// New share falls back to "-1" appendix, because the name is already taken
|
||||||
$this->assertExternalShareEntry($shareData2, $openShares[1], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
|
$this->assertExternalShareEntry($shareData2, $openShares[1], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
|
||||||
|
|
||||||
|
\Test_Helper::invokePrivate($this->manager, 'setupMounts');
|
||||||
|
$this->assertNotMount('SharedFolder');
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
|
||||||
|
|
||||||
// Accept the first share
|
// Accept the first share
|
||||||
$this->manager->acceptShare($openShares[0]['id']);
|
$this->manager->acceptShare($openShares[0]['id']);
|
||||||
|
|
||||||
|
@ -86,6 +100,11 @@ class ManagerTest extends TestCase {
|
||||||
$this->assertCount(1, $openShares);
|
$this->assertCount(1, $openShares);
|
||||||
$this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
|
$this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
|
||||||
|
|
||||||
|
\Test_Helper::invokePrivate($this->manager, 'setupMounts');
|
||||||
|
$this->assertMount($shareData1['name']);
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
|
||||||
|
|
||||||
// Add another share for "user" with the same name
|
// Add another share for "user" with the same name
|
||||||
$this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData3));
|
$this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData3));
|
||||||
$openShares = $this->manager->getOpenShares();
|
$openShares = $this->manager->getOpenShares();
|
||||||
|
@ -94,9 +113,19 @@ class ManagerTest extends TestCase {
|
||||||
// New share falls back to the original name (no "-\d", because the name is not taken)
|
// New share falls back to the original name (no "-\d", because the name is not taken)
|
||||||
$this->assertExternalShareEntry($shareData3, $openShares[1], 3, '{{TemporaryMountPointName#' . $shareData3['name'] . '}}');
|
$this->assertExternalShareEntry($shareData3, $openShares[1], 3, '{{TemporaryMountPointName#' . $shareData3['name'] . '}}');
|
||||||
|
|
||||||
|
\Test_Helper::invokePrivate($this->manager, 'setupMounts');
|
||||||
|
$this->assertMount($shareData1['name']);
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
|
||||||
|
|
||||||
// Decline the third share
|
// Decline the third share
|
||||||
$this->manager->declineShare($openShares[1]['id']);
|
$this->manager->declineShare($openShares[1]['id']);
|
||||||
|
|
||||||
|
\Test_Helper::invokePrivate($this->manager, 'setupMounts');
|
||||||
|
$this->assertMount($shareData1['name']);
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
|
||||||
|
|
||||||
// Check remaining shares - Accepted
|
// Check remaining shares - Accepted
|
||||||
$acceptedShares = \Test_Helper::invokePrivate($this->manager, 'getShares', [true]);
|
$acceptedShares = \Test_Helper::invokePrivate($this->manager, 'getShares', [true]);
|
||||||
$this->assertCount(1, $acceptedShares);
|
$this->assertCount(1, $acceptedShares);
|
||||||
|
@ -107,8 +136,19 @@ class ManagerTest extends TestCase {
|
||||||
$this->assertCount(1, $openShares);
|
$this->assertCount(1, $openShares);
|
||||||
$this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
|
$this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1');
|
||||||
|
|
||||||
|
\Test_Helper::invokePrivate($this->manager, 'setupMounts');
|
||||||
|
$this->assertMount($shareData1['name']);
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
|
||||||
|
|
||||||
$this->manager->removeUserShares($this->uid);
|
$this->manager->removeUserShares($this->uid);
|
||||||
$this->assertEmpty(\Test_Helper::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted');
|
$this->assertEmpty(\Test_Helper::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted');
|
||||||
|
|
||||||
|
$this->mountManager->clear();
|
||||||
|
\Test_Helper::invokePrivate($this->manager, 'setupMounts');
|
||||||
|
$this->assertNotMount($shareData1['name']);
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
|
||||||
|
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,6 +165,30 @@ class ManagerTest extends TestCase {
|
||||||
$this->assertEquals($expected['accepted'], (int) $actual['accepted'], 'Asserting accept of a share #' . $share);
|
$this->assertEquals($expected['accepted'], (int) $actual['accepted'], 'Asserting accept of a share #' . $share);
|
||||||
$this->assertEquals($expected['user'], $actual['user'], 'Asserting user of a share #' . $share);
|
$this->assertEquals($expected['user'], $actual['user'], 'Asserting user of a share #' . $share);
|
||||||
$this->assertEquals($mountPoint, $actual['mountpoint'], 'Asserting mountpoint of a share #' . $share);
|
$this->assertEquals($mountPoint, $actual['mountpoint'], 'Asserting mountpoint of a share #' . $share);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function assertMount($mountPoint) {
|
||||||
|
$mountPoint = rtrim($mountPoint, '/');
|
||||||
|
$mount = $this->mountManager->find($this->getFullPath($mountPoint));
|
||||||
|
$this->assertInstanceOf('\OCA\Files_Sharing\External\Mount', $mount);
|
||||||
|
$this->assertInstanceOf('\OCP\Files\Mount\IMountPoint', $mount);
|
||||||
|
$this->assertEquals($this->getFullPath($mountPoint), rtrim($mount->getMountPoint(), '/'));
|
||||||
|
$storage = $mount->getStorage();
|
||||||
|
$this->assertInstanceOf('\OCA\Files_Sharing\External\Storage', $storage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function assertNotMount($mountPoint) {
|
||||||
|
$mountPoint = rtrim($mountPoint, '/');
|
||||||
|
$mount = $this->mountManager->find($this->getFullPath($mountPoint));
|
||||||
|
if ($mount) {
|
||||||
|
$this->assertInstanceOf('\OCP\Files\Mount\IMountPoint', $mount);
|
||||||
|
$this->assertNotEquals($this->getFullPath($mountPoint), rtrim($mount->getMountPoint(), '/'));
|
||||||
|
} else {
|
||||||
|
$this->assertNull($mount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFullPath($path) {
|
||||||
|
return '/' . $this->uid . '/files' . $path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue