You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NotificationProviderManagerTest.php 3.5KB

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