public function SkipNewTest::testSkipNewAndSkipExisting in Feeds 8.3
Tests skip new items without update existing as well.
File
- tests/
src/ Kernel/ SkipNewTest.php, line 117
Class
- SkipNewTest
- Tests the feature of creating/skipping new items.
Namespace
Drupal\Tests\feeds\KernelCode
public function testSkipNewAndSkipExisting() {
// Configure that new items should not be imported and that existing items
// should not be updated.
$feed_type = $this
->createFeedTypeForThisTest([
'insert_new' => ProcessorInterface::SKIP_NEW,
'update_existing' => ProcessorInterface::SKIP_EXISTING,
]);
// Create two nodes whose title is in the feed.
$node1 = Node::create([
'type' => 'article',
'title' => 'Dries Buytaert: Eén using Drupal',
'body' => 'Foo',
]);
$node1
->save();
$node2 = Node::create([
'type' => 'article',
'title' => 'NodeOne: The new Feeds module',
'body' => 'Feeds exists for more than a decade now.',
]);
$node2
->save();
// Create a feed and import.
// No nodes should be created nor updated.
$feed = $this
->createFeed($feed_type
->id(), [
'source' => $this
->resourcesPath() . '/rss/drupalplanet.rss2',
]);
$feed
->import();
// Assert no created nodes and two nodes in total.
$this
->assertEquals(0, $feed
->getItemCount());
$this
->assertNodeCount(2);
$this
->assertEquals(0, $this->processState->created);
$this
->assertEquals(0, $this->processState->updated);
// All items should have been skipped.
$this
->assertEquals(25, $this->processState->skipped);
// Assert that the existing nodes did not change and were not touched by
// Feeds.
$node1 = $this
->reloadEntity($node1);
$this
->assertEquals('Foo', $node1->body->value);
$this
->assertEmpty($node1->feeds_item);
$node2 = $this
->reloadEntity($node2);
$this
->assertEquals('Feeds exists for more than a decade now.', $node2->body->value);
$this
->assertEmpty($node2->feeds_item);
}