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

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

    public function testCanProcessSubscriptionNotificationsQueue()
    {
        $object = $this->getTestObject();
        $call_count = 0;
        $recipient = $this->mocks()->getUser();
        $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->translator->addTranslation('en', ['notification:body' => 'Link: %s', 'notification:subject' => 'From: %s']);
        $this->hooks->registerHandler('send', 'notification:test_method', function ($hook, $type, $return, $params) use(&$call_count, $event, $recipient) {
            $call_count++;
            $this->assertInstanceOf(Notification::class, $params['notification']);
            $this->assertEquals($this->translator->translate('notification:subject', [$event->getActor()->name], $recipient->language), $params['notification']->subject);
            $this->assertEquals($this->translator->translate('notification:body', [$event->getObject()->getURL()], $recipient->language), $params['notification']->body);
            $this->assertEquals($event, $params['event']);
            return true;
        });
        $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);
        $event = $this->queue->dequeue();
        $this->assertInstanceOf(SubscriptionNotificationEvent::class, $event);
        $this->assertEquals(elgg_get_logged_in_user_entity(), $event->getActor());
        $this->assertEquals($object, $event->getObject());
        $this->assertEquals("test_event:{$object->getType()}:{$object->getSubtype()}", $event->getDescription());
        $this->notifications->enqueueEvent('test_event', $object->getType(), $object);
        $this->assertEquals(1, $this->queue->size());
        $deliveries = ["test_event:{$object->getType()}:{$object->getSubtype()}" => [$recipient->guid => ['test_method' => true, 'bad_method' => false]]];
        $this->session->removeLoggedInUser();
        $result = $this->notifications->processQueue($this->time + 10, true);
        $this->assertEquals(1, $call_count);
        $this->assertEquals($deliveries, $result);
    }