View source
<?php
namespace Drupal\Tests\message_subscribe_email\Kernel;
use Drupal\message\Entity\Message;
use Drupal\message_subscribe\Subscribers\DeliveryCandidate;
class MessageSubscribeEmailNotificationsTest extends MessageSubscribeEmailTestBase {
public function setUp() {
parent::setUp();
$flag = $this->flagService
->getFlagById('subscribe_node');
$this->flagService
->flag($flag, $this->nodes[1], $this->users[1]);
}
public function testEmailNotifications() {
$message = Message::create([
'template' => $this->messageTemplate
->id(),
]);
$uids = $this->messageSubscribers
->getSubscribers($this->nodes[1], $message);
$expected_uids = [
$this->users[1]
->id() => new DeliveryCandidate([
'subscribe_node',
], [
'email',
], $this->users[1]
->id()),
];
$this
->assertEquals($expected_uids, $uids, 'All expected subscribers were fetched.');
$this->flagService
->unflag($this->flagService
->getFlagById('subscribe_node'), $this->nodes[1], $this->users[1]);
$this->flagService
->flag($this->flagService
->getFlagById('subscribe_node'), $this->nodes[2], $this->users[1]);
$this->users[1]->message_subscribe_email = 0;
$this->users[1]
->save();
$this->flagService
->flag($this->flagService
->getFlagById('subscribe_node'), $this->nodes[1], $this->users[1]);
$uids = $this->messageSubscribers
->getSubscribers($this->nodes[1], $message);
$expected_uids = [
$this->users[1]
->id() => new DeliveryCandidate([
'subscribe_node',
], [], $this->users[1]
->id()),
];
$this
->assertEquals($expected_uids, $uids, 'All expected subscribers were fetched.');
$context = [
'node' => [
$this->nodes[1]
->id(),
],
];
$uids = $this->messageSubscribers
->getSubscribers($this->nodes[2], $message, [], $context);
$this
->assertEquals($expected_uids, $uids);
}
public function testFlagActionAccess() {
$node = $this->nodes[1];
$user = $this->users[1];
$email_flag = $this->flagService
->getFlagById('email_node');
$subscribe_flag = $this->flagService
->getFlagById('subscribe_node');
$access = $email_flag
->actionAccess('flag', $user, $node);
$this
->assertTrue($access
->isAllowed());
$access = $email_flag
->actionAccess('unflag', $user);
$this
->assertTrue($access
->isAllowed());
$this->flagService
->unflag($subscribe_flag, $node, $user);
$access = $email_flag
->actionAccess('flag', $user, $node);
$this
->assertFalse($access
->isAllowed());
$access = $email_flag
->actionAccess('unflag', $user, $node);
$this
->assertTrue($access
->isAllowed());
}
}