Fix tests

This commit is contained in:
Roeland Jago Douma 2016-08-23 10:16:33 +02:00
parent a1ed8207e9
commit cae87d028d
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
1 changed files with 44 additions and 13 deletions

View File

@ -30,6 +30,7 @@ use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\Files_Sharing\External\Manager; use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider; use OCA\Files_Sharing\External\MountProvider;
use OCA\Files_Sharing\Tests\TestCase; use OCA\Files_Sharing\Tests\TestCase;
use OCP\Http\Client\IClientService;
use Test\Traits\UserTrait; use Test\Traits\UserTrait;
/** /**
@ -48,8 +49,8 @@ class ManagerTest extends TestCase {
/** @var \OC\Files\Mount\Manager */ /** @var \OC\Files\Mount\Manager */
private $mountManager; private $mountManager;
/** @var \PHPUnit_Framework_MockObject_MockObject */ /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
private $httpHelper; private $clientService;
private $uid; private $uid;
@ -66,17 +67,17 @@ class ManagerTest extends TestCase {
$this->createUser($this->uid, ''); $this->createUser($this->uid, '');
$this->user = \OC::$server->getUserManager()->get($this->uid); $this->user = \OC::$server->getUserManager()->get($this->uid);
$this->mountManager = new \OC\Files\Mount\Manager(); $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( $discoveryManager = new DiscoveryManager(
\OC::$server->getMemCacheFactory(), \OC::$server->getMemCacheFactory(),
\OC::$server->getHTTPClientService() \OC::$server->getHTTPClientService()
); );
/** @var \OC\HTTPHelper $httpHelper */
$this->manager = new Manager( $this->manager = new Manager(
\OC::$server->getDatabaseConnection(), \OC::$server->getDatabaseConnection(),
$this->mountManager, $this->mountManager,
new StorageFactory(), new StorageFactory(),
$httpHelper, $this->clientService,
\OC::$server->getNotificationManager(), \OC::$server->getNotificationManager(),
$discoveryManager, $discoveryManager,
$this->uid $this->uid
@ -132,9 +133,17 @@ class ManagerTest extends TestCase {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); $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') ->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 // Accept the first share
$this->manager->acceptShare($openShares[0]['id']); $this->manager->acceptShare($openShares[0]['id']);
@ -167,9 +176,17 @@ class ManagerTest extends TestCase {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); $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') ->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 // Decline the third share
$this->manager->declineShare($openShares[1]['id']); $this->manager->declineShare($openShares[1]['id']);
@ -194,12 +211,26 @@ class ManagerTest extends TestCase {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); $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') ->method('post')
->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $openShares[0]['remote_id'] . '/decline'), $this->anything()); ->with($this->stringStartsWith('http://localhost/ocs/v1.php/cloud/shares/' . $openShares[0]['remote_id'] . '/decline'), $this->anything())
$this->httpHelper->expects($this->at(1)) ->willReturn($response);
$client2->expects($this->once())
->method('post') ->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->manager->removeUserShares($this->uid);
$this->assertEmpty(self::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted'); $this->assertEmpty(self::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted');