You are here

public function FeedsEventsTest::testEventDispatchOrderOnExpire in Feeds 8.3

Tests the order in which events are dispatched on an expire.

File

tests/src/Kernel/FeedsEventsTest.php, line 178

Class

FeedsEventsTest
Tests for dispatching feeds events.

Namespace

Drupal\Tests\feeds\Kernel

Code

public function testEventDispatchOrderOnExpire() {

  // Import items first.
  $feed_type = $this
    ->createFeedTypeForCsv([
    'guid' => 'guid',
    'title' => 'title',
  ], [
    'processor_configuration' => [
      'authorize' => FALSE,
      'values' => [
        'type' => 'article',
      ],
      'expire' => 3600,
    ],
  ]);
  $feed = $this
    ->createFeed($feed_type
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/csv/content.csv',
  ]);
  $feed
    ->import();

  // Set imported time of all imported items to a timestamp in the past so
  // that they expire.
  for ($i = 1; $i <= 2; $i++) {
    $node = Node::load($i);
    $node->feeds_item->imported = \Drupal::service('datetime.time')
      ->getRequestTime() - 3601;
    $node
      ->save();
  }

  // Now expire items.
  $GLOBALS['feeds_test_events'] = [];
  $feed
    ->startBatchExpire();
  $batch =& batch_get();
  $batch['progressive'] = FALSE;
  batch_process();
  $this
    ->assertEventSubscriberMessageOrder([
    FeedsSubscriber::class . '::onInitExpire called',
    FeedsSubscriber::class . '::onExpire called',
    FeedsSubscriber::class . '::onInitExpire called',
    FeedsSubscriber::class . '::onExpire called',
  ]);
}