Elgg\Notifications\NotificationsServiceTestCase::testCanAlterSubscriptionNotificationTranslations PHP Method

testCanAlterSubscriptionNotificationTranslations() public method

    public function testCanAlterSubscriptionNotificationTranslations()
    {
        $object = $this->getTestObject();
        $call_count = 0;
        $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->translator->addTranslation('en', ["notification:{$event->getDescription()}:body" => '%s %s %s %s %s %s', "notification:{$event->getDescription()}:subject" => '%s %s']);
        $this->hooks->registerHandler('send', 'notification:test_method', function ($hook, $type, $return, $params) use(&$call_count, $event, $object, $recipient) {
            $call_count++;
            $object = $event->getObject();
            if ($object instanceof ElggEntity) {
                $display_name = $object->getDisplayName();
                $container_name = '';
                $container = $object->getContainerEntity();
                if ($container) {
                    $container_name = $container->getDisplayName();
                }
            } else {
                $display_name = '';
                $container_name = '';
            }
            $this->assertInstanceOf(Notification::class, $params['notification']);
            $this->assertEquals($this->translator->translate("notification:{$event->getDescription()}:subject", [$event->getActor()->name, $display_name], $recipient->language), $params['notification']->subject);
            $this->assertEquals($this->translator->translate("notification:{$event->getDescription()}:body", [$recipient->name, $event->getActor()->name, $display_name, $container_name, $object->description, $object->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->notifications->enqueueEvent('test_event', $object->getType(), $object);
        $this->session->removeLoggedInUser();
        $this->notifications->processQueue($this->time + 10);
        $this->assertEquals(1, $call_count);
    }