NotificationProviderManagerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Thomas Citharel
  5. * @copyright Copyright (c) 2019, Georg Ehrke
  6. *
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Georg Ehrke <oc.list@georgehrke.com>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Citharel <nextcloud@tcit.fr>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
  29. use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
  30. use OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException;
  31. use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
  32. use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
  33. use OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException;
  34. use OCA\DAV\Capabilities;
  35. use Test\TestCase;
  36. class NotificationProviderManagerTest extends TestCase {
  37. /** @var NotificationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
  38. private $providerManager;
  39. /**
  40. * @throws \OCP\AppFramework\QueryException
  41. */
  42. protected function setUp(): void {
  43. parent::setUp();
  44. $this->providerManager = new NotificationProviderManager();
  45. $this->providerManager->registerProvider(EmailProvider::class);
  46. }
  47. /**
  48. * @throws ProviderNotAvailableException
  49. * @throws NotificationTypeDoesNotExistException
  50. */
  51. public function testGetProviderForUnknownType(): void {
  52. $this->expectException(\OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException::class);
  53. $this->expectExceptionMessage('Type NOT EXISTENT is not an accepted type of notification');
  54. $this->providerManager->getProvider('NOT EXISTENT');
  55. }
  56. /**
  57. * @throws NotificationTypeDoesNotExistException
  58. * @throws ProviderNotAvailableException
  59. */
  60. public function testGetProviderForUnRegisteredType(): void {
  61. $this->expectException(\OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException::class);
  62. $this->expectExceptionMessage('No notification provider for type AUDIO available');
  63. $this->providerManager->getProvider('AUDIO');
  64. }
  65. public function testGetProvider(): void {
  66. $provider = $this->providerManager->getProvider('EMAIL');
  67. $this->assertInstanceOf(EmailProvider::class, $provider);
  68. }
  69. public function testRegisterProvider(): void {
  70. $this->providerManager->registerProvider(PushProvider::class);
  71. $provider = $this->providerManager->getProvider('DISPLAY');
  72. $this->assertInstanceOf(PushProvider::class, $provider);
  73. }
  74. /**
  75. * @throws \OCP\AppFramework\QueryException
  76. */
  77. public function testRegisterBadProvider(): void {
  78. $this->expectException(\InvalidArgumentException::class);
  79. $this->expectExceptionMessage('Invalid notification provider registered');
  80. $this->providerManager->registerProvider(Capabilities::class);
  81. }
  82. public function testHasProvider(): void {
  83. $this->assertTrue($this->providerManager->hasProvider('EMAIL'));
  84. $this->assertFalse($this->providerManager->hasProvider('EMAIL123'));
  85. }
  86. }