Elgg\Notifications\NotificationsServiceTestCase::testCanUseHooksBeforeAndAfterInstantNotificationsQueue PHP Метод

testCanUseHooksBeforeAndAfterInstantNotificationsQueue() публичный Метод

    public function testCanUseHooksBeforeAndAfterInstantNotificationsQueue()
    {
        $object = $this->getTestObject();
        $from = $this->mocks()->getUser();
        $to1 = $this->mocks()->getUser();
        $to2 = $this->mocks()->getUser();
        create_metadata($to2->guid, 'notification:method:test_method', true, '', $to2->guid, ACCESS_PUBLIC);
        $subject = 'Test message';
        $body = 'Lorem ipsum';
        $subscribers = [$to1->guid => [], $to2->guid => ['test_method']];
        $event = new InstantNotificationEvent($object, 'test_event', $from);
        $before_call_count = 0;
        $after_call_count = 0;
        $this->hooks->registerHandler('send:before', 'notifications', function ($hook, $type, $return, $params) use(&$before_call_count, $event, $subscribers) {
            $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) {
            $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->assertEquals([], notify_user([$to1->guid, $to2->guid, 0], $from->guid, $subject, $body, ['object' => $object, 'summary' => $subject, 'action' => 'test_event']));
        $this->assertEquals(1, $before_call_count);
        $this->assertEquals(1, $after_call_count);
    }