You are here

public function QuotaTest::testFetch in Message 8

Tests the fetch method.

@covers ::fetch

File

tests/src/Kernel/Plugin/MessagePurge/QuotaTest.php, line 56

Class

QuotaTest
Integration tests for the 'quota' purge plugin.

Namespace

Drupal\Tests\message\Kernel\Plugin\MessagePurge

Code

public function testFetch() {
  $configuration = [
    'weight' => 4,
    'data' => [
      'quota' => 10,
    ],
  ];
  $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.
  foreach (range(1, 5) as $i) {
    $message = Message::create([
      'template' => $this->template
        ->id(),
    ]);
    $message
      ->save();
  }

  // None should be returned as there are less than 10.
  $this
    ->createPlugin($configuration);
  $this
    ->assertEquals([], $this->plugin
    ->fetch($this->template));

  // Set quota to 3.
  $configuration['data']['quota'] = 3;
  $this
    ->createPlugin($configuration);
  $this
    ->assertEquals([
    1 => 1,
    2 => 2,
  ], $this->plugin
    ->fetch($this->template));
}