|
|
|
|
@ -36,23 +36,25 @@ use OCP\AppFramework\Utility\ITimeFactory; |
|
|
|
|
use OCP\IL10N; |
|
|
|
|
use OCP\IURLGenerator; |
|
|
|
|
use OCP\L10N\IFactory; |
|
|
|
|
use OCP\Notification\AlreadyProcessedException; |
|
|
|
|
use OCP\Notification\INotification; |
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
|
|
|
use Test\TestCase; |
|
|
|
|
|
|
|
|
|
class NotifierTest extends TestCase { |
|
|
|
|
/** @var Notifier */ |
|
|
|
|
protected $notifier; |
|
|
|
|
|
|
|
|
|
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */ |
|
|
|
|
/** @var IFactory|MockObject */ |
|
|
|
|
protected $factory; |
|
|
|
|
|
|
|
|
|
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ |
|
|
|
|
/** @var IURLGenerator|MockObject */ |
|
|
|
|
protected $urlGenerator; |
|
|
|
|
|
|
|
|
|
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ |
|
|
|
|
/** @var IL10N|MockObject */ |
|
|
|
|
protected $l10n; |
|
|
|
|
|
|
|
|
|
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ |
|
|
|
|
/** @var ITimeFactory|MockObject */ |
|
|
|
|
protected $timeFactory; |
|
|
|
|
|
|
|
|
|
protected function setUp(): void { |
|
|
|
|
@ -111,7 +113,7 @@ class NotifierTest extends TestCase { |
|
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
|
|
|
$this->expectExceptionMessage('Notification not from this app'); |
|
|
|
|
|
|
|
|
|
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ |
|
|
|
|
/** @var INotification|MockObject $notification */ |
|
|
|
|
$notification = $this->createMock(INotification::class); |
|
|
|
|
|
|
|
|
|
$notification->expects($this->once()) |
|
|
|
|
@ -128,7 +130,7 @@ class NotifierTest extends TestCase { |
|
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
|
|
|
$this->expectExceptionMessage('Unknown subject'); |
|
|
|
|
|
|
|
|
|
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ |
|
|
|
|
/** @var INotification|MockObject $notification */ |
|
|
|
|
$notification = $this->createMock(INotification::class); |
|
|
|
|
|
|
|
|
|
$notification->expects($this->once()) |
|
|
|
|
@ -165,6 +167,28 @@ class NotifierTest extends TestCase { |
|
|
|
|
], |
|
|
|
|
"Calendar: Personal\r\nDate: 2005-08-15T15:52:01+02:00, 2005-08-15T15:52:01+02:00 - 2005-08-15T17:52:01+02:00 (Europe/Berlin)\r\nWhere: NC Headquarters" |
|
|
|
|
], |
|
|
|
|
[ |
|
|
|
|
'calendar_reminder', |
|
|
|
|
[ |
|
|
|
|
'title' => 'Title of this event', |
|
|
|
|
'start_atom' => '2005-08-15T13:00:00+02:00', |
|
|
|
|
], |
|
|
|
|
'Title of this event (1 hour ago)', |
|
|
|
|
[ |
|
|
|
|
'title' => 'Title of this event', |
|
|
|
|
'description' => null, |
|
|
|
|
'location' => 'NC Headquarters', |
|
|
|
|
'all_day' => false, |
|
|
|
|
'start_atom' => '2005-08-15T13:00:00+02:00', |
|
|
|
|
'start_is_floating' => false, |
|
|
|
|
'start_timezone' => 'Europe/Berlin', |
|
|
|
|
'end_atom' => '2005-08-15T15:00:00+02:00', |
|
|
|
|
'end_is_floating' => false, |
|
|
|
|
'end_timezone' => 'Europe/Berlin', |
|
|
|
|
'calendar_displayname' => 'Personal', |
|
|
|
|
], |
|
|
|
|
"Calendar: Personal\r\nDate: 2005-08-15T13:00:00+02:00, 2005-08-15T13:00:00+02:00 - 2005-08-15T15:00:00+02:00 (Europe/Berlin)\r\nWhere: NC Headquarters" |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -179,7 +203,7 @@ class NotifierTest extends TestCase { |
|
|
|
|
* @throws \Exception |
|
|
|
|
*/ |
|
|
|
|
public function testPrepare(string $subjectType, array $subjectParams, string $subject, array $messageParams, string $message): void { |
|
|
|
|
/** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ |
|
|
|
|
/** @var INotification|MockObject $notification */ |
|
|
|
|
$notification = $this->createMock(INotification::class); |
|
|
|
|
|
|
|
|
|
$notification->expects($this->once()) |
|
|
|
|
@ -222,4 +246,49 @@ class NotifierTest extends TestCase { |
|
|
|
|
|
|
|
|
|
$this->assertEquals($notification, $return); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testPassedEvent(): void { |
|
|
|
|
/** @var INotification|MockObject $notification */ |
|
|
|
|
$notification = $this->createMock(INotification::class); |
|
|
|
|
|
|
|
|
|
$notification->expects($this->once()) |
|
|
|
|
->method('getApp') |
|
|
|
|
->willReturn(Application::APP_ID); |
|
|
|
|
$notification->expects($this->once()) |
|
|
|
|
->method('getSubject') |
|
|
|
|
->willReturn('calendar_reminder'); |
|
|
|
|
$notification->expects($this->once()) |
|
|
|
|
->method('getSubjectParameters') |
|
|
|
|
->willReturn([ |
|
|
|
|
'title' => 'Title of this event', |
|
|
|
|
'start_atom' => '2005-08-15T08:00:00+02:00' |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
$notification->expects($this->once()) |
|
|
|
|
->method('getMessageParameters') |
|
|
|
|
->willReturn([ |
|
|
|
|
'title' => 'Title of this event', |
|
|
|
|
'description' => null, |
|
|
|
|
'location' => 'NC Headquarters', |
|
|
|
|
'all_day' => false, |
|
|
|
|
'start_atom' => '2005-08-15T08:00:00+02:00', |
|
|
|
|
'start_is_floating' => false, |
|
|
|
|
'start_timezone' => 'Europe/Berlin', |
|
|
|
|
'end_atom' => '2005-08-15T13:00:00+02:00', |
|
|
|
|
'end_is_floating' => false, |
|
|
|
|
'end_timezone' => 'Europe/Berlin', |
|
|
|
|
'calendar_displayname' => 'Personal', |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
$notification->expects($this->once()) |
|
|
|
|
->method('setParsedSubject') |
|
|
|
|
->with('Title of this event (6 hours ago)') |
|
|
|
|
->willReturnSelf(); |
|
|
|
|
|
|
|
|
|
$this->expectException(AlreadyProcessedException::class); |
|
|
|
|
|
|
|
|
|
$return = $this->notifier->prepare($notification, 'en'); |
|
|
|
|
|
|
|
|
|
$this->assertEquals($notification, $return); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|