Elgg\Notifications\NotificationsServiceTestCase::testCanUseHooksBeforeAndAfterSubscriptionNotificationsQueue PHP Method

testCanUseHooksBeforeAndAfterSubscriptionNotificationsQueue() public method

    public function testCanUseHooksBeforeAndAfterSubscriptionNotificationsQueue()
    {
        $object = $this->getTestObject();
        $before_call_count = 0;
        $after_call_count = 0;
        $recipient = $this->mocks()->getUser();
        $subscribers = [$recipient->guid => ['test_method', 'bad_method']];
        $mock = $this->getMock(SubscriptionsService::class, ['getSubscriptions'], [], '', false);
        $mock->expects($this->exactly(1))->method('getSubscriptions')->will($this->returnValue($subscribers));
        $this->subscriptions = $mock;
        $this->session->setLoggedInUser($this->actor);
        $event = new SubscriptionNotificationEvent($object, 'test_event');
        $this->hooks->registerHandler('send:before', 'notifications', function ($hook, $type, $return, $params) use(&$before_call_count, $event, $subscribers, $object) {
            $before_call_count++;
            $this->assertEquals($event, $params['event']);
            $this->assertEquals($subscribers, $params['subscriptions']);
            return false;
        });
        $this->hooks->registerHandler('send:after', 'notifications', function ($hook, $type, $return, $params) use(&$after_call_count, $event, $subscribers, $object) {
            $after_call_count++;
            $this->assertEquals($event, $params['event']);
            $this->assertEquals($subscribers, $params['subscriptions']);
            $this->assertEmpty($params['deliveries']);
        });
        $this->setupServices();
        $this->notifications->registerMethod('test_method');
        $this->notifications->registerEvent($object->getType(), $object->getSubtype(), ['test_event']);
        $this->assertEquals(0, $this->queue->size());
        $this->notifications->enqueueEvent('test_event', $object->getType(), $object);
        $this->assertEquals(1, $this->queue->size());
        $this->session->removeLoggedInUser();
        $this->assertEquals(1, $this->notifications->processQueue($this->time + 10));
        $this->assertEquals(1, $before_call_count);
        $this->assertEquals(1, $after_call_count);
    }