2019-03-16 18:19:25 +03:00
|
|
|
<?php
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
declare(strict_types=1);
|
2019-12-03 21:57:53 +03:00
|
|
|
|
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
|
|
|
*
|
2019-08-12 14:20:03 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
* @author Thomas Citharel <tcit@tcit.fr>
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2019-12-03 21:57:53 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-03-16 18:19:25 +03:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2019-03-16 18:19:25 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\Reminder\NotificationProvider;
|
|
|
|
|
|
|
|
use OCA\DAV\AppInfo\Application;
|
|
|
|
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2019-03-16 18:19:25 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IUser;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\L10N\IFactory as L10NFactory;
|
2019-03-16 18:19:25 +03:00
|
|
|
use OCP\Notification\IManager;
|
|
|
|
use OCP\Notification\INotification;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class PushProviderTest extends AbstractNotificationProviderTest {
|
|
|
|
|
|
|
|
/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
protected $logger;
|
|
|
|
|
|
|
|
/** @var L10NFactory|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
protected $l10nFactory;
|
|
|
|
|
|
|
|
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
protected $l10n;
|
|
|
|
|
|
|
|
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
protected $urlGenerator;
|
|
|
|
|
|
|
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
private $manager;
|
|
|
|
|
|
|
|
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
private $timeFactory;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2019-03-16 18:19:25 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2019-09-02 16:18:43 +03:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2019-03-16 18:19:25 +03:00
|
|
|
$this->manager = $this->createMock(IManager::class);
|
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
|
|
|
|
$this->provider = new PushProvider(
|
|
|
|
$this->config,
|
|
|
|
$this->manager,
|
|
|
|
$this->logger,
|
|
|
|
$this->l10nFactory,
|
|
|
|
$this->urlGenerator,
|
|
|
|
$this->timeFactory
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testNotificationType():void {
|
|
|
|
$this->assertEquals(PushProvider::NOTIFICATION_TYPE, 'DISPLAY');
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:18:43 +03:00
|
|
|
public function testNotSend(): void {
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('dav', 'sendEventRemindersPush', 'no')
|
|
|
|
->willReturn('no');
|
|
|
|
|
|
|
|
$this->manager->expects($this->never())
|
|
|
|
->method('createNotification');
|
|
|
|
$this->manager->expects($this->never())
|
|
|
|
->method('notify');
|
|
|
|
|
|
|
|
$user1 = $this->createMock(IUser::class);
|
|
|
|
$user1->method('getUID')
|
|
|
|
->willReturn('uid1');
|
|
|
|
$user2 = $this->createMock(IUser::class);
|
|
|
|
$user2->method('getUID')
|
|
|
|
->willReturn('uid2');
|
|
|
|
$user3 = $this->createMock(IUser::class);
|
|
|
|
$user3->method('getUID')
|
|
|
|
->willReturn('uid3');
|
|
|
|
|
|
|
|
$users = [$user1, $user2, $user3];
|
|
|
|
|
|
|
|
$this->provider->send($this->vcalendar->VEVENT, $this->calendarDisplayName, $users);
|
|
|
|
}
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testSend(): void {
|
2019-09-02 16:18:43 +03:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('dav', 'sendEventRemindersPush', 'no')
|
|
|
|
->willReturn('yes');
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$user1 = $this->createMock(IUser::class);
|
|
|
|
$user1->method('getUID')
|
|
|
|
->willReturn('uid1');
|
|
|
|
$user2 = $this->createMock(IUser::class);
|
|
|
|
$user2->method('getUID')
|
|
|
|
->willReturn('uid2');
|
|
|
|
$user3 = $this->createMock(IUser::class);
|
|
|
|
$user3->method('getUID')
|
|
|
|
->willReturn('uid3');
|
|
|
|
|
|
|
|
$users = [$user1, $user2, $user3];
|
|
|
|
|
|
|
|
$dateTime = new \DateTime('@946684800');
|
|
|
|
$this->timeFactory->method('getDateTime')
|
2019-03-16 18:19:25 +03:00
|
|
|
->with()
|
2019-08-12 14:20:03 +03:00
|
|
|
->willReturn($dateTime);
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$notification1 = $this->createNotificationMock('uid1', $dateTime);
|
|
|
|
$notification2 = $this->createNotificationMock('uid2', $dateTime);
|
|
|
|
$notification3 = $this->createNotificationMock('uid3', $dateTime);
|
|
|
|
|
|
|
|
$this->manager->expects($this->at(0))
|
|
|
|
->method('createNotification')
|
|
|
|
->with()
|
|
|
|
->willReturn($notification1);
|
|
|
|
$this->manager->expects($this->at(2))
|
|
|
|
->method('createNotification')
|
|
|
|
->with()
|
|
|
|
->willReturn($notification2);
|
|
|
|
$this->manager->expects($this->at(4))
|
|
|
|
->method('createNotification')
|
|
|
|
->with()
|
|
|
|
->willReturn($notification3);
|
|
|
|
|
|
|
|
$this->manager->expects($this->at(1))
|
|
|
|
->method('notify')
|
|
|
|
->with($notification1);
|
|
|
|
$this->manager->expects($this->at(3))
|
|
|
|
->method('notify')
|
|
|
|
->with($notification2);
|
|
|
|
$this->manager->expects($this->at(5))
|
|
|
|
->method('notify')
|
|
|
|
->with($notification3);
|
|
|
|
|
|
|
|
$this->provider->send($this->vcalendar->VEVENT, $this->calendarDisplayName, $users);
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|
2019-08-12 14:20:03 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $uid
|
|
|
|
* @param \DateTime $dt
|
|
|
|
*/
|
|
|
|
private function createNotificationMock(string $uid, \DateTime $dt):INotification {
|
|
|
|
$notification = $this->createMock(INotification::class);
|
|
|
|
$notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setApp')
|
|
|
|
->with('dav')
|
|
|
|
->willReturn($notification);
|
|
|
|
|
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setUser')
|
|
|
|
->with($uid)
|
|
|
|
->willReturn($notification);
|
|
|
|
|
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setDateTime')
|
|
|
|
->with($dt)
|
|
|
|
->willReturn($notification);
|
|
|
|
|
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setObject')
|
2020-02-01 17:29:02 +03:00
|
|
|
->with('dav', hash('sha256', 'uid1234', false))
|
2019-08-12 14:20:03 +03:00
|
|
|
->willReturn($notification);
|
|
|
|
|
|
|
|
$notification->expects($this->once())
|
|
|
|
->method('setSubject')
|
|
|
|
->with('calendar_reminder', [
|
|
|
|
'title' => 'Fellowship meeting',
|
|
|
|
'start_atom' => '2017-01-01T00:00:00+00:00',
|
|
|
|
])
|
|
|
|
->willReturn($notification);
|
|
|
|
|
|
|
|
$notification
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setMessage')
|
|
|
|
->with('calendar_reminder', [
|
|
|
|
'title' => 'Fellowship meeting',
|
|
|
|
'start_atom' => '2017-01-01T00:00:00+00:00',
|
|
|
|
'description' => null,
|
|
|
|
'location' => null,
|
|
|
|
'all_day' => false,
|
|
|
|
'start_is_floating' => false,
|
|
|
|
'start_timezone' => 'UTC',
|
|
|
|
'end_atom' => '2017-01-01T00:00:00+00:00',
|
|
|
|
'end_is_floating' => false,
|
|
|
|
'end_timezone' => 'UTC',
|
|
|
|
'calendar_displayname' => 'Personal',
|
|
|
|
])
|
|
|
|
->willReturn($notification);
|
|
|
|
|
|
|
|
return $notification;
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|