diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-01-16 11:37:41 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-01-18 17:53:58 +0100 |
commit | 6f6eb5b301e590cfc49cab0a43db9c032c3d4f85 (patch) | |
tree | 230685908ca0a5b9d95b7d2b3550ca924a334c50 | |
parent | 40c64e6a9c45ff571f302c75bfe64a73791e8b0e (diff) | |
download | nextcloud-server-6f6eb5b301e590cfc49cab0a43db9c032c3d4f85.tar.gz nextcloud-server-6f6eb5b301e590cfc49cab0a43db9c032c3d4f85.zip |
increase GenericProvider's test coverage
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r-- | apps/twofactor_backupcodes/tests/Unit/Activity/GenericProviderTest.php (renamed from apps/twofactor_backupcodes/tests/Unit/Activity/ProviderTest.php) | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/apps/twofactor_backupcodes/tests/Unit/Activity/ProviderTest.php b/apps/twofactor_backupcodes/tests/Unit/Activity/GenericProviderTest.php index 36e85ec1872..242c4ab4e8d 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Activity/ProviderTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Activity/GenericProviderTest.php @@ -29,12 +29,18 @@ use OCP\IL10N; use OCP\ILogger; use OCP\IURLGenerator; use OCP\L10N\IFactory; +use PHPUnit_Framework_MockObject_MockObject; use Test\TestCase; -class ProviderTest extends TestCase { +class GenericProviderTest extends TestCase { + /** @var IL10N|PHPUnit_Framework_MockObject_MockObject */ private $l10n; + + /** @var IURLGenerator|PHPUnit_Framework_MockObject_MockObject */ private $urlGenerator; + + /** @var ILogger|PHPUnit_Framework_MockObject_MockObject */ private $logger; /** @var GenericProvider */ @@ -55,7 +61,7 @@ class ProviderTest extends TestCase { $event = $this->createMock(IEvent::class); $event->expects($this->once()) ->method('getType') - ->will($this->returnValue('comments')); + ->willReturn('comments'); $this->setExpectedException(InvalidArgumentException::class); $this->provider->parse($lang, $event); @@ -63,8 +69,8 @@ class ProviderTest extends TestCase { public function subjectData() { return [ - ['twofactor_success'], - ['twofactor_failed'], + ['twofactor_success'], + ['twofactor_failed'], ]; } @@ -78,29 +84,49 @@ class ProviderTest extends TestCase { $event->expects($this->once()) ->method('getType') - ->will($this->returnValue('twofactor')); + ->willReturn('twofactor'); $this->l10n->expects($this->once()) ->method('get') ->with('core', $lang) - ->will($this->returnValue($l)); + ->willReturn($l); $this->urlGenerator->expects($this->once()) ->method('imagePath') ->with('core', 'actions/password.svg') - ->will($this->returnValue('path/to/image')); + ->willReturn('path/to/image'); $this->urlGenerator->expects($this->once()) ->method('getAbsoluteURL') ->with('path/to/image') - ->will($this->returnValue('absolute/path/to/image')); + ->willReturn('absolute/path/to/image'); $event->expects($this->once()) ->method('setIcon') ->with('absolute/path/to/image'); $event->expects($this->once()) ->method('getSubject') - ->will($this->returnValue($subject)); + ->willReturn($subject); $event->expects($this->once()) ->method('setParsedSubject'); $this->provider->parse($lang, $event); } + public function testParseInvalidSubject() { + $lang = 'ru'; + $l = $this->createMock(IL10N::class); + $event = $this->createMock(IEvent::class); + + $event->expects($this->once()) + ->method('getType') + ->willReturn('twofactor'); + $this->l10n->expects($this->once()) + ->method('get') + ->with('core', $lang) + ->willReturn($l); + $event->expects($this->once()) + ->method('getSubject') + ->willReturn('unrelated'); + + $this->expectException(InvalidArgumentException::class); + $this->provider->parse($lang, $event); + } + } |