public function ConfigEntityReferenceTest::testImportById in Feeds 8.3
Tests importing config entity references by ID.
File
- tests/
src/ Kernel/ Feeds/ Target/ ConfigEntityReferenceTest.php, line 59
Class
- ConfigEntityReferenceTest
- Tests for the config entity reference target.
Namespace
Drupal\Tests\feeds\Kernel\Feeds\TargetCode
public function testImportById() {
// Create a feed type, map to created field.
$feed_type = $this
->createFeedTypeForCsv([
'guid' => 'guid',
'title' => 'title',
'type' => 'type',
], [
'mappings' => array_merge($this
->getDefaultMappings(), [
[
'target' => 'field_entity_test_type',
'map' => [
'target_id' => 'type',
],
'settings' => [
'reference_by' => 'id',
],
],
]),
]);
// Import.
$feed = $this
->createFeed($feed_type
->id(), [
'source' => $this
->resourcesPath() . '/csv/content-with-config-reference.csv',
]);
$feed
->import();
// Assert two created nodes.
$this
->assertNodeCount(2);
// Test target id values of these nodes.
$expected_values = [
1 => 'test',
2 => 'test2',
];
foreach ($expected_values as $nid => $expected_value) {
$node = Node::load($nid);
$this
->assertEquals($expected_value, $node->field_entity_test_type->target_id);
}
}