You are here

public function ExpireTest::testExpireItemsWithCron in Feeds 8.3

Tests expiring items using cron.

@todo implement feature for expiring items using cron.

File

tests/src/Functional/ExpireTest.php, line 88

Class

ExpireTest
Tests the expire feature.

Namespace

Drupal\Tests\feeds\Functional

Code

public function testExpireItemsWithCron() {
  $this
    ->markTestIncomplete('Expiring items on cron runs is not implemented yet');

  // Set the import period to run as often as possible.
  $this->feedType
    ->setImportPeriod(FeedTypeInterface::SCHEDULE_CONTINUOUSLY);
  $this->feedType
    ->save();

  // Create a feed and import first file.
  $feed = $this
    ->createFeed($this->feedType
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/rss/googlenewstz.rss2',
  ]);

  // Run cron to import.
  $this
    ->cronRun();

  // Assert that 6 nodes have been created.
  $feed = $this
    ->reloadFeed($feed);
  static::assertEquals(6, $feed
    ->getItemCount());
  $this
    ->assertNodeCount(6);

  // Set import time to be about an hour in the past.
  \Drupal::database()
    ->update('node__feeds_item')
    ->fields([
    'feeds_item_imported' => $this->container
      ->get('datetime.time')
      ->getRequestTime() - 3601,
  ])
    ->execute();

  // Run cron again.
  $this
    ->cronRun();

  // Assert that all nodes have been expired.
  $feed = $this
    ->reloadFeed($feed);
  static::assertEquals(0, $feed
    ->getItemCount());
  $this
    ->assertNodeCount(0);

  // And assert that the feed is no longer locked.
  $this
    ->assertFalse($feed
    ->isLocked());
}