DaysTest.php 1.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
<?php

namespace Drupal\Tests\message\Unit\Plugin\MessagePurge;

use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Queue\QueueInterface;
use Drupal\message\MessagePurgeInterface;
use Drupal\message\Plugin\MessagePurge\Days;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Unit tests for the days purge plugin.
 *
 * @coversDefaultClass \Drupal\message\Plugin\MessagePurge\Days
 *
 * @group Message
 */
class DaysTest extends UnitTestCase {

  /**
   * Test processing zero message.
   *
   * @covers ::process
   */
  public function testProcessNone() {
    $query = $this->prophesize(QueryInterface::class)->reveal();
    $request_stack = $this->prophesize(RequestStack::class)->reveal();
    $queue = $this->prophesize(QueueInterface::class);
    $queue->createItem(Argument::any())->shouldNotBeCalled();
    $plugin = new Days([], 'days', [], $query, $queue->reveal(), $request_stack);
    $plugin->process([]);
  }

  /**
   * Tests processing more than defined queue item limit.
   *
   * @covers ::process
   */
  public function testProcess() {
    $query = $this->prophesize(QueryInterface::class)->reveal();
    $request_stack = $this->prophesize(RequestStack::class)->reveal();
    $queue = $this->prophesize(QueueInterface::class);
    $queue->createItem(Argument::size(MessagePurgeInterface::MESSAGE_DELETE_SIZE))->shouldBeCalledTimes(1);
    $queue->createItem(Argument::size(1))->shouldBeCalledTimes(1);
    $plugin = new Days([], 'days', [], $query, $queue->reveal(), $request_stack);

    $messages = range(1, MessagePurgeInterface::MESSAGE_DELETE_SIZE + 1);
    $plugin->process($messages);
  }

}