DaysTest.php in Message 8
File
tests/src/Kernel/Plugin/MessagePurge/DaysTest.php
View source
<?php
namespace Drupal\Tests\message\Kernel\Plugin\MessagePurge;
use Drupal\KernelTests\KernelTestBase;
use Drupal\message\Entity\Message;
use Drupal\message\Entity\MessageTemplate;
class DaysTest extends KernelTestBase {
public static $modules = [
'message',
'user',
];
protected $plugin;
protected $template;
protected $timeService;
public function setUp() {
parent::setUp();
$this
->installEntitySchema('message');
$this->template = MessageTemplate::create([
'template' => 'foo',
]);
$this->template
->save();
$this->timeService = $this->container
->get('datetime.time');
}
public function testFetch() {
$configuration = [
'weight' => 4,
'data' => [
'days' => 2,
],
];
$this
->createPlugin($configuration);
$this
->assertEquals([], $this->plugin
->fetch($this->template));
$messages = [];
foreach (range(1, 5) as $i) {
$message = Message::create([
'template' => $this->template
->id(),
]);
$message
->save();
$messages[$i] = $message;
}
$this
->createPlugin($configuration);
$this
->assertEquals([], $this->plugin
->fetch($this->template));
$messages[3]
->set('created', $this->timeService
->getRequestTime() - 86400 * 3);
$messages[3]
->save();
$this
->createPlugin($configuration);
$this
->assertEquals([
3 => 3,
], $this->plugin
->fetch($this->template));
}
public function testProcess() {
$messages = [];
foreach (range(1, 5) as $i) {
$message = Message::create([
'template' => $this->template
->id(),
]);
$message
->set('created', $this->timeService
->getRequestTime() - 86400);
$message
->save();
$messages[$i] = $message;
}
$configuration = [
'weight' => 4,
'data' => [
'days' => 0,
],
];
$this
->createPlugin($configuration);
$this
->assertEquals(5, count($this->plugin
->fetch($this->template)));
$this->plugin
->process(array_keys($messages));
$this->container
->get('cron')
->run();
$this
->createPlugin($configuration);
$this
->assertEquals([], $this->plugin
->fetch($this->template));
}
protected function createPlugin(array $configuration) {
$this->plugin = $this->container
->get('plugin.manager.message.purge')
->createInstance('days', $configuration);
}
}
Classes
Name |
Description |
DaysTest |
Integration tests for the 'days' purge plugin. |