You are here

public function DaysTest::testProcess in Message 8

Same name in this branch
  1. 8 tests/src/Unit/Plugin/MessagePurge/DaysTest.php \Drupal\Tests\message\Unit\Plugin\MessagePurge\DaysTest::testProcess()
  2. 8 tests/src/Kernel/Plugin/MessagePurge/DaysTest.php \Drupal\Tests\message\Kernel\Plugin\MessagePurge\DaysTest::testProcess()

Tests the processing of messages to be purged.

@covers ::process

File

tests/src/Kernel/Plugin/MessagePurge/DaysTest.php, line 101

Class

DaysTest
Integration tests for the 'days' purge plugin.

Namespace

Drupal\Tests\message\Kernel\Plugin\MessagePurge

Code

public function testProcess() {

  // Add some message using this template.

  /** @var \Drupal\message\MessageInterface[] $messages */
  $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;
  }

  // Verify the messages are there.
  $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));
}