NotificationProviderManagerTest.php 3.3 KB

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