DigestActionsTest.php in Message Digest 8
File
message_digest_ui/tests/src/Kernel/DigestActionsTest.php
View source
<?php
namespace Drupal\Tests\message_digest_ui\Kernel;
use Drupal\flag\FlagInterface;
use Drupal\Tests\message_subscribe_email\Kernel\MessageSubscribeEmailTestBase;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class DigestActionsTest extends MessageSubscribeEmailTestBase {
use TaxonomyTestTrait;
protected $actionManager;
protected $actionStorage;
protected $terms;
public static $modules = [
'message_digest',
'options',
'field',
'taxonomy',
];
public function setUp() {
parent::setUp();
$this
->installEntitySchema('taxonomy_term');
$this
->installConfig([
'message_digest',
]);
$this->container
->get('plugin.message_notify.notifier.manager')
->clearCachedDefinitions();
$this->actionManager = $this->container
->get('plugin.manager.action');
$this->actionStorage = $this->container
->get('entity_type.manager')
->getStorage('action');
$this->container
->get('module_installer')
->install([
'message_digest_ui',
]);
$this->actionManager
->clearCachedDefinitions();
$this
->installConfig([
'message_digest_ui',
]);
$this->container
->get('account_switcher')
->switchTo($this->users[2]);
assert($this->container
->get('entity_type.manager')
->getStorage('field_storage_config')
->load('flagging.message_digest'));
$vocabulary = $this
->createVocabulary();
$this->terms[] = $this
->createTerm($vocabulary);
$this->terms[] = $this
->createTerm($vocabulary);
}
public function testActionsNode($action_id, $interval_plugin, $flag_id) {
$action = $this->actionStorage
->load($action_id);
$plugin = $action
->getPlugin();
$flag = $this->flagService
->getFlagById($flag_id);
$entity = $this
->getTestEntity($flag);
$this->flagService
->flag($flag, $entity, $this->users[2]);
$plugin
->execute($entity);
$flagging = $this->flagService
->getFlagging($flag, $entity, $this->users[2]);
$this
->assertEquals($interval_plugin, $flagging->message_digest->value);
}
public function providerTestActionsNode() {
$cases = [];
$flags = [
'email_node',
'email_user',
'email_term',
];
foreach ([
'immediate',
'daily',
'weekly',
] as $interval) {
foreach ($flags as $flag_id) {
$cases[] = [
'message_digest_interval.' . $flag_id . '.' . $interval,
$interval === 'immediate' ? '0' : 'message_digest:' . $interval,
$flag_id,
];
}
}
return $cases;
}
protected function getTestEntity(FlagInterface $flag) {
switch ($flag
->getFlaggableEntityTypeId()) {
case 'node':
return $this->nodes[1];
case 'taxonomy_term':
return $this->terms[1];
case 'user':
return $this->users[1];
}
}
}