public function UpdateNonExistentTest::testDeleteNonExistentItems in Feeds 8.3
Tests 'Delete non-existent' option.
Tests that previously imported items that are no longer available in the feed get deleted when the 'update_non_existent' setting is set to '_delete'.
File
- tests/
src/ Kernel/ UpdateNonExistentTest.php, line 144
Class
- UpdateNonExistentTest
- Tests the feature of updating items that are no longer available in the feed.
Namespace
Drupal\Tests\feeds\KernelCode
public function testDeleteNonExistentItems() {
// Set 'update_non_existent' setting to 'unpublish'.
$config = $this->feedType
->getProcessor()
->getConfiguration();
$config['update_non_existent'] = ProcessorInterface::DELETE_NON_EXISTENT;
$this->feedType
->getProcessor()
->setConfiguration($config);
$this->feedType
->save();
// Create a feed and import first file.
$feed = $this
->createFeed($this->feedType
->id(), [
'source' => $this
->resourcesPath() . '/rss/googlenewstz.rss2',
]);
$feed
->import();
// Assert that 6 nodes have been created.
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();
$feed
->import();
// Assert that one node is removed.
static::assertEquals(5, $feed
->getItemCount());
$this
->assertNodeCount(5);
// Assert that the clean list is empty for the feed.
$this
->assertCleanListEmpty($feed);
// Re-import the original feed to import the removed node again.
$feed
->setSource($this
->resourcesPath() . '/rss/googlenewstz.rss2');
$feed
->save();
$feed
->import();
static::assertEquals(6, $feed
->getItemCount());
$this
->assertNodeCount(6);
}