public function testCanPrepareSubscriptionNotification()
{
$object = $this->getTestObject();
$recipient = $this->mocks()->getUser(['language' => 'en']);
$mock = $this->getMock(SubscriptionsService::class, ['getSubscriptions'], [], '', false);
$mock->expects($this->exactly(1))->method('getSubscriptions')->will($this->returnValue([$recipient->guid => ['test_method', 'bad_method']]));
$this->subscriptions = $mock;
$this->session->setLoggedInUser($this->actor);
$event = new SubscriptionNotificationEvent($object, 'test_event');
$this->hooks->registerHandler('prepare', 'notification', function ($hook, $type, $notification) {
$notification->prepare_hook = true;
return $notification;
});
$this->hooks->registerHandler('prepare', "notification:{$event->getDescription()}", function ($hook, $type, $notification) {
$notification->granular_prepare_hook = true;
return $notification;
});
$this->hooks->registerHandler('format', 'notification:test_method', function ($hook, $type, $notification) {
$notification->format_hook = true;
return $notification;
});
$this->hooks->registerHandler('send', 'notification:test_method', function ($hook, $type, $return, $params) {
$notification = $params['notification'];
$this->assertTrue($notification->prepare_hook);
$this->assertTrue($notification->granular_prepare_hook);
$this->assertTrue($notification->format_hook);
return true;
});
$this->setupServices();
$this->notifications->registerMethod('test_method');
$this->notifications->registerEvent($object->getType(), $object->getSubtype(), ['test_event']);
$this->notifications->enqueueEvent('test_event', $object->getType(), $object);
$this->session->removeLoggedInUser();
$this->assertEquals(1, $this->notifications->processQueue($this->time + 10));
}