public function EntityIdTest::testNoNodeIdChange in Feeds 8.3
Tests that node ID's don't change and that existing nodes are not hijacked.
File
- tests/
src/ Kernel/ EntityIdTest.php, line 108
Class
- EntityIdTest
- Tests for inserting and updating entity ID's.
Namespace
Drupal\Tests\feeds\KernelCode
public function testNoNodeIdChange() {
// Create two existing articles.
$node1 = Node::create([
'title' => 'Lorem ipsum',
'type' => 'article',
]);
$node1
->save();
// Create an existing article with ID 32.
$node32 = Node::create([
'nid' => 32,
'title' => 'Foo',
'type' => 'article',
]);
$node32
->save();
// Create a feed type, update by title.
$feed_type = $this
->createFeedTypeForCsv([
'title' => 'title',
'beta' => 'beta',
], [
'processor_configuration' => [
'update_existing' => ProcessorInterface::UPDATE_EXISTING,
'values' => [
'type' => 'article',
],
],
'mappings' => [
[
'target' => 'title',
'map' => [
'value' => 'title',
],
'unique' => [
'value' => TRUE,
],
],
[
'target' => 'nid',
'map' => [
'value' => 'beta',
],
],
],
]);
// Import data.
$feed = $this
->createFeed($feed_type
->id(), [
'source' => $this
->resourcesPath() . '/csv/content.csv',
]);
$feed
->import();
$this
->assertNodeCount(2);
// Ensure that node 42 doesn't exist.
$this
->assertNull(Node::load(42));
// Ensure that node 32 is still called 'Foo'.
$node32 = $this
->reloadEntity($node32);
$this
->assertEquals('Foo', $node32->title->value);
// Ensure that there are no SQL warnings.
$messages = \Drupal::messenger()
->all();
foreach ($messages['warning'] as $warning) {
$this
->assertStringNotContainsString('SQLSTATE', $warning);
}
}