diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-03-18 15:22:05 +0300 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-03-21 12:29:53 +0300 |
commit | b7f7fc7241d6e04ece6a11080bf5a72938b8280a (patch) | |
tree | da5a61734352f73c074b20f941e5baeeb17665b2 /apps/federation/tests | |
parent | a6c921267e00d0fb5021e8bdbd4d202931d7a58a (diff) |
Do not create a new job when it failed to connect atm
Diffstat (limited to 'apps/federation/tests')
-rw-r--r-- | apps/federation/tests/backgroundjob/getsharedsecrettest.php | 27 | ||||
-rw-r--r-- | apps/federation/tests/backgroundjob/requestsharedsecrettest.php | 26 |
2 files changed, 39 insertions, 14 deletions
diff --git a/apps/federation/tests/backgroundjob/getsharedsecrettest.php b/apps/federation/tests/backgroundjob/getsharedsecrettest.php index 08c8677415c..25f7502741d 100644 --- a/apps/federation/tests/backgroundjob/getsharedsecrettest.php +++ b/apps/federation/tests/backgroundjob/getsharedsecrettest.php @@ -95,8 +95,9 @@ class GetSharedSecretTest extends TestCase { * @dataProvider dataTestExecute * * @param bool $isTrustedServer + * @param bool $retainBackgroundJob */ - public function testExecute($isTrustedServer) { + public function testExecute($isTrustedServer, $retainBackgroundJob) { /** @var GetSharedSecret |\PHPUnit_Framework_MockObject_MockObject $getSharedSecret */ $getSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\GetSharedSecret') ->setConstructorArgs( @@ -111,7 +112,6 @@ class GetSharedSecretTest extends TestCase { )->setMethods(['parentExecute'])->getMock(); $this->invokePrivate($getSharedSecret, 'argument', [['url' => 'url']]); - $this->jobList->expects($this->once())->method('remove'); $this->trustedServers->expects($this->once())->method('isTrustedServer') ->with('url')->willReturn($isTrustedServer); if ($isTrustedServer) { @@ -119,6 +119,12 @@ class GetSharedSecretTest extends TestCase { } else { $getSharedSecret->expects($this->never())->method('parentExecute'); } + $this->invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]); + if ($retainBackgroundJob) { + $this->jobList->expects($this->never())->method('remove'); + } else { + $this->jobList->expects($this->once())->method('remove'); + } $getSharedSecret->execute($this->jobList); @@ -126,8 +132,9 @@ class GetSharedSecretTest extends TestCase { public function dataTestExecute() { return [ - [true], - [false] + [true, true], + [true, false], + [false, false], ]; } @@ -167,12 +174,9 @@ class GetSharedSecretTest extends TestCase { $statusCode !== Http::STATUS_OK && $statusCode !== Http::STATUS_FORBIDDEN ) { - $this->jobList->expects($this->once())->method('add') - ->with('OCA\Federation\BackgroundJob\GetSharedSecret', $argument); $this->dbHandler->expects($this->never())->method('addToken'); } else { $this->dbHandler->expects($this->once())->method('addToken')->with($target, ''); - $this->jobList->expects($this->never())->method('add'); } if ($statusCode === Http::STATUS_OK) { @@ -185,6 +189,15 @@ class GetSharedSecretTest extends TestCase { } $this->invokePrivate($this->getSharedSecret, 'run', [$argument]); + if ( + $statusCode !== Http::STATUS_OK + && $statusCode !== Http::STATUS_FORBIDDEN + ) { + $this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob')); + } else { + $this->assertFalse($this->invokePrivate($this->getSharedSecret, 'retainJob')); + } + } public function dataTestRun() { diff --git a/apps/federation/tests/backgroundjob/requestsharedsecrettest.php b/apps/federation/tests/backgroundjob/requestsharedsecrettest.php index 45f79e05249..5b4a1f87a5f 100644 --- a/apps/federation/tests/backgroundjob/requestsharedsecrettest.php +++ b/apps/federation/tests/backgroundjob/requestsharedsecrettest.php @@ -75,8 +75,9 @@ class RequestSharedSecretTest extends TestCase { * @dataProvider dataTestExecute * * @param bool $isTrustedServer + * @param bool $retainBackgroundJob */ - public function testExecute($isTrustedServer) { + public function testExecute($isTrustedServer, $retainBackgroundJob) { /** @var RequestSharedSecret |\PHPUnit_Framework_MockObject_MockObject $requestSharedSecret */ $requestSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\RequestSharedSecret') ->setConstructorArgs( @@ -90,7 +91,6 @@ class RequestSharedSecretTest extends TestCase { )->setMethods(['parentExecute'])->getMock(); $this->invokePrivate($requestSharedSecret, 'argument', [['url' => 'url']]); - $this->jobList->expects($this->once())->method('remove'); $this->trustedServers->expects($this->once())->method('isTrustedServer') ->with('url')->willReturn($isTrustedServer); if ($isTrustedServer) { @@ -98,6 +98,12 @@ class RequestSharedSecretTest extends TestCase { } else { $requestSharedSecret->expects($this->never())->method('parentExecute'); } + $this->invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]); + if ($retainBackgroundJob) { + $this->jobList->expects($this->never())->method('remove'); + } else { + $this->jobList->expects($this->once())->method('remove'); + } $requestSharedSecret->execute($this->jobList); @@ -105,8 +111,9 @@ class RequestSharedSecretTest extends TestCase { public function dataTestExecute() { return [ - [true], - [false] + [true, true], + [true, false], + [false, false], ]; } @@ -146,17 +153,22 @@ class RequestSharedSecretTest extends TestCase { $statusCode !== Http::STATUS_OK && $statusCode !== Http::STATUS_FORBIDDEN ) { - $this->jobList->expects($this->once())->method('add') - ->with('OCA\Federation\BackgroundJob\RequestSharedSecret', $argument); $this->dbHandler->expects($this->never())->method('addToken'); } if ($statusCode === Http::STATUS_FORBIDDEN) { - $this->jobList->expects($this->never())->method('add'); $this->dbHandler->expects($this->once())->method('addToken')->with($target, ''); } $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]); + if ( + $statusCode !== Http::STATUS_OK + && $statusCode !== Http::STATUS_FORBIDDEN + ) { + $this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob')); + } else { + $this->assertFalse($this->invokePrivate($this->requestSharedSecret, 'retainJob')); + } } public function dataTestRun() { |