public function DaysTest::testFetch in Message 8
Tests the fetch method.
@covers ::fetch
File
- tests/src/ Kernel/ Plugin/ MessagePurge/ DaysTest.php, line 64 
Class
- DaysTest
- Integration tests for the 'days' purge plugin.
Namespace
Drupal\Tests\message\Kernel\Plugin\MessagePurgeCode
public function testFetch() {
  $configuration = [
    'weight' => 4,
    'data' => [
      'days' => 2,
    ],
  ];
  $this
    ->createPlugin($configuration);
  // No IDs should return if there are no messages.
  $this
    ->assertEquals([], $this->plugin
    ->fetch($this->template));
  // 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
      ->save();
    $messages[$i] = $message;
  }
  // None should be returned as they are all newer than 2 days.
  $this
    ->createPlugin($configuration);
  $this
    ->assertEquals([], $this->plugin
    ->fetch($this->template));
  // Set message 3 to be 3 days old.
  $messages[3]
    ->set('created', $this->timeService
    ->getRequestTime() - 86400 * 3);
  $messages[3]
    ->save();
  $this
    ->createPlugin($configuration);
  $this
    ->assertEquals([
    3 => 3,
  ], $this->plugin
    ->fetch($this->template));
}