summaryrefslogtreecommitdiffstats
path: root/apps/federation
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federation')
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php18
-rw-r--r--apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php28
2 files changed, 34 insertions, 12 deletions
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
index 6364ddaedff..5006ce1c2ab 100644
--- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
@@ -33,6 +33,7 @@ use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClient;
+use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\ILogger;
use OCP\IURLGenerator;
@@ -50,6 +51,9 @@ class GetSharedSecretTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject | IClient */
private $httpClient;
+ /** @var \PHPUnit_Framework_MockObject_MockObject | IClientService */
+ private $httpClientService;
+
/** @var \PHPUnit_Framework_MockObject_MockObject | IJobList */
private $jobList;
@@ -77,6 +81,7 @@ class GetSharedSecretTest extends TestCase {
public function setUp() {
parent::setUp();
+ $this->httpClientService = $this->createMock(IClientService::class);
$this->httpClient = $this->getMockBuilder(IClient::class)->getMock();
$this->jobList = $this->getMockBuilder(IJobList::class)->getMock();
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
@@ -89,9 +94,10 @@ class GetSharedSecretTest extends TestCase {
$this->discoverService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
$this->discoverService->expects($this->any())->method('discover')->willReturn([]);
+ $this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient);
$this->getSharedSecret = new GetSharedSecret(
- $this->httpClient,
+ $this->httpClientService,
$this->urlGenerator,
$this->jobList,
$this->trustedServers,
@@ -112,7 +118,7 @@ class GetSharedSecretTest extends TestCase {
$getSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\GetSharedSecret')
->setConstructorArgs(
[
- $this->httpClient,
+ $this->httpClientService,
$this->urlGenerator,
$this->jobList,
$this->trustedServers,
@@ -120,7 +126,7 @@ class GetSharedSecretTest extends TestCase {
$this->dbHandler,
$this->discoverService
]
- )->setMethods(['parentExecute'])->getMock();
+ )->setMethods(['parentExecute', 'reAddJob'])->getMock();
$this->invokePrivate($getSharedSecret, 'argument', [['url' => 'url']]);
$this->trustedServers->expects($this->once())->method('isTrustedServer')
@@ -131,10 +137,12 @@ class GetSharedSecretTest extends TestCase {
$getSharedSecret->expects($this->never())->method('parentExecute');
}
$this->invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]);
+ $this->jobList->expects($this->once())->method('remove');
if ($retainBackgroundJob) {
- $this->jobList->expects($this->never())->method('remove');
+ $getSharedSecret->expects($this->once())->method('reAddJob');
} else {
- $this->jobList->expects($this->once())->method('remove');
+ $getSharedSecret->expects($this->never())->method('reAddJob');
+
}
$getSharedSecret->execute($this->jobList);
diff --git a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
index 06da29d17fc..807ee2c000a 100644
--- a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
@@ -31,13 +31,18 @@ use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClient;
+use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
+use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
use Test\TestCase;
class RequestSharedSecretTest extends TestCase {
+ /** @var \PHPUnit_Framework_MockObject_MockObject | IClientService */
+ private $httpClientService;
+
/** @var \PHPUnit_Framework_MockObject_MockObject | IClient */
private $httpClient;
@@ -59,12 +64,16 @@ class RequestSharedSecretTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject | IDiscoveryService */
private $discoveryService;
+ /** @var \PHPUnit_Framework_MockObject_MockObject | ILogger */
+ private $logger;
+
/** @var RequestSharedSecret */
private $requestSharedSecret;
public function setUp() {
parent::setUp();
+ $this->httpClientService = $this->createMock(IClientService::class);
$this->httpClient = $this->getMockBuilder(IClient::class)->getMock();
$this->jobList = $this->getMockBuilder(IJobList::class)->getMock();
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
@@ -74,16 +83,19 @@ class RequestSharedSecretTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->response = $this->getMockBuilder(IResponse::class)->getMock();
$this->discoveryService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
+ $this->logger = $this->createMock(ILogger::class);
$this->discoveryService->expects($this->any())->method('discover')->willReturn([]);
+ $this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient);
$this->requestSharedSecret = new RequestSharedSecret(
- $this->httpClient,
+ $this->httpClientService,
$this->urlGenerator,
$this->jobList,
$this->trustedServers,
$this->dbHandler,
- $this->discoveryService
+ $this->discoveryService,
+ $this->logger
);
}
@@ -98,14 +110,15 @@ class RequestSharedSecretTest extends TestCase {
$requestSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\RequestSharedSecret')
->setConstructorArgs(
[
- $this->httpClient,
+ $this->httpClientService,
$this->urlGenerator,
$this->jobList,
$this->trustedServers,
$this->dbHandler,
- $this->discoveryService
+ $this->discoveryService,
+ $this->logger
]
- )->setMethods(['parentExecute'])->getMock();
+ )->setMethods(['parentExecute', 'reAddJob'])->getMock();
$this->invokePrivate($requestSharedSecret, 'argument', [['url' => 'url']]);
$this->trustedServers->expects($this->once())->method('isTrustedServer')
@@ -116,10 +129,11 @@ class RequestSharedSecretTest extends TestCase {
$requestSharedSecret->expects($this->never())->method('parentExecute');
}
$this->invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]);
+ $this->jobList->expects($this->once())->method('remove');
if ($retainBackgroundJob) {
- $this->jobList->expects($this->never())->method('remove');
+ $requestSharedSecret->expects($this->once())->method('reAddJob');
} else {
- $this->jobList->expects($this->once())->method('remove');
+ $requestSharedSecret->expects($this->never())->method('reAddJob');
}
$requestSharedSecret->execute($this->jobList);