summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/External
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-08-23 10:16:33 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-08-24 21:30:42 +0200
commitcae87d028dab8e5089f7f37520062826e4897752 (patch)
treec261f36119d20c22f382b298863d00810ce94ec2 /apps/files_sharing/tests/External
parenta1ed8207e9461929196340034b8c36265bd88776 (diff)
downloadnextcloud-server-cae87d028dab8e5089f7f37520062826e4897752.tar.gz
nextcloud-server-cae87d028dab8e5089f7f37520062826e4897752.zip
Fix tests
Diffstat (limited to 'apps/files_sharing/tests/External')
-rw-r--r--apps/files_sharing/tests/External/ManagerTest.php57
1 files changed, 44 insertions, 13 deletions
diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php
index 931c1fed14d..096bbe85776 100644
--- a/apps/files_sharing/tests/External/ManagerTest.php
+++ b/apps/files_sharing/tests/External/ManagerTest.php
@@ -30,6 +30,7 @@ use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider;
use OCA\Files_Sharing\Tests\TestCase;
+use OCP\Http\Client\IClientService;
use Test\Traits\UserTrait;
/**
@@ -48,8 +49,8 @@ class ManagerTest extends TestCase {
/** @var \OC\Files\Mount\Manager */
private $mountManager;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
- private $httpHelper;
+ /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
+ private $clientService;
private $uid;
@@ -66,17 +67,17 @@ class ManagerTest extends TestCase {
$this->createUser($this->uid, '');
$this->user = \OC::$server->getUserManager()->get($this->uid);
$this->mountManager = new \OC\Files\Mount\Manager();
- $this->httpHelper = $httpHelper = $this->getMockBuilder('\OC\HTTPHelper')->disableOriginalConstructor()->getMock();
+ $this->clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')
+ ->disableOriginalConstructor()->getMock();
$discoveryManager = new DiscoveryManager(
\OC::$server->getMemCacheFactory(),
\OC::$server->getHTTPClientService()
);
- /** @var \OC\HTTPHelper $httpHelper */
$this->manager = new Manager(
\OC::$server->getDatabaseConnection(),
$this->mountManager,
new StorageFactory(),
- $httpHelper,
+ $this->clientService,
\OC::$server->getNotificationManager(),
$discoveryManager,
$this->uid
@@ -132,9 +133,17 @@ class ManagerTest extends TestCase {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
- $this->httpHelper->expects($this->at(0))
+ $client = $this->getMockBuilder('OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $this->clientService->expects($this->at(0))
+ ->method('newClient')
+ ->willReturn($client);
+ $response = $this->getMockBuilder('OCP\Http\Client\IResponse')
+ ->disableOriginalConstructor()->getMock();
+ $client->expects($this->once())
->method('post')
- ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $openShares[0]['remote_id']), $this->anything());
+ ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $openShares[0]['remote_id']), $this->anything())
+ ->willReturn($response);
// Accept the first share
$this->manager->acceptShare($openShares[0]['id']);
@@ -167,9 +176,17 @@ class ManagerTest extends TestCase {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
- $this->httpHelper->expects($this->at(0))
+ $client = $this->getMockBuilder('OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $this->clientService->expects($this->at(0))
+ ->method('newClient')
+ ->willReturn($client);
+ $response = $this->getMockBuilder('OCP\Http\Client\IResponse')
+ ->disableOriginalConstructor()->getMock();
+ $client->expects($this->once())
->method('post')
- ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $openShares[1]['remote_id'] . '/decline'), $this->anything());
+ ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $openShares[1]['remote_id'] . '/decline'), $this->anything())
+ ->willReturn($response);
// Decline the third share
$this->manager->declineShare($openShares[1]['id']);
@@ -194,12 +211,26 @@ class ManagerTest extends TestCase {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
- $this->httpHelper->expects($this->at(0))
+ $client1 = $this->getMockBuilder('OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $client2 = $this->getMockBuilder('OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $this->clientService->expects($this->at(0))
+ ->method('newClient')
+ ->willReturn($client1);
+ $this->clientService->expects($this->at(1))
+ ->method('newClient')
+ ->willReturn($client2);
+ $response = $this->getMockBuilder('OCP\Http\Client\IResponse')
+ ->disableOriginalConstructor()->getMock();
+ $client1->expects($this->once())
->method('post')
- ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $openShares[0]['remote_id'] . '/decline'), $this->anything());
- $this->httpHelper->expects($this->at(1))
+ ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $openShares[0]['remote_id'] . '/decline'), $this->anything())
+ ->willReturn($response);
+ $client2->expects($this->once())
->method('post')
- ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $acceptedShares[0]['remote_id'] . '/decline'), $this->anything());
+ ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $acceptedShares[0]['remote_id'] . '/decline'), $this->anything())
+ ->willReturn($response);
$this->manager->removeUserShares($this->uid);
$this->assertEmpty(self::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted');