public function EntityIdTest::testInsertNodeId in Feeds 8.3
Tests creating a node where the source dictates the node ID.
File
- tests/
src/ Kernel/ EntityIdTest.php, line 18
Class
- EntityIdTest
- Tests for inserting and updating entity ID's.
Namespace
Drupal\Tests\feeds\KernelCode
public function testInsertNodeId() {
$feed_type = $this
->createFeedTypeForCsv([
'title' => 'title',
'beta' => 'beta',
], [
'mappings' => [
[
'target' => 'title',
'map' => [
'value' => 'title',
],
],
[
'target' => 'nid',
'map' => [
'value' => 'beta',
],
],
],
]);
// Import data.
$feed = $this
->createFeed($feed_type
->id(), [
'source' => $this
->resourcesPath() . '/csv/content.csv',
]);
$feed
->import();
$this
->assertNodeCount(2);
// Check the imported values.
$node = Node::load(42);
$this
->assertEquals('Lorem ipsum', $node->title->value);
$node = Node::load(32);
$this
->assertEquals('Ut wisi enim ad minim veniam', $node->title->value);
// Ensure that an other import doesn't result into SQL errors.
$feed
->import();
// Ensure that there are no SQL warnings.
$messages = \Drupal::messenger()
->all();
foreach ($messages['warning'] as $warning) {
$this
->assertStringNotContainsString('SQLSTATE', $warning);
}
}