ExpireTest.php in Feeds 8.3
File
tests/src/Functional/ExpireTest.php
View source
<?php
namespace Drupal\Tests\feeds\Functional;
use Drupal\feeds\FeedTypeInterface;
use Drupal\feeds\Plugin\Type\Processor\ProcessorInterface;
class ExpireTest extends FeedsBrowserTestBase {
protected $feedType;
protected function setUp() {
parent::setUp();
$this->feedType = $this
->createFeedType([
'fetcher' => 'directory',
'fetcher_configuration' => [
'allowed_extensions' => 'atom rss rss1 rss2 opml xml',
],
'processor_configuration' => [
'authorize' => FALSE,
'update_existing' => ProcessorInterface::UPDATE_EXISTING,
'values' => [
'type' => 'article',
],
'expire' => 3600,
'skip_hash_check' => TRUE,
],
]);
}
public function testExpireItemsWithBatch() {
$feed = $this
->createFeed($this->feedType
->id(), [
'source' => $this
->resourcesPath() . '/rss/googlenewstz.rss2',
]);
$this
->batchImport($feed);
$feed = $this
->reloadFeed($feed);
static::assertEquals(6, $feed
->getItemCount());
$this
->assertNodeCount(6);
\Drupal::database()
->update('node__feeds_item')
->fields([
'feeds_item_imported' => $this->container
->get('datetime.time')
->getRequestTime() - 3601,
])
->execute();
$feed
->setSource($this
->resourcesPath() . '/rss/googlenewstz_missing.rss2');
$feed
->save();
$this
->batchImport($feed);
$feed = $this
->reloadFeed($feed);
$this
->assertText('Expired 1 items.');
static::assertEquals(5, $feed
->getItemCount());
$this
->assertNodeCount(5);
$this
->assertFalse($feed
->isLocked());
}
public function testExpireItemsWithCron() {
$this
->markTestIncomplete('Expiring items on cron runs is not implemented yet');
$this->feedType
->setImportPeriod(FeedTypeInterface::SCHEDULE_CONTINUOUSLY);
$this->feedType
->save();
$feed = $this
->createFeed($this->feedType
->id(), [
'source' => $this
->resourcesPath() . '/rss/googlenewstz.rss2',
]);
$this
->cronRun();
$feed = $this
->reloadFeed($feed);
static::assertEquals(6, $feed
->getItemCount());
$this
->assertNodeCount(6);
\Drupal::database()
->update('node__feeds_item')
->fields([
'feeds_item_imported' => $this->container
->get('datetime.time')
->getRequestTime() - 3601,
])
->execute();
$this
->cronRun();
$feed = $this
->reloadFeed($feed);
static::assertEquals(0, $feed
->getItemCount());
$this
->assertNodeCount(0);
$this
->assertFalse($feed
->isLocked());
}
}