@@ -19,88 +19,88 @@ |
||
| 19 | 19 | use Test\TestCase; |
| 20 | 20 | |
| 21 | 21 | class ProviderTest extends TestCase { |
| 22 | - private IFactory&MockObject $l10n; |
|
| 23 | - private IURLGenerator&MockObject $urlGenerator; |
|
| 24 | - private IManager&MockObject $activityManager; |
|
| 25 | - private Provider $provider; |
|
| 26 | - |
|
| 27 | - protected function setUp(): void { |
|
| 28 | - parent::setUp(); |
|
| 29 | - |
|
| 30 | - $this->l10n = $this->createMock(IFactory::class); |
|
| 31 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
| 32 | - $this->activityManager = $this->createMock(IManager::class); |
|
| 33 | - |
|
| 34 | - $this->provider = new Provider($this->l10n, $this->urlGenerator, $this->activityManager); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function testParseUnrelated(): void { |
|
| 38 | - $lang = 'ru'; |
|
| 39 | - $event = $this->createMock(IEvent::class); |
|
| 40 | - $event->expects($this->once()) |
|
| 41 | - ->method('getApp') |
|
| 42 | - ->willReturn('comments'); |
|
| 43 | - $this->expectException(UnknownActivityException::class); |
|
| 44 | - |
|
| 45 | - $this->provider->parse($lang, $event); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public static function subjectData(): array { |
|
| 49 | - return [ |
|
| 50 | - ['codes_generated'], |
|
| 51 | - ]; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - #[\PHPUnit\Framework\Attributes\DataProvider('subjectData')] |
|
| 55 | - public function testParse(string $subject): void { |
|
| 56 | - $lang = 'ru'; |
|
| 57 | - $event = $this->createMock(IEvent::class); |
|
| 58 | - $l = $this->createMock(IL10N::class); |
|
| 59 | - |
|
| 60 | - $event->expects($this->once()) |
|
| 61 | - ->method('getApp') |
|
| 62 | - ->willReturn('twofactor_backupcodes'); |
|
| 63 | - $this->l10n->expects($this->once()) |
|
| 64 | - ->method('get') |
|
| 65 | - ->with('twofactor_backupcodes', $lang) |
|
| 66 | - ->willReturn($l); |
|
| 67 | - $this->urlGenerator->expects($this->once()) |
|
| 68 | - ->method('imagePath') |
|
| 69 | - ->with('core', 'actions/password.svg') |
|
| 70 | - ->willReturn('path/to/image'); |
|
| 71 | - $this->urlGenerator->expects($this->once()) |
|
| 72 | - ->method('getAbsoluteURL') |
|
| 73 | - ->with('path/to/image') |
|
| 74 | - ->willReturn('absolute/path/to/image'); |
|
| 75 | - $event->expects($this->once()) |
|
| 76 | - ->method('setIcon') |
|
| 77 | - ->with('absolute/path/to/image'); |
|
| 78 | - $event->expects($this->once()) |
|
| 79 | - ->method('getSubject') |
|
| 80 | - ->willReturn($subject); |
|
| 81 | - $event->expects($this->once()) |
|
| 82 | - ->method('setParsedSubject'); |
|
| 83 | - |
|
| 84 | - $this->provider->parse($lang, $event); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function testParseInvalidSubject(): void { |
|
| 88 | - $lang = 'ru'; |
|
| 89 | - $l = $this->createMock(IL10N::class); |
|
| 90 | - $event = $this->createMock(IEvent::class); |
|
| 91 | - |
|
| 92 | - $event->expects($this->once()) |
|
| 93 | - ->method('getApp') |
|
| 94 | - ->willReturn('twofactor_backupcodes'); |
|
| 95 | - $this->l10n->expects($this->once()) |
|
| 96 | - ->method('get') |
|
| 97 | - ->with('twofactor_backupcodes', $lang) |
|
| 98 | - ->willReturn($l); |
|
| 99 | - $event->expects($this->once()) |
|
| 100 | - ->method('getSubject') |
|
| 101 | - ->willReturn('unrelated'); |
|
| 102 | - |
|
| 103 | - $this->expectException(UnknownActivityException::class); |
|
| 104 | - $this->provider->parse($lang, $event); |
|
| 105 | - } |
|
| 22 | + private IFactory&MockObject $l10n; |
|
| 23 | + private IURLGenerator&MockObject $urlGenerator; |
|
| 24 | + private IManager&MockObject $activityManager; |
|
| 25 | + private Provider $provider; |
|
| 26 | + |
|
| 27 | + protected function setUp(): void { |
|
| 28 | + parent::setUp(); |
|
| 29 | + |
|
| 30 | + $this->l10n = $this->createMock(IFactory::class); |
|
| 31 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
| 32 | + $this->activityManager = $this->createMock(IManager::class); |
|
| 33 | + |
|
| 34 | + $this->provider = new Provider($this->l10n, $this->urlGenerator, $this->activityManager); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function testParseUnrelated(): void { |
|
| 38 | + $lang = 'ru'; |
|
| 39 | + $event = $this->createMock(IEvent::class); |
|
| 40 | + $event->expects($this->once()) |
|
| 41 | + ->method('getApp') |
|
| 42 | + ->willReturn('comments'); |
|
| 43 | + $this->expectException(UnknownActivityException::class); |
|
| 44 | + |
|
| 45 | + $this->provider->parse($lang, $event); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public static function subjectData(): array { |
|
| 49 | + return [ |
|
| 50 | + ['codes_generated'], |
|
| 51 | + ]; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + #[\PHPUnit\Framework\Attributes\DataProvider('subjectData')] |
|
| 55 | + public function testParse(string $subject): void { |
|
| 56 | + $lang = 'ru'; |
|
| 57 | + $event = $this->createMock(IEvent::class); |
|
| 58 | + $l = $this->createMock(IL10N::class); |
|
| 59 | + |
|
| 60 | + $event->expects($this->once()) |
|
| 61 | + ->method('getApp') |
|
| 62 | + ->willReturn('twofactor_backupcodes'); |
|
| 63 | + $this->l10n->expects($this->once()) |
|
| 64 | + ->method('get') |
|
| 65 | + ->with('twofactor_backupcodes', $lang) |
|
| 66 | + ->willReturn($l); |
|
| 67 | + $this->urlGenerator->expects($this->once()) |
|
| 68 | + ->method('imagePath') |
|
| 69 | + ->with('core', 'actions/password.svg') |
|
| 70 | + ->willReturn('path/to/image'); |
|
| 71 | + $this->urlGenerator->expects($this->once()) |
|
| 72 | + ->method('getAbsoluteURL') |
|
| 73 | + ->with('path/to/image') |
|
| 74 | + ->willReturn('absolute/path/to/image'); |
|
| 75 | + $event->expects($this->once()) |
|
| 76 | + ->method('setIcon') |
|
| 77 | + ->with('absolute/path/to/image'); |
|
| 78 | + $event->expects($this->once()) |
|
| 79 | + ->method('getSubject') |
|
| 80 | + ->willReturn($subject); |
|
| 81 | + $event->expects($this->once()) |
|
| 82 | + ->method('setParsedSubject'); |
|
| 83 | + |
|
| 84 | + $this->provider->parse($lang, $event); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function testParseInvalidSubject(): void { |
|
| 88 | + $lang = 'ru'; |
|
| 89 | + $l = $this->createMock(IL10N::class); |
|
| 90 | + $event = $this->createMock(IEvent::class); |
|
| 91 | + |
|
| 92 | + $event->expects($this->once()) |
|
| 93 | + ->method('getApp') |
|
| 94 | + ->willReturn('twofactor_backupcodes'); |
|
| 95 | + $this->l10n->expects($this->once()) |
|
| 96 | + ->method('get') |
|
| 97 | + ->with('twofactor_backupcodes', $lang) |
|
| 98 | + ->willReturn($l); |
|
| 99 | + $event->expects($this->once()) |
|
| 100 | + ->method('getSubject') |
|
| 101 | + ->willReturn('unrelated'); |
|
| 102 | + |
|
| 103 | + $this->expectException(UnknownActivityException::class); |
|
| 104 | + $this->provider->parse($lang, $event); |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -15,88 +15,88 @@ |
||
| 15 | 15 | |
| 16 | 16 | class RequestRemoteAddressTest extends \Test\TestCase { |
| 17 | 17 | |
| 18 | - protected IRequest&MockObject $request; |
|
| 19 | - |
|
| 20 | - protected function getL10NMock(): IL10N&MockObject { |
|
| 21 | - $l = $this->createMock(IL10N::class); |
|
| 22 | - $l->expects($this->any()) |
|
| 23 | - ->method('t') |
|
| 24 | - ->willReturnCallback(function ($string, $args) { |
|
| 25 | - return sprintf($string, $args); |
|
| 26 | - }); |
|
| 27 | - return $l; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - protected function setUp(): void { |
|
| 31 | - parent::setUp(); |
|
| 32 | - |
|
| 33 | - $this->request = $this->createMock(IRequest::class); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public static function dataExecuteCheckIPv4(): array { |
|
| 37 | - return [ |
|
| 38 | - ['127.0.0.1/32', '127.0.0.1', true], |
|
| 39 | - ['127.0.0.1/32', '127.0.0.0', false], |
|
| 40 | - ['127.0.0.1/31', '127.0.0.0', true], |
|
| 41 | - ['127.0.0.1/32', '127.0.0.2', false], |
|
| 42 | - ['127.0.0.1/31', '127.0.0.2', false], |
|
| 43 | - ['127.0.0.1/30', '127.0.0.2', true], |
|
| 44 | - ]; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')] |
|
| 48 | - public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void { |
|
| 49 | - $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); |
|
| 50 | - |
|
| 51 | - $this->request->expects($this->once()) |
|
| 52 | - ->method('getRemoteAddress') |
|
| 53 | - ->willReturn($ip); |
|
| 54 | - |
|
| 55 | - $this->assertEquals($expected, $check->executeCheck('matchesIPv4', $value)); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')] |
|
| 59 | - public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void { |
|
| 60 | - $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); |
|
| 61 | - |
|
| 62 | - $this->request->expects($this->once()) |
|
| 63 | - ->method('getRemoteAddress') |
|
| 64 | - ->willReturn($ip); |
|
| 65 | - |
|
| 66 | - $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv4', $value)); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public static function dataExecuteCheckIPv6(): array { |
|
| 70 | - return [ |
|
| 71 | - ['::1/128', '::1', true], |
|
| 72 | - ['::2/128', '::3', false], |
|
| 73 | - ['::2/127', '::3', true], |
|
| 74 | - ['::1/128', '::2', false], |
|
| 75 | - ['::1/127', '::2', false], |
|
| 76 | - ['::1/126', '::2', true], |
|
| 77 | - ['1234::1/127', '1234::', true], |
|
| 78 | - ]; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')] |
|
| 82 | - public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void { |
|
| 83 | - $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); |
|
| 84 | - |
|
| 85 | - $this->request->expects($this->once()) |
|
| 86 | - ->method('getRemoteAddress') |
|
| 87 | - ->willReturn($ip); |
|
| 88 | - |
|
| 89 | - $this->assertEquals($expected, $check->executeCheck('matchesIPv6', $value)); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')] |
|
| 93 | - public function testExecuteCheckNotMatchesIPv6(string $value, string $ip, bool $expected): void { |
|
| 94 | - $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); |
|
| 95 | - |
|
| 96 | - $this->request->expects($this->once()) |
|
| 97 | - ->method('getRemoteAddress') |
|
| 98 | - ->willReturn($ip); |
|
| 99 | - |
|
| 100 | - $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv6', $value)); |
|
| 101 | - } |
|
| 18 | + protected IRequest&MockObject $request; |
|
| 19 | + |
|
| 20 | + protected function getL10NMock(): IL10N&MockObject { |
|
| 21 | + $l = $this->createMock(IL10N::class); |
|
| 22 | + $l->expects($this->any()) |
|
| 23 | + ->method('t') |
|
| 24 | + ->willReturnCallback(function ($string, $args) { |
|
| 25 | + return sprintf($string, $args); |
|
| 26 | + }); |
|
| 27 | + return $l; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + protected function setUp(): void { |
|
| 31 | + parent::setUp(); |
|
| 32 | + |
|
| 33 | + $this->request = $this->createMock(IRequest::class); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public static function dataExecuteCheckIPv4(): array { |
|
| 37 | + return [ |
|
| 38 | + ['127.0.0.1/32', '127.0.0.1', true], |
|
| 39 | + ['127.0.0.1/32', '127.0.0.0', false], |
|
| 40 | + ['127.0.0.1/31', '127.0.0.0', true], |
|
| 41 | + ['127.0.0.1/32', '127.0.0.2', false], |
|
| 42 | + ['127.0.0.1/31', '127.0.0.2', false], |
|
| 43 | + ['127.0.0.1/30', '127.0.0.2', true], |
|
| 44 | + ]; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')] |
|
| 48 | + public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void { |
|
| 49 | + $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); |
|
| 50 | + |
|
| 51 | + $this->request->expects($this->once()) |
|
| 52 | + ->method('getRemoteAddress') |
|
| 53 | + ->willReturn($ip); |
|
| 54 | + |
|
| 55 | + $this->assertEquals($expected, $check->executeCheck('matchesIPv4', $value)); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')] |
|
| 59 | + public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void { |
|
| 60 | + $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); |
|
| 61 | + |
|
| 62 | + $this->request->expects($this->once()) |
|
| 63 | + ->method('getRemoteAddress') |
|
| 64 | + ->willReturn($ip); |
|
| 65 | + |
|
| 66 | + $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv4', $value)); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public static function dataExecuteCheckIPv6(): array { |
|
| 70 | + return [ |
|
| 71 | + ['::1/128', '::1', true], |
|
| 72 | + ['::2/128', '::3', false], |
|
| 73 | + ['::2/127', '::3', true], |
|
| 74 | + ['::1/128', '::2', false], |
|
| 75 | + ['::1/127', '::2', false], |
|
| 76 | + ['::1/126', '::2', true], |
|
| 77 | + ['1234::1/127', '1234::', true], |
|
| 78 | + ]; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')] |
|
| 82 | + public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void { |
|
| 83 | + $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); |
|
| 84 | + |
|
| 85 | + $this->request->expects($this->once()) |
|
| 86 | + ->method('getRemoteAddress') |
|
| 87 | + ->willReturn($ip); |
|
| 88 | + |
|
| 89 | + $this->assertEquals($expected, $check->executeCheck('matchesIPv6', $value)); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')] |
|
| 93 | + public function testExecuteCheckNotMatchesIPv6(string $value, string $ip, bool $expected): void { |
|
| 94 | + $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); |
|
| 95 | + |
|
| 96 | + $this->request->expects($this->once()) |
|
| 97 | + ->method('getRemoteAddress') |
|
| 98 | + ->willReturn($ip); |
|
| 99 | + |
|
| 100 | + $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv6', $value)); |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -16,79 +16,79 @@ |
||
| 16 | 16 | use Test\TestCase; |
| 17 | 17 | |
| 18 | 18 | class RequestUserAgentTest extends TestCase { |
| 19 | - protected IRequest&MockObject $request; |
|
| 20 | - protected RequestUserAgent $check; |
|
| 19 | + protected IRequest&MockObject $request; |
|
| 20 | + protected RequestUserAgent $check; |
|
| 21 | 21 | |
| 22 | - protected function setUp(): void { |
|
| 23 | - parent::setUp(); |
|
| 22 | + protected function setUp(): void { |
|
| 23 | + parent::setUp(); |
|
| 24 | 24 | |
| 25 | - $this->request = $this->createMock(IRequest::class); |
|
| 26 | - /** @var IL10N&MockObject $l */ |
|
| 27 | - $l = $this->createMock(IL10N::class); |
|
| 28 | - $l->expects($this->any()) |
|
| 29 | - ->method('t') |
|
| 30 | - ->willReturnCallback(function ($string, $args) { |
|
| 31 | - return sprintf($string, $args); |
|
| 32 | - }); |
|
| 25 | + $this->request = $this->createMock(IRequest::class); |
|
| 26 | + /** @var IL10N&MockObject $l */ |
|
| 27 | + $l = $this->createMock(IL10N::class); |
|
| 28 | + $l->expects($this->any()) |
|
| 29 | + ->method('t') |
|
| 30 | + ->willReturnCallback(function ($string, $args) { |
|
| 31 | + return sprintf($string, $args); |
|
| 32 | + }); |
|
| 33 | 33 | |
| 34 | - $this->check = new RequestUserAgent($l, $this->request); |
|
| 35 | - } |
|
| 34 | + $this->check = new RequestUserAgent($l, $this->request); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public static function dataExecuteCheck(): array { |
|
| 38 | - return [ |
|
| 39 | - ['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], |
|
| 40 | - ['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], |
|
| 41 | - ['is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', false], |
|
| 42 | - ['is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false], |
|
| 43 | - ['is', 'android', 'Filelink for *cloud/2.2.0', false], |
|
| 44 | - ['!is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false], |
|
| 45 | - ['!is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true], |
|
| 46 | - ['!is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', true], |
|
| 47 | - ['!is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true], |
|
| 48 | - ['!is', 'android', 'Filelink for *cloud/2.2.0', true], |
|
| 37 | + public static function dataExecuteCheck(): array { |
|
| 38 | + return [ |
|
| 39 | + ['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], |
|
| 40 | + ['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], |
|
| 41 | + ['is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', false], |
|
| 42 | + ['is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false], |
|
| 43 | + ['is', 'android', 'Filelink for *cloud/2.2.0', false], |
|
| 44 | + ['!is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false], |
|
| 45 | + ['!is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true], |
|
| 46 | + ['!is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', true], |
|
| 47 | + ['!is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true], |
|
| 48 | + ['!is', 'android', 'Filelink for *cloud/2.2.0', true], |
|
| 49 | 49 | |
| 50 | - ['is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false], |
|
| 51 | - ['is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true], |
|
| 52 | - ['is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', false], |
|
| 53 | - ['is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false], |
|
| 54 | - ['is', 'ios', 'Filelink for *cloud/2.2.0', false], |
|
| 55 | - ['!is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], |
|
| 56 | - ['!is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], |
|
| 57 | - ['!is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', true], |
|
| 58 | - ['!is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true], |
|
| 59 | - ['!is', 'ios', 'Filelink for *cloud/2.2.0', true], |
|
| 50 | + ['is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false], |
|
| 51 | + ['is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true], |
|
| 52 | + ['is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', false], |
|
| 53 | + ['is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false], |
|
| 54 | + ['is', 'ios', 'Filelink for *cloud/2.2.0', false], |
|
| 55 | + ['!is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], |
|
| 56 | + ['!is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], |
|
| 57 | + ['!is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', true], |
|
| 58 | + ['!is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true], |
|
| 59 | + ['!is', 'ios', 'Filelink for *cloud/2.2.0', true], |
|
| 60 | 60 | |
| 61 | - ['is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false], |
|
| 62 | - ['is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], |
|
| 63 | - ['is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', true], |
|
| 64 | - ['is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false], |
|
| 65 | - ['is', 'desktop', 'Filelink for *cloud/2.2.0', false], |
|
| 66 | - ['!is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], |
|
| 67 | - ['!is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true], |
|
| 68 | - ['!is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', false], |
|
| 69 | - ['!is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true], |
|
| 70 | - ['!is', 'desktop', 'Filelink for *cloud/2.2.0', true], |
|
| 61 | + ['is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false], |
|
| 62 | + ['is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], |
|
| 63 | + ['is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', true], |
|
| 64 | + ['is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false], |
|
| 65 | + ['is', 'desktop', 'Filelink for *cloud/2.2.0', false], |
|
| 66 | + ['!is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], |
|
| 67 | + ['!is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true], |
|
| 68 | + ['!is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', false], |
|
| 69 | + ['!is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true], |
|
| 70 | + ['!is', 'desktop', 'Filelink for *cloud/2.2.0', true], |
|
| 71 | 71 | |
| 72 | - ['is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false], |
|
| 73 | - ['is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], |
|
| 74 | - ['is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', false], |
|
| 75 | - ['is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true], |
|
| 76 | - ['is', 'mail', 'Filelink for *cloud/2.2.0', true], |
|
| 77 | - ['!is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], |
|
| 78 | - ['!is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true], |
|
| 79 | - ['!is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', true], |
|
| 80 | - ['!is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false], |
|
| 81 | - ['!is', 'mail', 'Filelink for *cloud/2.2.0', false], |
|
| 82 | - ]; |
|
| 83 | - } |
|
| 72 | + ['is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false], |
|
| 73 | + ['is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], |
|
| 74 | + ['is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', false], |
|
| 75 | + ['is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true], |
|
| 76 | + ['is', 'mail', 'Filelink for *cloud/2.2.0', true], |
|
| 77 | + ['!is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], |
|
| 78 | + ['!is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true], |
|
| 79 | + ['!is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', true], |
|
| 80 | + ['!is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false], |
|
| 81 | + ['!is', 'mail', 'Filelink for *cloud/2.2.0', false], |
|
| 82 | + ]; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] |
|
| 86 | - public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { |
|
| 87 | - $this->request->expects($this->once()) |
|
| 88 | - ->method('getHeader') |
|
| 89 | - ->willReturn($actualValue); |
|
| 85 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] |
|
| 86 | + public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { |
|
| 87 | + $this->request->expects($this->once()) |
|
| 88 | + ->method('getHeader') |
|
| 89 | + ->willReturn($actualValue); |
|
| 90 | 90 | |
| 91 | - /** @var AbstractStringCheck $check */ |
|
| 92 | - $this->assertEquals($expected, $this->check->executeCheck($operation, $checkValue)); |
|
| 93 | - } |
|
| 91 | + /** @var AbstractStringCheck $check */ |
|
| 92 | + $this->assertEquals($expected, $this->check->executeCheck($operation, $checkValue)); |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -13,105 +13,105 @@ |
||
| 13 | 13 | use PHPUnit\Framework\MockObject\MockObject; |
| 14 | 14 | |
| 15 | 15 | class AbstractStringCheckTest extends \Test\TestCase { |
| 16 | - protected function getCheckMock(): AbstractStringCheck|MockObject { |
|
| 17 | - $l = $this->getMockBuilder(IL10N::class) |
|
| 18 | - ->disableOriginalConstructor() |
|
| 19 | - ->getMock(); |
|
| 20 | - $l->expects($this->any()) |
|
| 21 | - ->method('t') |
|
| 22 | - ->willReturnCallback(function ($string, $args) { |
|
| 23 | - return sprintf($string, $args); |
|
| 24 | - }); |
|
| 25 | - |
|
| 26 | - $check = $this->getMockBuilder(AbstractStringCheck::class) |
|
| 27 | - ->setConstructorArgs([ |
|
| 28 | - $l, |
|
| 29 | - ]) |
|
| 30 | - ->onlyMethods([ |
|
| 31 | - 'executeCheck', |
|
| 32 | - 'getActualValue', |
|
| 33 | - ]) |
|
| 34 | - ->getMock(); |
|
| 35 | - |
|
| 36 | - return $check; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public static function dataExecuteStringCheck(): array { |
|
| 40 | - return [ |
|
| 41 | - ['is', 'same', 'same', true], |
|
| 42 | - ['is', 'different', 'not the same', false], |
|
| 43 | - ['!is', 'same', 'same', false], |
|
| 44 | - ['!is', 'different', 'not the same', true], |
|
| 45 | - |
|
| 46 | - ['matches', '/match/', 'match', true], |
|
| 47 | - ['matches', '/different/', 'not the same', false], |
|
| 48 | - ['!matches', '/match/', 'match', false], |
|
| 49 | - ['!matches', '/different/', 'not the same', true], |
|
| 50 | - ]; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteStringCheck')] |
|
| 54 | - public function testExecuteStringCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { |
|
| 55 | - $check = $this->getCheckMock(); |
|
| 56 | - |
|
| 57 | - /** @var AbstractStringCheck $check */ |
|
| 58 | - $this->assertEquals($expected, $this->invokePrivate($check, 'executeStringCheck', [$operation, $checkValue, $actualValue])); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public static function dataValidateCheck(): array { |
|
| 62 | - return [ |
|
| 63 | - ['is', '/Invalid(Regex/'], |
|
| 64 | - ['!is', '/Invalid(Regex/'], |
|
| 65 | - ['matches', '/Valid(Regex)/'], |
|
| 66 | - ['!matches', '/Valid(Regex)/'], |
|
| 67 | - ]; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')] |
|
| 71 | - public function testValidateCheck(string $operator, string $value): void { |
|
| 72 | - $check = $this->getCheckMock(); |
|
| 73 | - |
|
| 74 | - /** @var AbstractStringCheck $check */ |
|
| 75 | - $check->validateCheck($operator, $value); |
|
| 76 | - |
|
| 77 | - $this->addToAssertionCount(1); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public static function dataValidateCheckInvalid(): array { |
|
| 81 | - return [ |
|
| 82 | - ['!!is', '', 1, 'The given operator is invalid'], |
|
| 83 | - ['less', '', 1, 'The given operator is invalid'], |
|
| 84 | - ['matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'], |
|
| 85 | - ['!matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'], |
|
| 86 | - ]; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')] |
|
| 90 | - public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { |
|
| 91 | - $check = $this->getCheckMock(); |
|
| 92 | - |
|
| 93 | - try { |
|
| 94 | - /** @var AbstractStringCheck $check */ |
|
| 95 | - $check->validateCheck($operator, $value); |
|
| 96 | - } catch (\UnexpectedValueException $e) { |
|
| 97 | - $this->assertEquals($exceptionCode, $e->getCode()); |
|
| 98 | - $this->assertEquals($exceptionMessage, $e->getMessage()); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public static function dataMatch(): array { |
|
| 103 | - return [ |
|
| 104 | - ['/valid/', 'valid', [], true], |
|
| 105 | - ['/valid/', 'valid', [md5('/valid/') => [md5('valid') => false]], false], // Cache hit |
|
| 106 | - ]; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataMatch')] |
|
| 110 | - public function testMatch(string $pattern, string $subject, array $matches, bool $expected): void { |
|
| 111 | - $check = $this->getCheckMock(); |
|
| 112 | - |
|
| 113 | - $this->invokePrivate($check, 'matches', [$matches]); |
|
| 114 | - |
|
| 115 | - $this->assertEquals($expected, $this->invokePrivate($check, 'match', [$pattern, $subject])); |
|
| 116 | - } |
|
| 16 | + protected function getCheckMock(): AbstractStringCheck|MockObject { |
|
| 17 | + $l = $this->getMockBuilder(IL10N::class) |
|
| 18 | + ->disableOriginalConstructor() |
|
| 19 | + ->getMock(); |
|
| 20 | + $l->expects($this->any()) |
|
| 21 | + ->method('t') |
|
| 22 | + ->willReturnCallback(function ($string, $args) { |
|
| 23 | + return sprintf($string, $args); |
|
| 24 | + }); |
|
| 25 | + |
|
| 26 | + $check = $this->getMockBuilder(AbstractStringCheck::class) |
|
| 27 | + ->setConstructorArgs([ |
|
| 28 | + $l, |
|
| 29 | + ]) |
|
| 30 | + ->onlyMethods([ |
|
| 31 | + 'executeCheck', |
|
| 32 | + 'getActualValue', |
|
| 33 | + ]) |
|
| 34 | + ->getMock(); |
|
| 35 | + |
|
| 36 | + return $check; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public static function dataExecuteStringCheck(): array { |
|
| 40 | + return [ |
|
| 41 | + ['is', 'same', 'same', true], |
|
| 42 | + ['is', 'different', 'not the same', false], |
|
| 43 | + ['!is', 'same', 'same', false], |
|
| 44 | + ['!is', 'different', 'not the same', true], |
|
| 45 | + |
|
| 46 | + ['matches', '/match/', 'match', true], |
|
| 47 | + ['matches', '/different/', 'not the same', false], |
|
| 48 | + ['!matches', '/match/', 'match', false], |
|
| 49 | + ['!matches', '/different/', 'not the same', true], |
|
| 50 | + ]; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteStringCheck')] |
|
| 54 | + public function testExecuteStringCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { |
|
| 55 | + $check = $this->getCheckMock(); |
|
| 56 | + |
|
| 57 | + /** @var AbstractStringCheck $check */ |
|
| 58 | + $this->assertEquals($expected, $this->invokePrivate($check, 'executeStringCheck', [$operation, $checkValue, $actualValue])); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public static function dataValidateCheck(): array { |
|
| 62 | + return [ |
|
| 63 | + ['is', '/Invalid(Regex/'], |
|
| 64 | + ['!is', '/Invalid(Regex/'], |
|
| 65 | + ['matches', '/Valid(Regex)/'], |
|
| 66 | + ['!matches', '/Valid(Regex)/'], |
|
| 67 | + ]; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')] |
|
| 71 | + public function testValidateCheck(string $operator, string $value): void { |
|
| 72 | + $check = $this->getCheckMock(); |
|
| 73 | + |
|
| 74 | + /** @var AbstractStringCheck $check */ |
|
| 75 | + $check->validateCheck($operator, $value); |
|
| 76 | + |
|
| 77 | + $this->addToAssertionCount(1); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public static function dataValidateCheckInvalid(): array { |
|
| 81 | + return [ |
|
| 82 | + ['!!is', '', 1, 'The given operator is invalid'], |
|
| 83 | + ['less', '', 1, 'The given operator is invalid'], |
|
| 84 | + ['matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'], |
|
| 85 | + ['!matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'], |
|
| 86 | + ]; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')] |
|
| 90 | + public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { |
|
| 91 | + $check = $this->getCheckMock(); |
|
| 92 | + |
|
| 93 | + try { |
|
| 94 | + /** @var AbstractStringCheck $check */ |
|
| 95 | + $check->validateCheck($operator, $value); |
|
| 96 | + } catch (\UnexpectedValueException $e) { |
|
| 97 | + $this->assertEquals($exceptionCode, $e->getCode()); |
|
| 98 | + $this->assertEquals($exceptionMessage, $e->getMessage()); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public static function dataMatch(): array { |
|
| 103 | + return [ |
|
| 104 | + ['/valid/', 'valid', [], true], |
|
| 105 | + ['/valid/', 'valid', [md5('/valid/') => [md5('valid') => false]], false], // Cache hit |
|
| 106 | + ]; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataMatch')] |
|
| 110 | + public function testMatch(string $pattern, string $subject, array $matches, bool $expected): void { |
|
| 111 | + $check = $this->getCheckMock(); |
|
| 112 | + |
|
| 113 | + $this->invokePrivate($check, 'matches', [$matches]); |
|
| 114 | + |
|
| 115 | + $this->assertEquals($expected, $this->invokePrivate($check, 'match', [$pattern, $subject])); |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -14,113 +14,113 @@ |
||
| 14 | 14 | use PHPUnit\Framework\MockObject\MockObject; |
| 15 | 15 | |
| 16 | 16 | class RequestTimeTest extends \Test\TestCase { |
| 17 | - protected ITimeFactory&MockObject $timeFactory; |
|
| 18 | - |
|
| 19 | - protected function getL10NMock(): IL10N&MockObject { |
|
| 20 | - $l = $this->createMock(IL10N::class); |
|
| 21 | - $l->expects($this->any()) |
|
| 22 | - ->method('t') |
|
| 23 | - ->willReturnCallback(function ($string, $args) { |
|
| 24 | - return sprintf($string, $args); |
|
| 25 | - }); |
|
| 26 | - return $l; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - protected function setUp(): void { |
|
| 30 | - parent::setUp(); |
|
| 31 | - |
|
| 32 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public static function dataExecuteCheck(): array { |
|
| 36 | - return [ |
|
| 37 | - [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467870105, false], // 2016-07-07T07:41:45+02:00 |
|
| 38 | - [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467873705, true], // 2016-07-07T08:41:45+02:00 |
|
| 39 | - [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467902505, true], // 2016-07-07T16:41:45+02:00 |
|
| 40 | - [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467906105, false], // 2016-07-07T17:41:45+02:00 |
|
| 41 | - [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467870105, true], // 2016-07-07T07:41:45+02:00 |
|
| 42 | - [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467873705, false], // 2016-07-07T08:41:45+02:00 |
|
| 43 | - [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467902505, false], // 2016-07-07T16:41:45+02:00 |
|
| 44 | - [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467906105, true], // 2016-07-07T17:41:45+02:00 |
|
| 45 | - |
|
| 46 | - [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467843105, false], // 2016-07-07T07:41:45+09:30 |
|
| 47 | - [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467846705, true], // 2016-07-07T08:41:45+09:30 |
|
| 48 | - [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467875505, true], // 2016-07-07T16:41:45+09:30 |
|
| 49 | - [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467879105, false], // 2016-07-07T17:41:45+09:30 |
|
| 50 | - [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467843105, true], // 2016-07-07T07:41:45+09:30 |
|
| 51 | - [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467846705, false], // 2016-07-07T08:41:45+09:30 |
|
| 52 | - [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467875505, false], // 2016-07-07T16:41:45+09:30 |
|
| 53 | - [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467879105, true], // 2016-07-07T17:41:45+09:30 |
|
| 54 | - |
|
| 55 | - [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467916905, false], // 2016-07-07T07:41:45-11:00 |
|
| 56 | - [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467920505, true], // 2016-07-07T08:41:45-11:00 |
|
| 57 | - [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467949305, true], // 2016-07-07T16:41:45-11:00 |
|
| 58 | - [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467952905, false], // 2016-07-07T17:41:45-11:00 |
|
| 59 | - [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467916905, true], // 2016-07-07T07:41:45-11:00 |
|
| 60 | - [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467920505, false], // 2016-07-07T08:41:45-11:00 |
|
| 61 | - [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467949305, false], // 2016-07-07T16:41:45-11:00 |
|
| 62 | - [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467952905, true], // 2016-07-07T17:41:45-11:00 |
|
| 63 | - ]; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] |
|
| 67 | - public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void { |
|
| 68 | - $check = new RequestTime($this->getL10NMock(), $this->timeFactory); |
|
| 69 | - |
|
| 70 | - $this->timeFactory->expects($this->once()) |
|
| 71 | - ->method('getTime') |
|
| 72 | - ->willReturn($timestamp); |
|
| 73 | - |
|
| 74 | - $this->assertEquals($expected, $check->executeCheck('in', $value)); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] |
|
| 78 | - public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void { |
|
| 79 | - $check = new RequestTime($this->getL10NMock(), $this->timeFactory); |
|
| 80 | - |
|
| 81 | - $this->timeFactory->expects($this->once()) |
|
| 82 | - ->method('getTime') |
|
| 83 | - ->willReturn($timestamp); |
|
| 84 | - |
|
| 85 | - $this->assertEquals(!$expected, $check->executeCheck('!in', $value)); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public static function dataValidateCheck(): array { |
|
| 89 | - return [ |
|
| 90 | - ['in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]'], |
|
| 91 | - ['!in', '["08:00 Europe/Berlin","17:00 America/North_Dakota/Beulah"]'], |
|
| 92 | - ['in', '["08:00 America/Port-au-Prince","17:00 America/Argentina/San_Luis"]'], |
|
| 93 | - ]; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')] |
|
| 97 | - public function testValidateCheck(string $operator, string $value): void { |
|
| 98 | - $check = new RequestTime($this->getL10NMock(), $this->timeFactory); |
|
| 99 | - $check->validateCheck($operator, $value); |
|
| 100 | - $this->addToAssertionCount(1); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public static function dataValidateCheckInvalid(): array { |
|
| 104 | - return [ |
|
| 105 | - ['!!in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]', 1, 'The given operator is invalid'], |
|
| 106 | - ['in', '["28:00 Europe/Berlin","17:00 Europe/Berlin"]', 2, 'The given time span is invalid'], |
|
| 107 | - ['in', '["08:00 Europe/Berlin","27:00 Europe/Berlin"]', 2, 'The given time span is invalid'], |
|
| 108 | - ['in', '["08:00 Europa/Berlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'], |
|
| 109 | - ['in', '["08:00 Europe/Berlin","17:00 Europa/Berlin"]', 4, 'The given end time is invalid'], |
|
| 110 | - ['in', '["08:00 Europe/Bearlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'], |
|
| 111 | - ['in', '["08:00 Europe/Berlin","17:00 Europe/Bearlin"]', 4, 'The given end time is invalid'], |
|
| 112 | - ]; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')] |
|
| 116 | - public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { |
|
| 117 | - $check = new RequestTime($this->getL10NMock(), $this->timeFactory); |
|
| 118 | - |
|
| 119 | - try { |
|
| 120 | - $check->validateCheck($operator, $value); |
|
| 121 | - } catch (\UnexpectedValueException $e) { |
|
| 122 | - $this->assertEquals($exceptionCode, $e->getCode()); |
|
| 123 | - $this->assertEquals($exceptionMessage, $e->getMessage()); |
|
| 124 | - } |
|
| 125 | - } |
|
| 17 | + protected ITimeFactory&MockObject $timeFactory; |
|
| 18 | + |
|
| 19 | + protected function getL10NMock(): IL10N&MockObject { |
|
| 20 | + $l = $this->createMock(IL10N::class); |
|
| 21 | + $l->expects($this->any()) |
|
| 22 | + ->method('t') |
|
| 23 | + ->willReturnCallback(function ($string, $args) { |
|
| 24 | + return sprintf($string, $args); |
|
| 25 | + }); |
|
| 26 | + return $l; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + protected function setUp(): void { |
|
| 30 | + parent::setUp(); |
|
| 31 | + |
|
| 32 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public static function dataExecuteCheck(): array { |
|
| 36 | + return [ |
|
| 37 | + [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467870105, false], // 2016-07-07T07:41:45+02:00 |
|
| 38 | + [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467873705, true], // 2016-07-07T08:41:45+02:00 |
|
| 39 | + [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467902505, true], // 2016-07-07T16:41:45+02:00 |
|
| 40 | + [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467906105, false], // 2016-07-07T17:41:45+02:00 |
|
| 41 | + [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467870105, true], // 2016-07-07T07:41:45+02:00 |
|
| 42 | + [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467873705, false], // 2016-07-07T08:41:45+02:00 |
|
| 43 | + [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467902505, false], // 2016-07-07T16:41:45+02:00 |
|
| 44 | + [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467906105, true], // 2016-07-07T17:41:45+02:00 |
|
| 45 | + |
|
| 46 | + [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467843105, false], // 2016-07-07T07:41:45+09:30 |
|
| 47 | + [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467846705, true], // 2016-07-07T08:41:45+09:30 |
|
| 48 | + [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467875505, true], // 2016-07-07T16:41:45+09:30 |
|
| 49 | + [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467879105, false], // 2016-07-07T17:41:45+09:30 |
|
| 50 | + [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467843105, true], // 2016-07-07T07:41:45+09:30 |
|
| 51 | + [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467846705, false], // 2016-07-07T08:41:45+09:30 |
|
| 52 | + [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467875505, false], // 2016-07-07T16:41:45+09:30 |
|
| 53 | + [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467879105, true], // 2016-07-07T17:41:45+09:30 |
|
| 54 | + |
|
| 55 | + [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467916905, false], // 2016-07-07T07:41:45-11:00 |
|
| 56 | + [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467920505, true], // 2016-07-07T08:41:45-11:00 |
|
| 57 | + [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467949305, true], // 2016-07-07T16:41:45-11:00 |
|
| 58 | + [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467952905, false], // 2016-07-07T17:41:45-11:00 |
|
| 59 | + [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467916905, true], // 2016-07-07T07:41:45-11:00 |
|
| 60 | + [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467920505, false], // 2016-07-07T08:41:45-11:00 |
|
| 61 | + [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467949305, false], // 2016-07-07T16:41:45-11:00 |
|
| 62 | + [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467952905, true], // 2016-07-07T17:41:45-11:00 |
|
| 63 | + ]; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] |
|
| 67 | + public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void { |
|
| 68 | + $check = new RequestTime($this->getL10NMock(), $this->timeFactory); |
|
| 69 | + |
|
| 70 | + $this->timeFactory->expects($this->once()) |
|
| 71 | + ->method('getTime') |
|
| 72 | + ->willReturn($timestamp); |
|
| 73 | + |
|
| 74 | + $this->assertEquals($expected, $check->executeCheck('in', $value)); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] |
|
| 78 | + public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void { |
|
| 79 | + $check = new RequestTime($this->getL10NMock(), $this->timeFactory); |
|
| 80 | + |
|
| 81 | + $this->timeFactory->expects($this->once()) |
|
| 82 | + ->method('getTime') |
|
| 83 | + ->willReturn($timestamp); |
|
| 84 | + |
|
| 85 | + $this->assertEquals(!$expected, $check->executeCheck('!in', $value)); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public static function dataValidateCheck(): array { |
|
| 89 | + return [ |
|
| 90 | + ['in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]'], |
|
| 91 | + ['!in', '["08:00 Europe/Berlin","17:00 America/North_Dakota/Beulah"]'], |
|
| 92 | + ['in', '["08:00 America/Port-au-Prince","17:00 America/Argentina/San_Luis"]'], |
|
| 93 | + ]; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')] |
|
| 97 | + public function testValidateCheck(string $operator, string $value): void { |
|
| 98 | + $check = new RequestTime($this->getL10NMock(), $this->timeFactory); |
|
| 99 | + $check->validateCheck($operator, $value); |
|
| 100 | + $this->addToAssertionCount(1); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public static function dataValidateCheckInvalid(): array { |
|
| 104 | + return [ |
|
| 105 | + ['!!in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]', 1, 'The given operator is invalid'], |
|
| 106 | + ['in', '["28:00 Europe/Berlin","17:00 Europe/Berlin"]', 2, 'The given time span is invalid'], |
|
| 107 | + ['in', '["08:00 Europe/Berlin","27:00 Europe/Berlin"]', 2, 'The given time span is invalid'], |
|
| 108 | + ['in', '["08:00 Europa/Berlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'], |
|
| 109 | + ['in', '["08:00 Europe/Berlin","17:00 Europa/Berlin"]', 4, 'The given end time is invalid'], |
|
| 110 | + ['in', '["08:00 Europe/Bearlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'], |
|
| 111 | + ['in', '["08:00 Europe/Berlin","17:00 Europe/Bearlin"]', 4, 'The given end time is invalid'], |
|
| 112 | + ]; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')] |
|
| 116 | + public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { |
|
| 117 | + $check = new RequestTime($this->getL10NMock(), $this->timeFactory); |
|
| 118 | + |
|
| 119 | + try { |
|
| 120 | + $check->validateCheck($operator, $value); |
|
| 121 | + } catch (\UnexpectedValueException $e) { |
|
| 122 | + $this->assertEquals($exceptionCode, $e->getCode()); |
|
| 123 | + $this->assertEquals($exceptionMessage, $e->getMessage()); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -13,124 +13,124 @@ |
||
| 13 | 13 | use Test\TestCase; |
| 14 | 14 | |
| 15 | 15 | class CommentersSorterTest extends TestCase { |
| 16 | - protected ICommentsManager&MockObject $commentsManager; |
|
| 17 | - protected CommentersSorter $sorter; |
|
| 16 | + protected ICommentsManager&MockObject $commentsManager; |
|
| 17 | + protected CommentersSorter $sorter; |
|
| 18 | 18 | |
| 19 | - protected function setUp(): void { |
|
| 20 | - parent::setUp(); |
|
| 19 | + protected function setUp(): void { |
|
| 20 | + parent::setUp(); |
|
| 21 | 21 | |
| 22 | - $this->commentsManager = $this->createMock(ICommentsManager::class); |
|
| 22 | + $this->commentsManager = $this->createMock(ICommentsManager::class); |
|
| 23 | 23 | |
| 24 | - $this->sorter = new CommentersSorter($this->commentsManager); |
|
| 25 | - } |
|
| 24 | + $this->sorter = new CommentersSorter($this->commentsManager); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param $data |
|
| 29 | - */ |
|
| 30 | - #[\PHPUnit\Framework\Attributes\DataProvider('sortDataProvider')] |
|
| 31 | - public function testSort($data): void { |
|
| 32 | - $commentMocks = []; |
|
| 33 | - foreach ($data['actors'] as $actorType => $actors) { |
|
| 34 | - foreach ($actors as $actorId => $noOfComments) { |
|
| 35 | - for ($i = 0;$i < $noOfComments;$i++) { |
|
| 36 | - $mock = $this->createMock(IComment::class); |
|
| 37 | - $mock->expects($this->atLeastOnce()) |
|
| 38 | - ->method('getActorType') |
|
| 39 | - ->willReturn($actorType); |
|
| 40 | - $mock->expects($this->atLeastOnce()) |
|
| 41 | - ->method('getActorId') |
|
| 42 | - ->willReturn($actorId); |
|
| 43 | - $commentMocks[] = $mock; |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 27 | + /** |
|
| 28 | + * @param $data |
|
| 29 | + */ |
|
| 30 | + #[\PHPUnit\Framework\Attributes\DataProvider('sortDataProvider')] |
|
| 31 | + public function testSort($data): void { |
|
| 32 | + $commentMocks = []; |
|
| 33 | + foreach ($data['actors'] as $actorType => $actors) { |
|
| 34 | + foreach ($actors as $actorId => $noOfComments) { |
|
| 35 | + for ($i = 0;$i < $noOfComments;$i++) { |
|
| 36 | + $mock = $this->createMock(IComment::class); |
|
| 37 | + $mock->expects($this->atLeastOnce()) |
|
| 38 | + ->method('getActorType') |
|
| 39 | + ->willReturn($actorType); |
|
| 40 | + $mock->expects($this->atLeastOnce()) |
|
| 41 | + ->method('getActorId') |
|
| 42 | + ->willReturn($actorId); |
|
| 43 | + $commentMocks[] = $mock; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $this->commentsManager->expects($this->once()) |
|
| 49 | - ->method('getForObject') |
|
| 50 | - ->willReturn($commentMocks); |
|
| 48 | + $this->commentsManager->expects($this->once()) |
|
| 49 | + ->method('getForObject') |
|
| 50 | + ->willReturn($commentMocks); |
|
| 51 | 51 | |
| 52 | - $workArray = $data['input']; |
|
| 53 | - $this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '24']); |
|
| 52 | + $workArray = $data['input']; |
|
| 53 | + $this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '24']); |
|
| 54 | 54 | |
| 55 | - $this->assertEquals($data['expected'], $workArray); |
|
| 56 | - } |
|
| 55 | + $this->assertEquals($data['expected'], $workArray); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public static function sortDataProvider(): array { |
|
| 59 | - return [[ |
|
| 60 | - [ |
|
| 61 | - #1 – sort properly and otherwise keep existing order |
|
| 62 | - 'actors' => ['users' => ['celia' => 3, 'darius' => 7, 'faruk' => 5, 'gail' => 5], 'bots' => ['r2-d2' => 8]], |
|
| 63 | - 'input' => [ |
|
| 64 | - 'users' => [ |
|
| 65 | - ['value' => ['shareWith' => 'alice']], |
|
| 66 | - ['value' => ['shareWith' => 'bob']], |
|
| 67 | - ['value' => ['shareWith' => 'celia']], |
|
| 68 | - ['value' => ['shareWith' => 'darius']], |
|
| 69 | - ['value' => ['shareWith' => 'elena']], |
|
| 70 | - ['value' => ['shareWith' => 'faruk']], |
|
| 71 | - ['value' => ['shareWith' => 'gail']], |
|
| 72 | - ], |
|
| 73 | - 'bots' => [ |
|
| 74 | - ['value' => ['shareWith' => 'c-3po']], |
|
| 75 | - ['value' => ['shareWith' => 'r2-d2']], |
|
| 76 | - ] |
|
| 77 | - ], |
|
| 78 | - 'expected' => [ |
|
| 79 | - 'users' => [ |
|
| 80 | - ['value' => ['shareWith' => 'darius']], |
|
| 81 | - ['value' => ['shareWith' => 'faruk']], |
|
| 82 | - ['value' => ['shareWith' => 'gail']], |
|
| 83 | - ['value' => ['shareWith' => 'celia']], |
|
| 84 | - ['value' => ['shareWith' => 'alice']], |
|
| 85 | - ['value' => ['shareWith' => 'bob']], |
|
| 86 | - ['value' => ['shareWith' => 'elena']], |
|
| 87 | - ], |
|
| 88 | - 'bots' => [ |
|
| 89 | - ['value' => ['shareWith' => 'r2-d2']], |
|
| 90 | - ['value' => ['shareWith' => 'c-3po']], |
|
| 91 | - ] |
|
| 92 | - ], |
|
| 93 | - ], |
|
| 94 | - [ |
|
| 95 | - #2 – no commentors, input equals output |
|
| 96 | - 'actors' => [], |
|
| 97 | - 'input' => [ |
|
| 98 | - 'users' => [ |
|
| 99 | - ['value' => ['shareWith' => 'alice']], |
|
| 100 | - ['value' => ['shareWith' => 'bob']], |
|
| 101 | - ['value' => ['shareWith' => 'celia']], |
|
| 102 | - ['value' => ['shareWith' => 'darius']], |
|
| 103 | - ['value' => ['shareWith' => 'elena']], |
|
| 104 | - ['value' => ['shareWith' => 'faruk']], |
|
| 105 | - ['value' => ['shareWith' => 'gail']], |
|
| 106 | - ], |
|
| 107 | - 'bots' => [ |
|
| 108 | - ['value' => ['shareWith' => 'c-3po']], |
|
| 109 | - ['value' => ['shareWith' => 'r2-d2']], |
|
| 110 | - ] |
|
| 111 | - ], |
|
| 112 | - 'expected' => [ |
|
| 113 | - 'users' => [ |
|
| 114 | - ['value' => ['shareWith' => 'alice']], |
|
| 115 | - ['value' => ['shareWith' => 'bob']], |
|
| 116 | - ['value' => ['shareWith' => 'celia']], |
|
| 117 | - ['value' => ['shareWith' => 'darius']], |
|
| 118 | - ['value' => ['shareWith' => 'elena']], |
|
| 119 | - ['value' => ['shareWith' => 'faruk']], |
|
| 120 | - ['value' => ['shareWith' => 'gail']], |
|
| 121 | - ], |
|
| 122 | - 'bots' => [ |
|
| 123 | - ['value' => ['shareWith' => 'c-3po']], |
|
| 124 | - ['value' => ['shareWith' => 'r2-d2']], |
|
| 125 | - ] |
|
| 126 | - ], |
|
| 127 | - ], |
|
| 128 | - [ |
|
| 129 | - #3 – no nothing |
|
| 130 | - 'actors' => [], |
|
| 131 | - 'input' => [], |
|
| 132 | - 'expected' => [], |
|
| 133 | - ], |
|
| 134 | - ]]; |
|
| 135 | - } |
|
| 58 | + public static function sortDataProvider(): array { |
|
| 59 | + return [[ |
|
| 60 | + [ |
|
| 61 | + #1 – sort properly and otherwise keep existing order |
|
| 62 | + 'actors' => ['users' => ['celia' => 3, 'darius' => 7, 'faruk' => 5, 'gail' => 5], 'bots' => ['r2-d2' => 8]], |
|
| 63 | + 'input' => [ |
|
| 64 | + 'users' => [ |
|
| 65 | + ['value' => ['shareWith' => 'alice']], |
|
| 66 | + ['value' => ['shareWith' => 'bob']], |
|
| 67 | + ['value' => ['shareWith' => 'celia']], |
|
| 68 | + ['value' => ['shareWith' => 'darius']], |
|
| 69 | + ['value' => ['shareWith' => 'elena']], |
|
| 70 | + ['value' => ['shareWith' => 'faruk']], |
|
| 71 | + ['value' => ['shareWith' => 'gail']], |
|
| 72 | + ], |
|
| 73 | + 'bots' => [ |
|
| 74 | + ['value' => ['shareWith' => 'c-3po']], |
|
| 75 | + ['value' => ['shareWith' => 'r2-d2']], |
|
| 76 | + ] |
|
| 77 | + ], |
|
| 78 | + 'expected' => [ |
|
| 79 | + 'users' => [ |
|
| 80 | + ['value' => ['shareWith' => 'darius']], |
|
| 81 | + ['value' => ['shareWith' => 'faruk']], |
|
| 82 | + ['value' => ['shareWith' => 'gail']], |
|
| 83 | + ['value' => ['shareWith' => 'celia']], |
|
| 84 | + ['value' => ['shareWith' => 'alice']], |
|
| 85 | + ['value' => ['shareWith' => 'bob']], |
|
| 86 | + ['value' => ['shareWith' => 'elena']], |
|
| 87 | + ], |
|
| 88 | + 'bots' => [ |
|
| 89 | + ['value' => ['shareWith' => 'r2-d2']], |
|
| 90 | + ['value' => ['shareWith' => 'c-3po']], |
|
| 91 | + ] |
|
| 92 | + ], |
|
| 93 | + ], |
|
| 94 | + [ |
|
| 95 | + #2 – no commentors, input equals output |
|
| 96 | + 'actors' => [], |
|
| 97 | + 'input' => [ |
|
| 98 | + 'users' => [ |
|
| 99 | + ['value' => ['shareWith' => 'alice']], |
|
| 100 | + ['value' => ['shareWith' => 'bob']], |
|
| 101 | + ['value' => ['shareWith' => 'celia']], |
|
| 102 | + ['value' => ['shareWith' => 'darius']], |
|
| 103 | + ['value' => ['shareWith' => 'elena']], |
|
| 104 | + ['value' => ['shareWith' => 'faruk']], |
|
| 105 | + ['value' => ['shareWith' => 'gail']], |
|
| 106 | + ], |
|
| 107 | + 'bots' => [ |
|
| 108 | + ['value' => ['shareWith' => 'c-3po']], |
|
| 109 | + ['value' => ['shareWith' => 'r2-d2']], |
|
| 110 | + ] |
|
| 111 | + ], |
|
| 112 | + 'expected' => [ |
|
| 113 | + 'users' => [ |
|
| 114 | + ['value' => ['shareWith' => 'alice']], |
|
| 115 | + ['value' => ['shareWith' => 'bob']], |
|
| 116 | + ['value' => ['shareWith' => 'celia']], |
|
| 117 | + ['value' => ['shareWith' => 'darius']], |
|
| 118 | + ['value' => ['shareWith' => 'elena']], |
|
| 119 | + ['value' => ['shareWith' => 'faruk']], |
|
| 120 | + ['value' => ['shareWith' => 'gail']], |
|
| 121 | + ], |
|
| 122 | + 'bots' => [ |
|
| 123 | + ['value' => ['shareWith' => 'c-3po']], |
|
| 124 | + ['value' => ['shareWith' => 'r2-d2']], |
|
| 125 | + ] |
|
| 126 | + ], |
|
| 127 | + ], |
|
| 128 | + [ |
|
| 129 | + #3 – no nothing |
|
| 130 | + 'actors' => [], |
|
| 131 | + 'input' => [], |
|
| 132 | + 'expected' => [], |
|
| 133 | + ], |
|
| 134 | + ]]; |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -28,187 +28,187 @@ |
||
| 28 | 28 | use Test\TestCase; |
| 29 | 29 | |
| 30 | 30 | class NotificationsTest extends TestCase { |
| 31 | - protected ICommentsManager&MockObject $commentsManager; |
|
| 32 | - protected IRootFolder&MockObject $rootFolder; |
|
| 33 | - protected IUserSession&MockObject $session; |
|
| 34 | - protected IManager&MockObject $notificationManager; |
|
| 35 | - protected IURLGenerator&MockObject $urlGenerator; |
|
| 36 | - protected NotificationsController $notificationsController; |
|
| 37 | - |
|
| 38 | - protected function setUp(): void { |
|
| 39 | - parent::setUp(); |
|
| 40 | - |
|
| 41 | - $this->commentsManager = $this->createMock(ICommentsManager::class); |
|
| 42 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 43 | - $this->session = $this->createMock(IUserSession::class); |
|
| 44 | - $this->notificationManager = $this->createMock(IManager::class); |
|
| 45 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
| 46 | - |
|
| 47 | - $this->notificationsController = new NotificationsController( |
|
| 48 | - 'comments', |
|
| 49 | - $this->createMock(IRequest::class), |
|
| 50 | - $this->commentsManager, |
|
| 51 | - $this->rootFolder, |
|
| 52 | - $this->urlGenerator, |
|
| 53 | - $this->notificationManager, |
|
| 54 | - $this->session |
|
| 55 | - ); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function testViewGuestRedirect(): void { |
|
| 59 | - $this->commentsManager->expects($this->never()) |
|
| 60 | - ->method('get'); |
|
| 61 | - |
|
| 62 | - $this->rootFolder->expects($this->never()) |
|
| 63 | - ->method('getUserFolder'); |
|
| 64 | - |
|
| 65 | - $this->session->expects($this->once()) |
|
| 66 | - ->method('getUser') |
|
| 67 | - ->willReturn(null); |
|
| 68 | - |
|
| 69 | - $this->notificationManager->expects($this->never()) |
|
| 70 | - ->method('createNotification'); |
|
| 71 | - $this->notificationManager->expects($this->never()) |
|
| 72 | - ->method('markProcessed'); |
|
| 73 | - |
|
| 74 | - $this->urlGenerator->expects($this->exactly(2)) |
|
| 75 | - ->method('linkToRoute') |
|
| 76 | - ->willReturnMap([ |
|
| 77 | - ['comments.Notifications.view', ['id' => '42'], 'link-to-comment'], |
|
| 78 | - ['core.login.showLoginForm', ['redirect_url' => 'link-to-comment'], 'link-to-login'], |
|
| 79 | - ]); |
|
| 80 | - |
|
| 81 | - /** @var RedirectResponse $response */ |
|
| 82 | - $response = $this->notificationsController->view('42'); |
|
| 83 | - $this->assertInstanceOf(RedirectResponse::class, $response); |
|
| 84 | - $this->assertSame('link-to-login', $response->getRedirectURL()); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function testViewSuccess(): void { |
|
| 88 | - $comment = $this->createMock(IComment::class); |
|
| 89 | - $comment->expects($this->any()) |
|
| 90 | - ->method('getObjectType') |
|
| 91 | - ->willReturn('files'); |
|
| 92 | - $comment->expects($this->any()) |
|
| 93 | - ->method('getId') |
|
| 94 | - ->willReturn('1234'); |
|
| 95 | - |
|
| 96 | - $this->commentsManager->expects($this->any()) |
|
| 97 | - ->method('get') |
|
| 98 | - ->with('42') |
|
| 99 | - ->willReturn($comment); |
|
| 100 | - |
|
| 101 | - $file = $this->createMock(Node::class); |
|
| 102 | - $folder = $this->createMock(Folder::class); |
|
| 103 | - $user = $this->createMock(IUser::class); |
|
| 104 | - |
|
| 105 | - $this->rootFolder->expects($this->once()) |
|
| 106 | - ->method('getUserFolder') |
|
| 107 | - ->willReturn($folder); |
|
| 108 | - |
|
| 109 | - $folder->expects($this->once()) |
|
| 110 | - ->method('getById') |
|
| 111 | - ->willReturn([$file]); |
|
| 112 | - |
|
| 113 | - $this->session->expects($this->once()) |
|
| 114 | - ->method('getUser') |
|
| 115 | - ->willReturn($user); |
|
| 116 | - |
|
| 117 | - $user->expects($this->any()) |
|
| 118 | - ->method('getUID') |
|
| 119 | - ->willReturn('user'); |
|
| 120 | - |
|
| 121 | - $notification = $this->createMock(INotification::class); |
|
| 122 | - $notification->expects($this->any()) |
|
| 123 | - ->method($this->anything()) |
|
| 124 | - ->willReturn($notification); |
|
| 125 | - |
|
| 126 | - $this->notificationManager->expects($this->once()) |
|
| 127 | - ->method('createNotification') |
|
| 128 | - ->willReturn($notification); |
|
| 129 | - $this->notificationManager->expects($this->once()) |
|
| 130 | - ->method('markProcessed') |
|
| 131 | - ->with($notification); |
|
| 132 | - |
|
| 133 | - $response = $this->notificationsController->view('42'); |
|
| 134 | - $this->assertInstanceOf(RedirectResponse::class, $response); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function testViewInvalidComment(): void { |
|
| 138 | - $this->commentsManager->expects($this->any()) |
|
| 139 | - ->method('get') |
|
| 140 | - ->with('42') |
|
| 141 | - ->willThrowException(new NotFoundException()); |
|
| 142 | - |
|
| 143 | - $this->rootFolder->expects($this->never()) |
|
| 144 | - ->method('getUserFolder'); |
|
| 145 | - |
|
| 146 | - $user = $this->createMock(IUser::class); |
|
| 147 | - |
|
| 148 | - $this->session->expects($this->once()) |
|
| 149 | - ->method('getUser') |
|
| 150 | - ->willReturn($user); |
|
| 151 | - |
|
| 152 | - $user->expects($this->any()) |
|
| 153 | - ->method('getUID') |
|
| 154 | - ->willReturn('user'); |
|
| 155 | - |
|
| 156 | - $this->notificationManager->expects($this->never()) |
|
| 157 | - ->method('createNotification'); |
|
| 158 | - $this->notificationManager->expects($this->never()) |
|
| 159 | - ->method('markProcessed'); |
|
| 160 | - |
|
| 161 | - $response = $this->notificationsController->view('42'); |
|
| 162 | - $this->assertInstanceOf(NotFoundResponse::class, $response); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - public function testViewNoFile(): void { |
|
| 166 | - $comment = $this->createMock(IComment::class); |
|
| 167 | - $comment->expects($this->any()) |
|
| 168 | - ->method('getObjectType') |
|
| 169 | - ->willReturn('files'); |
|
| 170 | - $comment->expects($this->any()) |
|
| 171 | - ->method('getId') |
|
| 172 | - ->willReturn('1234'); |
|
| 173 | - |
|
| 174 | - $this->commentsManager->expects($this->any()) |
|
| 175 | - ->method('get') |
|
| 176 | - ->with('42') |
|
| 177 | - ->willReturn($comment); |
|
| 178 | - |
|
| 179 | - $folder = $this->createMock(Folder::class); |
|
| 180 | - |
|
| 181 | - $this->rootFolder->expects($this->once()) |
|
| 182 | - ->method('getUserFolder') |
|
| 183 | - ->willReturn($folder); |
|
| 184 | - |
|
| 185 | - $folder->expects($this->once()) |
|
| 186 | - ->method('getById') |
|
| 187 | - ->willReturn([]); |
|
| 188 | - |
|
| 189 | - $user = $this->createMock(IUser::class); |
|
| 190 | - |
|
| 191 | - $this->session->expects($this->once()) |
|
| 192 | - ->method('getUser') |
|
| 193 | - ->willReturn($user); |
|
| 194 | - |
|
| 195 | - $user->expects($this->any()) |
|
| 196 | - ->method('getUID') |
|
| 197 | - ->willReturn('user'); |
|
| 198 | - |
|
| 199 | - $notification = $this->createMock(INotification::class); |
|
| 200 | - $notification->expects($this->any()) |
|
| 201 | - ->method($this->anything()) |
|
| 202 | - ->willReturn($notification); |
|
| 203 | - |
|
| 204 | - $this->notificationManager->expects($this->once()) |
|
| 205 | - ->method('createNotification') |
|
| 206 | - ->willReturn($notification); |
|
| 207 | - $this->notificationManager->expects($this->once()) |
|
| 208 | - ->method('markProcessed') |
|
| 209 | - ->with($notification); |
|
| 210 | - |
|
| 211 | - $response = $this->notificationsController->view('42'); |
|
| 212 | - $this->assertInstanceOf(NotFoundResponse::class, $response); |
|
| 213 | - } |
|
| 31 | + protected ICommentsManager&MockObject $commentsManager; |
|
| 32 | + protected IRootFolder&MockObject $rootFolder; |
|
| 33 | + protected IUserSession&MockObject $session; |
|
| 34 | + protected IManager&MockObject $notificationManager; |
|
| 35 | + protected IURLGenerator&MockObject $urlGenerator; |
|
| 36 | + protected NotificationsController $notificationsController; |
|
| 37 | + |
|
| 38 | + protected function setUp(): void { |
|
| 39 | + parent::setUp(); |
|
| 40 | + |
|
| 41 | + $this->commentsManager = $this->createMock(ICommentsManager::class); |
|
| 42 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 43 | + $this->session = $this->createMock(IUserSession::class); |
|
| 44 | + $this->notificationManager = $this->createMock(IManager::class); |
|
| 45 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
| 46 | + |
|
| 47 | + $this->notificationsController = new NotificationsController( |
|
| 48 | + 'comments', |
|
| 49 | + $this->createMock(IRequest::class), |
|
| 50 | + $this->commentsManager, |
|
| 51 | + $this->rootFolder, |
|
| 52 | + $this->urlGenerator, |
|
| 53 | + $this->notificationManager, |
|
| 54 | + $this->session |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function testViewGuestRedirect(): void { |
|
| 59 | + $this->commentsManager->expects($this->never()) |
|
| 60 | + ->method('get'); |
|
| 61 | + |
|
| 62 | + $this->rootFolder->expects($this->never()) |
|
| 63 | + ->method('getUserFolder'); |
|
| 64 | + |
|
| 65 | + $this->session->expects($this->once()) |
|
| 66 | + ->method('getUser') |
|
| 67 | + ->willReturn(null); |
|
| 68 | + |
|
| 69 | + $this->notificationManager->expects($this->never()) |
|
| 70 | + ->method('createNotification'); |
|
| 71 | + $this->notificationManager->expects($this->never()) |
|
| 72 | + ->method('markProcessed'); |
|
| 73 | + |
|
| 74 | + $this->urlGenerator->expects($this->exactly(2)) |
|
| 75 | + ->method('linkToRoute') |
|
| 76 | + ->willReturnMap([ |
|
| 77 | + ['comments.Notifications.view', ['id' => '42'], 'link-to-comment'], |
|
| 78 | + ['core.login.showLoginForm', ['redirect_url' => 'link-to-comment'], 'link-to-login'], |
|
| 79 | + ]); |
|
| 80 | + |
|
| 81 | + /** @var RedirectResponse $response */ |
|
| 82 | + $response = $this->notificationsController->view('42'); |
|
| 83 | + $this->assertInstanceOf(RedirectResponse::class, $response); |
|
| 84 | + $this->assertSame('link-to-login', $response->getRedirectURL()); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function testViewSuccess(): void { |
|
| 88 | + $comment = $this->createMock(IComment::class); |
|
| 89 | + $comment->expects($this->any()) |
|
| 90 | + ->method('getObjectType') |
|
| 91 | + ->willReturn('files'); |
|
| 92 | + $comment->expects($this->any()) |
|
| 93 | + ->method('getId') |
|
| 94 | + ->willReturn('1234'); |
|
| 95 | + |
|
| 96 | + $this->commentsManager->expects($this->any()) |
|
| 97 | + ->method('get') |
|
| 98 | + ->with('42') |
|
| 99 | + ->willReturn($comment); |
|
| 100 | + |
|
| 101 | + $file = $this->createMock(Node::class); |
|
| 102 | + $folder = $this->createMock(Folder::class); |
|
| 103 | + $user = $this->createMock(IUser::class); |
|
| 104 | + |
|
| 105 | + $this->rootFolder->expects($this->once()) |
|
| 106 | + ->method('getUserFolder') |
|
| 107 | + ->willReturn($folder); |
|
| 108 | + |
|
| 109 | + $folder->expects($this->once()) |
|
| 110 | + ->method('getById') |
|
| 111 | + ->willReturn([$file]); |
|
| 112 | + |
|
| 113 | + $this->session->expects($this->once()) |
|
| 114 | + ->method('getUser') |
|
| 115 | + ->willReturn($user); |
|
| 116 | + |
|
| 117 | + $user->expects($this->any()) |
|
| 118 | + ->method('getUID') |
|
| 119 | + ->willReturn('user'); |
|
| 120 | + |
|
| 121 | + $notification = $this->createMock(INotification::class); |
|
| 122 | + $notification->expects($this->any()) |
|
| 123 | + ->method($this->anything()) |
|
| 124 | + ->willReturn($notification); |
|
| 125 | + |
|
| 126 | + $this->notificationManager->expects($this->once()) |
|
| 127 | + ->method('createNotification') |
|
| 128 | + ->willReturn($notification); |
|
| 129 | + $this->notificationManager->expects($this->once()) |
|
| 130 | + ->method('markProcessed') |
|
| 131 | + ->with($notification); |
|
| 132 | + |
|
| 133 | + $response = $this->notificationsController->view('42'); |
|
| 134 | + $this->assertInstanceOf(RedirectResponse::class, $response); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function testViewInvalidComment(): void { |
|
| 138 | + $this->commentsManager->expects($this->any()) |
|
| 139 | + ->method('get') |
|
| 140 | + ->with('42') |
|
| 141 | + ->willThrowException(new NotFoundException()); |
|
| 142 | + |
|
| 143 | + $this->rootFolder->expects($this->never()) |
|
| 144 | + ->method('getUserFolder'); |
|
| 145 | + |
|
| 146 | + $user = $this->createMock(IUser::class); |
|
| 147 | + |
|
| 148 | + $this->session->expects($this->once()) |
|
| 149 | + ->method('getUser') |
|
| 150 | + ->willReturn($user); |
|
| 151 | + |
|
| 152 | + $user->expects($this->any()) |
|
| 153 | + ->method('getUID') |
|
| 154 | + ->willReturn('user'); |
|
| 155 | + |
|
| 156 | + $this->notificationManager->expects($this->never()) |
|
| 157 | + ->method('createNotification'); |
|
| 158 | + $this->notificationManager->expects($this->never()) |
|
| 159 | + ->method('markProcessed'); |
|
| 160 | + |
|
| 161 | + $response = $this->notificationsController->view('42'); |
|
| 162 | + $this->assertInstanceOf(NotFoundResponse::class, $response); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + public function testViewNoFile(): void { |
|
| 166 | + $comment = $this->createMock(IComment::class); |
|
| 167 | + $comment->expects($this->any()) |
|
| 168 | + ->method('getObjectType') |
|
| 169 | + ->willReturn('files'); |
|
| 170 | + $comment->expects($this->any()) |
|
| 171 | + ->method('getId') |
|
| 172 | + ->willReturn('1234'); |
|
| 173 | + |
|
| 174 | + $this->commentsManager->expects($this->any()) |
|
| 175 | + ->method('get') |
|
| 176 | + ->with('42') |
|
| 177 | + ->willReturn($comment); |
|
| 178 | + |
|
| 179 | + $folder = $this->createMock(Folder::class); |
|
| 180 | + |
|
| 181 | + $this->rootFolder->expects($this->once()) |
|
| 182 | + ->method('getUserFolder') |
|
| 183 | + ->willReturn($folder); |
|
| 184 | + |
|
| 185 | + $folder->expects($this->once()) |
|
| 186 | + ->method('getById') |
|
| 187 | + ->willReturn([]); |
|
| 188 | + |
|
| 189 | + $user = $this->createMock(IUser::class); |
|
| 190 | + |
|
| 191 | + $this->session->expects($this->once()) |
|
| 192 | + ->method('getUser') |
|
| 193 | + ->willReturn($user); |
|
| 194 | + |
|
| 195 | + $user->expects($this->any()) |
|
| 196 | + ->method('getUID') |
|
| 197 | + ->willReturn('user'); |
|
| 198 | + |
|
| 199 | + $notification = $this->createMock(INotification::class); |
|
| 200 | + $notification->expects($this->any()) |
|
| 201 | + ->method($this->anything()) |
|
| 202 | + ->willReturn($notification); |
|
| 203 | + |
|
| 204 | + $this->notificationManager->expects($this->once()) |
|
| 205 | + ->method('createNotification') |
|
| 206 | + ->willReturn($notification); |
|
| 207 | + $this->notificationManager->expects($this->once()) |
|
| 208 | + ->method('markProcessed') |
|
| 209 | + ->with($notification); |
|
| 210 | + |
|
| 211 | + $response = $this->notificationsController->view('42'); |
|
| 212 | + $this->assertInstanceOf(NotFoundResponse::class, $response); |
|
| 213 | + } |
|
| 214 | 214 | } |
@@ -18,178 +18,178 @@ |
||
| 18 | 18 | use Test\TestCase; |
| 19 | 19 | |
| 20 | 20 | class ListenerTest extends TestCase { |
| 21 | - protected IManager&MockObject $notificationManager; |
|
| 22 | - protected IUserManager&MockObject $userManager; |
|
| 23 | - protected IURLGenerator&MockObject $urlGenerator; |
|
| 24 | - protected Listener $listener; |
|
| 25 | - |
|
| 26 | - protected function setUp(): void { |
|
| 27 | - parent::setUp(); |
|
| 28 | - |
|
| 29 | - $this->notificationManager = $this->createMock(IManager::class); |
|
| 30 | - $this->userManager = $this->createMock(IUserManager::class); |
|
| 31 | - |
|
| 32 | - $this->listener = new Listener( |
|
| 33 | - $this->notificationManager, |
|
| 34 | - $this->userManager |
|
| 35 | - ); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public static function eventProvider(): array { |
|
| 39 | - return [ |
|
| 40 | - [CommentsEvent::EVENT_ADD, 'notify'], |
|
| 41 | - [CommentsEvent::EVENT_UPDATE, 'notify'], |
|
| 42 | - [CommentsEvent::EVENT_PRE_UPDATE, 'markProcessed'], |
|
| 43 | - [CommentsEvent::EVENT_DELETE, 'markProcessed'] |
|
| 44 | - ]; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param string $eventType |
|
| 49 | - * @param string $notificationMethod |
|
| 50 | - */ |
|
| 51 | - #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')] |
|
| 52 | - public function testEvaluate($eventType, $notificationMethod): void { |
|
| 53 | - /** @var IComment|MockObject $comment */ |
|
| 54 | - $comment = $this->createMock(IComment::class); |
|
| 55 | - $comment->expects($this->any()) |
|
| 56 | - ->method('getObjectType') |
|
| 57 | - ->willReturn('files'); |
|
| 58 | - $comment->expects($this->any()) |
|
| 59 | - ->method('getCreationDateTime') |
|
| 60 | - ->willReturn(new \DateTime()); |
|
| 61 | - $comment->expects($this->once()) |
|
| 62 | - ->method('getMentions') |
|
| 63 | - ->willReturn([ |
|
| 64 | - [ 'type' => 'user', 'id' => 'foobar'], |
|
| 65 | - [ 'type' => 'user', 'id' => 'barfoo'], |
|
| 66 | - [ 'type' => 'user', 'id' => '[email protected]'], |
|
| 67 | - [ 'type' => 'user', 'id' => '[email protected]@foobar.io'], |
|
| 68 | - [ 'type' => 'user', 'id' => '23452-4333-54353-2342'], |
|
| 69 | - [ 'type' => 'user', 'id' => 'yolo'], |
|
| 70 | - ]); |
|
| 71 | - $comment->expects($this->atLeastOnce()) |
|
| 72 | - ->method('getId') |
|
| 73 | - ->willReturn('1234'); |
|
| 74 | - |
|
| 75 | - /** @var CommentsEvent|MockObject $event */ |
|
| 76 | - $event = $this->createMock(CommentsEvent::class); |
|
| 77 | - $event->expects($this->once()) |
|
| 78 | - ->method('getComment') |
|
| 79 | - ->willReturn($comment); |
|
| 80 | - $event->expects(($this->any())) |
|
| 81 | - ->method(('getEvent')) |
|
| 82 | - ->willReturn($eventType); |
|
| 83 | - |
|
| 84 | - /** @var INotification|MockObject $notification */ |
|
| 85 | - $notification = $this->createMock(INotification::class); |
|
| 86 | - $notification->expects($this->any()) |
|
| 87 | - ->method($this->anything()) |
|
| 88 | - ->willReturn($notification); |
|
| 89 | - $notification->expects($this->exactly(6)) |
|
| 90 | - ->method('setUser'); |
|
| 91 | - |
|
| 92 | - $this->notificationManager->expects($this->once()) |
|
| 93 | - ->method('createNotification') |
|
| 94 | - ->willReturn($notification); |
|
| 95 | - $this->notificationManager->expects($this->exactly(6)) |
|
| 96 | - ->method($notificationMethod) |
|
| 97 | - ->with($this->isInstanceOf('\OCP\Notification\INotification')); |
|
| 98 | - |
|
| 99 | - $this->userManager->expects($this->exactly(6)) |
|
| 100 | - ->method('userExists') |
|
| 101 | - ->willReturnMap([ |
|
| 102 | - ['foobar', true], |
|
| 103 | - ['barfoo', true], |
|
| 104 | - ['[email protected]', true], |
|
| 105 | - ['[email protected]@foobar.io', true], |
|
| 106 | - ['23452-4333-54353-2342', true], |
|
| 107 | - ['yolo', true] |
|
| 108 | - ]); |
|
| 109 | - |
|
| 110 | - $this->listener->evaluate($event); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')] |
|
| 114 | - public function testEvaluateNoMentions(string $eventType): void { |
|
| 115 | - /** @var IComment|MockObject $comment */ |
|
| 116 | - $comment = $this->createMock(IComment::class); |
|
| 117 | - $comment->expects($this->any()) |
|
| 118 | - ->method('getObjectType') |
|
| 119 | - ->willReturn('files'); |
|
| 120 | - $comment->expects($this->any()) |
|
| 121 | - ->method('getCreationDateTime') |
|
| 122 | - ->willReturn(new \DateTime()); |
|
| 123 | - $comment->expects($this->once()) |
|
| 124 | - ->method('getMentions') |
|
| 125 | - ->willReturn([]); |
|
| 126 | - |
|
| 127 | - /** @var CommentsEvent|MockObject $event */ |
|
| 128 | - $event = $this->createMock(CommentsEvent::class); |
|
| 129 | - $event->expects($this->once()) |
|
| 130 | - ->method('getComment') |
|
| 131 | - ->willReturn($comment); |
|
| 132 | - $event->expects(($this->any())) |
|
| 133 | - ->method(('getEvent')) |
|
| 134 | - ->willReturn($eventType); |
|
| 135 | - |
|
| 136 | - $this->notificationManager->expects($this->never()) |
|
| 137 | - ->method('createNotification'); |
|
| 138 | - $this->notificationManager->expects($this->never()) |
|
| 139 | - ->method('notify'); |
|
| 140 | - $this->notificationManager->expects($this->never()) |
|
| 141 | - ->method('markProcessed'); |
|
| 142 | - |
|
| 143 | - $this->userManager->expects($this->never()) |
|
| 144 | - ->method('userExists'); |
|
| 145 | - |
|
| 146 | - $this->listener->evaluate($event); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - public function testEvaluateUserDoesNotExist(): void { |
|
| 150 | - /** @var IComment|MockObject $comment */ |
|
| 151 | - $comment = $this->createMock(IComment::class); |
|
| 152 | - $comment->expects($this->any()) |
|
| 153 | - ->method('getObjectType') |
|
| 154 | - ->willReturn('files'); |
|
| 155 | - $comment->expects($this->any()) |
|
| 156 | - ->method('getCreationDateTime') |
|
| 157 | - ->willReturn(new \DateTime()); |
|
| 158 | - $comment->expects($this->once()) |
|
| 159 | - ->method('getMentions') |
|
| 160 | - ->willReturn([[ 'type' => 'user', 'id' => 'foobar']]); |
|
| 161 | - $comment->expects($this->atLeastOnce()) |
|
| 162 | - ->method('getId') |
|
| 163 | - ->willReturn('1234'); |
|
| 164 | - |
|
| 165 | - /** @var CommentsEvent|MockObject $event */ |
|
| 166 | - $event = $this->createMock(CommentsEvent::class); |
|
| 167 | - $event->expects($this->once()) |
|
| 168 | - ->method('getComment') |
|
| 169 | - ->willReturn($comment); |
|
| 170 | - $event->expects(($this->any())) |
|
| 171 | - ->method(('getEvent')) |
|
| 172 | - ->willReturn(CommentsEvent::EVENT_ADD); |
|
| 173 | - |
|
| 174 | - /** @var INotification|MockObject $notification */ |
|
| 175 | - $notification = $this->createMock(INotification::class); |
|
| 176 | - $notification->expects($this->any()) |
|
| 177 | - ->method($this->anything()) |
|
| 178 | - ->willReturn($notification); |
|
| 179 | - $notification->expects($this->never()) |
|
| 180 | - ->method('setUser'); |
|
| 181 | - |
|
| 182 | - $this->notificationManager->expects($this->once()) |
|
| 183 | - ->method('createNotification') |
|
| 184 | - ->willReturn($notification); |
|
| 185 | - $this->notificationManager->expects($this->never()) |
|
| 186 | - ->method('notify'); |
|
| 187 | - |
|
| 188 | - $this->userManager->expects($this->once()) |
|
| 189 | - ->method('userExists') |
|
| 190 | - ->with('foobar') |
|
| 191 | - ->willReturn(false); |
|
| 192 | - |
|
| 193 | - $this->listener->evaluate($event); |
|
| 194 | - } |
|
| 21 | + protected IManager&MockObject $notificationManager; |
|
| 22 | + protected IUserManager&MockObject $userManager; |
|
| 23 | + protected IURLGenerator&MockObject $urlGenerator; |
|
| 24 | + protected Listener $listener; |
|
| 25 | + |
|
| 26 | + protected function setUp(): void { |
|
| 27 | + parent::setUp(); |
|
| 28 | + |
|
| 29 | + $this->notificationManager = $this->createMock(IManager::class); |
|
| 30 | + $this->userManager = $this->createMock(IUserManager::class); |
|
| 31 | + |
|
| 32 | + $this->listener = new Listener( |
|
| 33 | + $this->notificationManager, |
|
| 34 | + $this->userManager |
|
| 35 | + ); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public static function eventProvider(): array { |
|
| 39 | + return [ |
|
| 40 | + [CommentsEvent::EVENT_ADD, 'notify'], |
|
| 41 | + [CommentsEvent::EVENT_UPDATE, 'notify'], |
|
| 42 | + [CommentsEvent::EVENT_PRE_UPDATE, 'markProcessed'], |
|
| 43 | + [CommentsEvent::EVENT_DELETE, 'markProcessed'] |
|
| 44 | + ]; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param string $eventType |
|
| 49 | + * @param string $notificationMethod |
|
| 50 | + */ |
|
| 51 | + #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')] |
|
| 52 | + public function testEvaluate($eventType, $notificationMethod): void { |
|
| 53 | + /** @var IComment|MockObject $comment */ |
|
| 54 | + $comment = $this->createMock(IComment::class); |
|
| 55 | + $comment->expects($this->any()) |
|
| 56 | + ->method('getObjectType') |
|
| 57 | + ->willReturn('files'); |
|
| 58 | + $comment->expects($this->any()) |
|
| 59 | + ->method('getCreationDateTime') |
|
| 60 | + ->willReturn(new \DateTime()); |
|
| 61 | + $comment->expects($this->once()) |
|
| 62 | + ->method('getMentions') |
|
| 63 | + ->willReturn([ |
|
| 64 | + [ 'type' => 'user', 'id' => 'foobar'], |
|
| 65 | + [ 'type' => 'user', 'id' => 'barfoo'], |
|
| 66 | + [ 'type' => 'user', 'id' => '[email protected]'], |
|
| 67 | + [ 'type' => 'user', 'id' => '[email protected]@foobar.io'], |
|
| 68 | + [ 'type' => 'user', 'id' => '23452-4333-54353-2342'], |
|
| 69 | + [ 'type' => 'user', 'id' => 'yolo'], |
|
| 70 | + ]); |
|
| 71 | + $comment->expects($this->atLeastOnce()) |
|
| 72 | + ->method('getId') |
|
| 73 | + ->willReturn('1234'); |
|
| 74 | + |
|
| 75 | + /** @var CommentsEvent|MockObject $event */ |
|
| 76 | + $event = $this->createMock(CommentsEvent::class); |
|
| 77 | + $event->expects($this->once()) |
|
| 78 | + ->method('getComment') |
|
| 79 | + ->willReturn($comment); |
|
| 80 | + $event->expects(($this->any())) |
|
| 81 | + ->method(('getEvent')) |
|
| 82 | + ->willReturn($eventType); |
|
| 83 | + |
|
| 84 | + /** @var INotification|MockObject $notification */ |
|
| 85 | + $notification = $this->createMock(INotification::class); |
|
| 86 | + $notification->expects($this->any()) |
|
| 87 | + ->method($this->anything()) |
|
| 88 | + ->willReturn($notification); |
|
| 89 | + $notification->expects($this->exactly(6)) |
|
| 90 | + ->method('setUser'); |
|
| 91 | + |
|
| 92 | + $this->notificationManager->expects($this->once()) |
|
| 93 | + ->method('createNotification') |
|
| 94 | + ->willReturn($notification); |
|
| 95 | + $this->notificationManager->expects($this->exactly(6)) |
|
| 96 | + ->method($notificationMethod) |
|
| 97 | + ->with($this->isInstanceOf('\OCP\Notification\INotification')); |
|
| 98 | + |
|
| 99 | + $this->userManager->expects($this->exactly(6)) |
|
| 100 | + ->method('userExists') |
|
| 101 | + ->willReturnMap([ |
|
| 102 | + ['foobar', true], |
|
| 103 | + ['barfoo', true], |
|
| 104 | + ['[email protected]', true], |
|
| 105 | + ['[email protected]@foobar.io', true], |
|
| 106 | + ['23452-4333-54353-2342', true], |
|
| 107 | + ['yolo', true] |
|
| 108 | + ]); |
|
| 109 | + |
|
| 110 | + $this->listener->evaluate($event); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')] |
|
| 114 | + public function testEvaluateNoMentions(string $eventType): void { |
|
| 115 | + /** @var IComment|MockObject $comment */ |
|
| 116 | + $comment = $this->createMock(IComment::class); |
|
| 117 | + $comment->expects($this->any()) |
|
| 118 | + ->method('getObjectType') |
|
| 119 | + ->willReturn('files'); |
|
| 120 | + $comment->expects($this->any()) |
|
| 121 | + ->method('getCreationDateTime') |
|
| 122 | + ->willReturn(new \DateTime()); |
|
| 123 | + $comment->expects($this->once()) |
|
| 124 | + ->method('getMentions') |
|
| 125 | + ->willReturn([]); |
|
| 126 | + |
|
| 127 | + /** @var CommentsEvent|MockObject $event */ |
|
| 128 | + $event = $this->createMock(CommentsEvent::class); |
|
| 129 | + $event->expects($this->once()) |
|
| 130 | + ->method('getComment') |
|
| 131 | + ->willReturn($comment); |
|
| 132 | + $event->expects(($this->any())) |
|
| 133 | + ->method(('getEvent')) |
|
| 134 | + ->willReturn($eventType); |
|
| 135 | + |
|
| 136 | + $this->notificationManager->expects($this->never()) |
|
| 137 | + ->method('createNotification'); |
|
| 138 | + $this->notificationManager->expects($this->never()) |
|
| 139 | + ->method('notify'); |
|
| 140 | + $this->notificationManager->expects($this->never()) |
|
| 141 | + ->method('markProcessed'); |
|
| 142 | + |
|
| 143 | + $this->userManager->expects($this->never()) |
|
| 144 | + ->method('userExists'); |
|
| 145 | + |
|
| 146 | + $this->listener->evaluate($event); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + public function testEvaluateUserDoesNotExist(): void { |
|
| 150 | + /** @var IComment|MockObject $comment */ |
|
| 151 | + $comment = $this->createMock(IComment::class); |
|
| 152 | + $comment->expects($this->any()) |
|
| 153 | + ->method('getObjectType') |
|
| 154 | + ->willReturn('files'); |
|
| 155 | + $comment->expects($this->any()) |
|
| 156 | + ->method('getCreationDateTime') |
|
| 157 | + ->willReturn(new \DateTime()); |
|
| 158 | + $comment->expects($this->once()) |
|
| 159 | + ->method('getMentions') |
|
| 160 | + ->willReturn([[ 'type' => 'user', 'id' => 'foobar']]); |
|
| 161 | + $comment->expects($this->atLeastOnce()) |
|
| 162 | + ->method('getId') |
|
| 163 | + ->willReturn('1234'); |
|
| 164 | + |
|
| 165 | + /** @var CommentsEvent|MockObject $event */ |
|
| 166 | + $event = $this->createMock(CommentsEvent::class); |
|
| 167 | + $event->expects($this->once()) |
|
| 168 | + ->method('getComment') |
|
| 169 | + ->willReturn($comment); |
|
| 170 | + $event->expects(($this->any())) |
|
| 171 | + ->method(('getEvent')) |
|
| 172 | + ->willReturn(CommentsEvent::EVENT_ADD); |
|
| 173 | + |
|
| 174 | + /** @var INotification|MockObject $notification */ |
|
| 175 | + $notification = $this->createMock(INotification::class); |
|
| 176 | + $notification->expects($this->any()) |
|
| 177 | + ->method($this->anything()) |
|
| 178 | + ->willReturn($notification); |
|
| 179 | + $notification->expects($this->never()) |
|
| 180 | + ->method('setUser'); |
|
| 181 | + |
|
| 182 | + $this->notificationManager->expects($this->once()) |
|
| 183 | + ->method('createNotification') |
|
| 184 | + ->willReturn($notification); |
|
| 185 | + $this->notificationManager->expects($this->never()) |
|
| 186 | + ->method('notify'); |
|
| 187 | + |
|
| 188 | + $this->userManager->expects($this->once()) |
|
| 189 | + ->method('userExists') |
|
| 190 | + ->with('foobar') |
|
| 191 | + ->willReturn(false); |
|
| 192 | + |
|
| 193 | + $this->listener->evaluate($event); |
|
| 194 | + } |
|
| 195 | 195 | } |
@@ -17,71 +17,71 @@ |
||
| 17 | 17 | use Test\TestCase; |
| 18 | 18 | |
| 19 | 19 | class EventHandlerTest extends TestCase { |
| 20 | - protected ActivityListener&MockObject $activityListener; |
|
| 21 | - protected NotificationListener&MockObject $notificationListener; |
|
| 22 | - protected CommentsEventListener $eventHandler; |
|
| 23 | - |
|
| 24 | - protected function setUp(): void { |
|
| 25 | - parent::setUp(); |
|
| 26 | - |
|
| 27 | - $this->activityListener = $this->createMock(ActivityListener::class); |
|
| 28 | - $this->notificationListener = $this->createMock(NotificationListener::class); |
|
| 29 | - |
|
| 30 | - $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function testNotFiles(): void { |
|
| 34 | - /** @var IComment|MockObject $comment */ |
|
| 35 | - $comment = $this->createMock(IComment::class); |
|
| 36 | - $comment->expects($this->once()) |
|
| 37 | - ->method('getObjectType') |
|
| 38 | - ->willReturn('smiles'); |
|
| 39 | - |
|
| 40 | - /** @var CommentsEvent|MockObject $event */ |
|
| 41 | - $event = $this->createMock(CommentsEvent::class); |
|
| 42 | - $event->expects($this->once()) |
|
| 43 | - ->method('getComment') |
|
| 44 | - ->willReturn($comment); |
|
| 45 | - $event->expects($this->never()) |
|
| 46 | - ->method('getEvent'); |
|
| 47 | - |
|
| 48 | - $this->eventHandler->handle($event); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public static function handledProvider(): array { |
|
| 52 | - return [ |
|
| 53 | - [CommentsEvent::EVENT_DELETE], |
|
| 54 | - [CommentsEvent::EVENT_UPDATE], |
|
| 55 | - [CommentsEvent::EVENT_PRE_UPDATE], |
|
| 56 | - [CommentsEvent::EVENT_ADD] |
|
| 57 | - ]; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - #[\PHPUnit\Framework\Attributes\DataProvider('handledProvider')] |
|
| 61 | - public function testHandled(string $eventType): void { |
|
| 62 | - /** @var IComment|MockObject $comment */ |
|
| 63 | - $comment = $this->createMock(IComment::class); |
|
| 64 | - $comment->expects($this->once()) |
|
| 65 | - ->method('getObjectType') |
|
| 66 | - ->willReturn('files'); |
|
| 67 | - |
|
| 68 | - /** @var CommentsEvent|MockObject $event */ |
|
| 69 | - $event = $this->createMock(CommentsEvent::class); |
|
| 70 | - $event->expects($this->atLeastOnce()) |
|
| 71 | - ->method('getComment') |
|
| 72 | - ->willReturn($comment); |
|
| 73 | - $event->expects($this->atLeastOnce()) |
|
| 74 | - ->method('getEvent') |
|
| 75 | - ->willReturn($eventType); |
|
| 76 | - |
|
| 77 | - $this->notificationListener->expects($this->once()) |
|
| 78 | - ->method('evaluate') |
|
| 79 | - ->with($event); |
|
| 80 | - |
|
| 81 | - $this->activityListener->expects($this->any()) |
|
| 82 | - ->method('commentEvent') |
|
| 83 | - ->with($event); |
|
| 84 | - |
|
| 85 | - $this->eventHandler->handle($event); |
|
| 86 | - } |
|
| 20 | + protected ActivityListener&MockObject $activityListener; |
|
| 21 | + protected NotificationListener&MockObject $notificationListener; |
|
| 22 | + protected CommentsEventListener $eventHandler; |
|
| 23 | + |
|
| 24 | + protected function setUp(): void { |
|
| 25 | + parent::setUp(); |
|
| 26 | + |
|
| 27 | + $this->activityListener = $this->createMock(ActivityListener::class); |
|
| 28 | + $this->notificationListener = $this->createMock(NotificationListener::class); |
|
| 29 | + |
|
| 30 | + $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function testNotFiles(): void { |
|
| 34 | + /** @var IComment|MockObject $comment */ |
|
| 35 | + $comment = $this->createMock(IComment::class); |
|
| 36 | + $comment->expects($this->once()) |
|
| 37 | + ->method('getObjectType') |
|
| 38 | + ->willReturn('smiles'); |
|
| 39 | + |
|
| 40 | + /** @var CommentsEvent|MockObject $event */ |
|
| 41 | + $event = $this->createMock(CommentsEvent::class); |
|
| 42 | + $event->expects($this->once()) |
|
| 43 | + ->method('getComment') |
|
| 44 | + ->willReturn($comment); |
|
| 45 | + $event->expects($this->never()) |
|
| 46 | + ->method('getEvent'); |
|
| 47 | + |
|
| 48 | + $this->eventHandler->handle($event); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public static function handledProvider(): array { |
|
| 52 | + return [ |
|
| 53 | + [CommentsEvent::EVENT_DELETE], |
|
| 54 | + [CommentsEvent::EVENT_UPDATE], |
|
| 55 | + [CommentsEvent::EVENT_PRE_UPDATE], |
|
| 56 | + [CommentsEvent::EVENT_ADD] |
|
| 57 | + ]; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + #[\PHPUnit\Framework\Attributes\DataProvider('handledProvider')] |
|
| 61 | + public function testHandled(string $eventType): void { |
|
| 62 | + /** @var IComment|MockObject $comment */ |
|
| 63 | + $comment = $this->createMock(IComment::class); |
|
| 64 | + $comment->expects($this->once()) |
|
| 65 | + ->method('getObjectType') |
|
| 66 | + ->willReturn('files'); |
|
| 67 | + |
|
| 68 | + /** @var CommentsEvent|MockObject $event */ |
|
| 69 | + $event = $this->createMock(CommentsEvent::class); |
|
| 70 | + $event->expects($this->atLeastOnce()) |
|
| 71 | + ->method('getComment') |
|
| 72 | + ->willReturn($comment); |
|
| 73 | + $event->expects($this->atLeastOnce()) |
|
| 74 | + ->method('getEvent') |
|
| 75 | + ->willReturn($eventType); |
|
| 76 | + |
|
| 77 | + $this->notificationListener->expects($this->once()) |
|
| 78 | + ->method('evaluate') |
|
| 79 | + ->with($event); |
|
| 80 | + |
|
| 81 | + $this->activityListener->expects($this->any()) |
|
| 82 | + ->method('commentEvent') |
|
| 83 | + ->with($event); |
|
| 84 | + |
|
| 85 | + $this->eventHandler->handle($event); |
|
| 86 | + } |
|
| 87 | 87 | } |