NotificationProviderManagerTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Test\TestCase;
  15. class NotificationProviderManagerTest extends TestCase {
  16. /** @var NotificationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
  17. private $providerManager;
  18. /**
  19. * @throws \OCP\AppFramework\QueryException
  20. */
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $this->providerManager = new NotificationProviderManager();
  24. $this->providerManager->registerProvider(EmailProvider::class);
  25. }
  26. /**
  27. * @throws ProviderNotAvailableException
  28. * @throws NotificationTypeDoesNotExistException
  29. */
  30. public function testGetProviderForUnknownType(): void {
  31. $this->expectException(\OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException::class);
  32. $this->expectExceptionMessage('Type NOT EXISTENT is not an accepted type of notification');
  33. $this->providerManager->getProvider('NOT EXISTENT');
  34. }
  35. /**
  36. * @throws NotificationTypeDoesNotExistException
  37. * @throws ProviderNotAvailableException
  38. */
  39. public function testGetProviderForUnRegisteredType(): void {
  40. $this->expectException(\OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException::class);
  41. $this->expectExceptionMessage('No notification provider for type AUDIO available');
  42. $this->providerManager->getProvider('AUDIO');
  43. }
  44. public function testGetProvider(): void {
  45. $provider = $this->providerManager->getProvider('EMAIL');
  46. $this->assertInstanceOf(EmailProvider::class, $provider);
  47. }
  48. public function testRegisterProvider(): void {
  49. $this->providerManager->registerProvider(PushProvider::class);
  50. $provider = $this->providerManager->getProvider('DISPLAY');
  51. $this->assertInstanceOf(PushProvider::class, $provider);
  52. }
  53. /**
  54. * @throws \OCP\AppFramework\QueryException
  55. */
  56. public function testRegisterBadProvider(): void {
  57. $this->expectException(\InvalidArgumentException::class);
  58. $this->expectExceptionMessage('Invalid notification provider registered');
  59. $this->providerManager->registerProvider(Capabilities::class);
  60. }
  61. public function testHasProvider(): void {
  62. $this->assertTrue($this->providerManager->hasProvider('EMAIL'));
  63. $this->assertFalse($this->providerManager->hasProvider('EMAIL123'));
  64. }
  65. }