public function MessageDigestUiTest::testNotifiersDigest in Message Digest 8
Tests that notifiers are properly altered for digest users.
File
- message_digest_ui/
tests/ src/ Kernel/ MessageDigestUiTest.php, line 80
Class
- MessageDigestUiTest
- Basic tests for the Message Digest UI module.
Namespace
Drupal\Tests\message_digest_ui\KernelCode
public function testNotifiersDigest() {
// Set user 2 to receive daily digests.
$this->users[2]->message_digest = 'message_digest:daily';
$this->users[2]
->save();
$this
->assertEquals('message_digest:daily', $this->users[2]->message_digest->value);
// Subscribe users 2 and 3 to node 1.
$flag = $this->flagService
->getFlagById('subscribe_node');
$this->container
->set('current_user', $this->users[2]);
$this->flagService
->flag($flag, $this->nodes[1], $this->users[2]);
$this->container
->set('current_user', $this->users[3]);
$this->flagService
->flag($flag, $this->nodes[1], $this->users[3]);
// Subscribe user 3 to node 2, and set to digests.
$this->flagService
->flag($flag, $this->nodes[2], $this->users[3]);
$flaggings = $this->flagService
->getAllEntityFlaggings($this->nodes[2], $this->users[3]);
$this
->assertEquals(2, count($flaggings));
// User 3 should not have digests set for this node initially.
$this
->assertEmpty($flaggings[6]->message_digest->value);
// Set to receive digests for node 2.
$flaggings[6]->message_digest = 'message_digest:daily';
$flaggings[6]
->save();
// Verify that the corresponding email flagging has the user's digest set.
$flaggings = $this->flagService
->getAllEntityFlaggings($this->nodes[1], $this->users[2]);
$this
->assertEquals(2, count($flaggings));
$email_flag = $flaggings[2];
$this
->assertEquals('message_digest:daily', $email_flag->message_digest->value);
// Assert subscribers data.
$expected_uids = [
$this->users[2]
->id() => new DeliveryCandidate([
'subscribe_node',
], [
'message_digest:daily',
], $this->users[2]
->id()),
$this->users[3]
->id() => new DeliveryCandidate([
'subscribe_node',
], [
'email',
], $this->users[3]
->id()),
];
$message = Message::create([
'template' => $this->messageTemplate
->id(),
]);
$uids = $this->messageSubscribers
->getSubscribers($this->nodes[1], $message);
$this
->assertEquals($expected_uids, $uids, 'All expected subscribers were fetched.');
}