Files
nextcloud-server-mirror/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php
Côme Chilliet 1ab09ec753 chore: Apply new coding standard to all files
The diff can be checked using: git diff --ignore-all-space --ignore-blank-lines
To see only the changes not related to blank lines.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2026-06-01 13:46:39 +02:00

83 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
use OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException;
use OCA\DAV\Capabilities;
use Psr\Container\ContainerExceptionInterface;
use Test\TestCase;
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
class NotificationProviderManagerTest extends TestCase {
private NotificationProviderManager $providerManager;
/**
* @throws ContainerExceptionInterface
*/
protected function setUp(): void {
parent::setUp();
$this->providerManager = new NotificationProviderManager();
$this->providerManager->registerProvider(EmailProvider::class);
}
/**
* @throws ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException
*/
public function testGetProviderForUnknownType(): void {
$this->expectException(NotificationTypeDoesNotExistException::class);
$this->expectExceptionMessage('Type NOT EXISTENT is not an accepted type of notification');
$this->providerManager->getProvider('NOT EXISTENT');
}
/**
* @throws NotificationTypeDoesNotExistException
* @throws ProviderNotAvailableException
*/
public function testGetProviderForUnRegisteredType(): void {
$this->expectException(ProviderNotAvailableException::class);
$this->expectExceptionMessage('No notification provider for type AUDIO available');
$this->providerManager->getProvider('AUDIO');
}
public function testGetProvider(): void {
$provider = $this->providerManager->getProvider('EMAIL');
$this->assertInstanceOf(EmailProvider::class, $provider);
}
public function testRegisterProvider(): void {
$this->providerManager->registerProvider(PushProvider::class);
$provider = $this->providerManager->getProvider('DISPLAY');
$this->assertInstanceOf(PushProvider::class, $provider);
}
/**
* @throws ContainerExceptionInterface
*/
public function testRegisterBadProvider(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid notification provider registered');
$this->providerManager->registerProvider(Capabilities::class);
}
public function testHasProvider(): void {
$this->assertTrue($this->providerManager->hasProvider('EMAIL'));
$this->assertFalse($this->providerManager->hasProvider('EMAIL123'));
}
}