public function UpdateNonExistentTest::testDeleteNonExistentItemsWithBatch in Feeds 8.3
Tests 'Delete non-existent' option using a Batch.
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' and when performing an import using the UI.
File
- tests/
src/ Functional/ UpdateNonExistentTest.php, line 114
Class
- UpdateNonExistentTest
- Tests the feature of updating items that are no longer available in the feed.
Namespace
Drupal\Tests\feeds\FunctionalCode
public function testDeleteNonExistentItemsWithBatch() {
// 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',
]);
$this
->batchImport($feed);
// Assert that 6 nodes have been created.
$feed = $this
->reloadFeed($feed);
$this
->assertText('Created 6 Article items.');
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
->batchImport($feed);
// Assert that one node is removed.
$feed = $this
->reloadFeed($feed);
$this
->assertText('Cleaned 1 Article.');
static::assertEquals(5, $feed
->getItemCount());
$this
->assertNodeCount(5);
// Re-import the original feed to import the removed node again.
$feed
->setSource($this
->resourcesPath() . '/rss/googlenewstz.rss2');
$feed
->save();
$this
->batchImport($feed);
$feed = $this
->reloadFeed($feed);
$this
->assertText('Created 1 Article.');
static::assertEquals(6, $feed
->getItemCount());
$this
->assertNodeCount(6);
}