public function UpdateNonExistentTest::testUnpublishNonExistentItemsWithCron in Feeds 8.3
Tests 'Unpublish non-existent' option using cron.
Tests that previously imported items that are no longer available in the feed get unpublished when the 'update_non_existent' setting is set to 'entity:unpublish_action:node' and when performing an import using cron.
File
- tests/
src/ Functional/ UpdateNonExistentTest.php, line 161
Class
- UpdateNonExistentTest
- Tests the feature of updating items that are no longer available in the feed.
Namespace
Drupal\Tests\feeds\FunctionalCode
public function testUnpublishNonExistentItemsWithCron() {
// Set 'update_non_existent' setting to 'unpublish'.
$config = $this->feedType
->getProcessor()
->getConfiguration();
$config['update_non_existent'] = 'entity:unpublish_action:node';
$this->feedType
->getProcessor()
->setConfiguration($config);
// 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();
// Reload feed and assert that 6 nodes have been created.
$feed = $this
->reloadFeed($feed);
static::assertEquals(6, $feed
->getItemCount());
$this
->assertNodeCount(6);
// Import an "updated" version of the file from which one item is removed.
$feed
->setSource($this
->resourcesPath() . '/rss/googlenewstz_missing.rss2');
$feed
->save();
$this
->cronRun();
// Assert that one node was unpublished.
$node = $this
->getNodeByTitle('Egypt, Hamas exchange fire on Gaza frontier, 1 dead - Reuters');
$this
->assertFalse($node
->isPublished());
// Manually publish the node.
$node->status = 1;
$node
->setTitle('Lorem');
$node
->save();
$this
->assertTrue($node
->isPublished(), 'Node is published');
// Import the same file again to ensure that the node does not get
// unpublished again (since the node was already unpublished during the
// previous import).
$this
->cronRun();
$node = $this
->reloadEntity($node);
$this
->assertTrue($node
->isPublished(), 'Node is not updated');
// Re-import the original feed to ensure the unpublished node is updated,
// even though the item is the same since the last time it was available in
// the feed. Fact is that the node was not available in the previous import
// and that should be seen as a change.
$feed = $this
->reloadFeed($feed);
$feed
->setSource($this
->resourcesPath() . '/rss/googlenewstz.rss2');
$feed
->save();
$this
->cronRun();
$node = $this
->reloadEntity($node);
static::assertEquals('Egypt, Hamas exchange fire on Gaza frontier, 1 dead - Reuters', $node
->getTitle());
}