NotificationProviderManagerTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
  8. use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
  9. use OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException;
  10. use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
  11. use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
  12. use OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException;
  13. use OCA\DAV\Capabilities;
  14. use OCP\AppFramework\QueryException;
  15. use Test\TestCase;
  16. class NotificationProviderManagerTest extends TestCase {
  17. /** @var NotificationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
  18. private $providerManager;
  19. /**
  20. * @throws QueryException
  21. */
  22. protected function setUp(): void {
  23. parent::setUp();
  24. $this->providerManager = new NotificationProviderManager();
  25. $this->providerManager->registerProvider(EmailProvider::class);
  26. }
  27. /**
  28. * @throws ProviderNotAvailableException
  29. * @throws NotificationTypeDoesNotExistException
  30. */
  31. public function testGetProviderForUnknownType(): void {
  32. $this->expectException(NotificationTypeDoesNotExistException::class);
  33. $this->expectExceptionMessage('Type NOT EXISTENT is not an accepted type of notification');
  34. $this->providerManager->getProvider('NOT EXISTENT');
  35. }
  36. /**
  37. * @throws NotificationTypeDoesNotExistException
  38. * @throws ProviderNotAvailableException
  39. */
  40. public function testGetProviderForUnRegisteredType(): void {
  41. $this->expectException(ProviderNotAvailableException::class);
  42. $this->expectExceptionMessage('No notification provider for type AUDIO available');
  43. $this->providerManager->getProvider('AUDIO');
  44. }
  45. public function testGetProvider(): void {
  46. $provider = $this->providerManager->getProvider('EMAIL');
  47. $this->assertInstanceOf(EmailProvider::class, $provider);
  48. }
  49. public function testRegisterProvider(): void {
  50. $this->providerManager->registerProvider(PushProvider::class);
  51. $provider = $this->providerManager->getProvider('DISPLAY');
  52. $this->assertInstanceOf(PushProvider::class, $provider);
  53. }
  54. /**
  55. * @throws QueryException
  56. */
  57. public function testRegisterBadProvider(): void {
  58. $this->expectException(\InvalidArgumentException::class);
  59. $this->expectExceptionMessage('Invalid notification provider registered');
  60. $this->providerManager->registerProvider(Capabilities::class);
  61. }
  62. public function testHasProvider(): void {
  63. $this->assertTrue($this->providerManager->hasProvider('EMAIL'));
  64. $this->assertFalse($this->providerManager->hasProvider('EMAIL123'));
  65. }
  66. }