2019-03-16 18:19:25 +03:00
|
|
|
<?php
|
2019-08-12 14:20:03 +03:00
|
|
|
declare(strict_types=1);
|
2019-03-16 18:19:25 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2019, Thomas Citharel
|
2019-08-12 14:20:03 +03:00
|
|
|
* @copyright Copyright (c) 2019, Georg Ehrke
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
|
|
|
* @author Thomas Citharel <tcit@tcit.fr>
|
2019-08-12 14:20:03 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2019-03-16 18:19:25 +03:00
|
|
|
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 Test\TestCase;
|
|
|
|
|
|
|
|
class NotificationProviderManagerTest extends TestCase {
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
/** @var NotificationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
private $providerManager;
|
2019-03-16 18:19:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \OCP\AppFramework\QueryException
|
|
|
|
*/
|
2019-11-21 18:40:38 +03:00
|
|
|
public function setUp(): void {
|
2019-03-16 18:19:25 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$this->providerManager = new NotificationProviderManager();
|
|
|
|
$this->providerManager->registerProvider(EmailProvider::class);
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException
|
|
|
|
* @expectedExceptionMessage Type NOT EXISTENT is not an accepted type of notification
|
|
|
|
* @throws ProviderNotAvailableException
|
|
|
|
* @throws NotificationTypeDoesNotExistException
|
|
|
|
*/
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testGetProviderForUnknownType(): void{
|
|
|
|
$this->providerManager->getProvider('NOT EXISTENT');
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException
|
|
|
|
* @expectedExceptionMessage No notification provider for type AUDIO available
|
|
|
|
* @throws NotificationTypeDoesNotExistException
|
|
|
|
* @throws ProviderNotAvailableException
|
|
|
|
*/
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testGetProviderForUnRegisteredType(): void{
|
|
|
|
$this->providerManager->getProvider('AUDIO');
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testGetProvider(): void{
|
|
|
|
$provider = $this->providerManager->getProvider('EMAIL');
|
|
|
|
$this->assertInstanceOf(EmailProvider::class, $provider);
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testRegisterProvider(): void{
|
2019-03-16 18:19:25 +03:00
|
|
|
$this->providerManager->registerProvider(PushProvider::class);
|
|
|
|
$provider = $this->providerManager->getProvider('DISPLAY');
|
|
|
|
$this->assertInstanceOf(PushProvider::class, $provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedExceptionMessage Invalid notification provider registered
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
* @throws \OCP\AppFramework\QueryException
|
|
|
|
*/
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testRegisterBadProvider(): void{
|
2019-03-16 18:19:25 +03:00
|
|
|
$this->providerManager->registerProvider(Capabilities::class);
|
|
|
|
}
|
2019-08-12 14:20:03 +03:00
|
|
|
|
|
|
|
public function testHasProvider(): void {
|
|
|
|
$this->assertTrue($this->providerManager->hasProvider('EMAIL'));
|
|
|
|
$this->assertFalse($this->providerManager->hasProvider('EMAIL123'));
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|