You are here

public function EntityIdTest::testUpdateByNodeId in Feeds 8.3

Tests updating an existing node using node ID.

File

tests/src/Kernel/EntityIdTest.php, line 61

Class

EntityIdTest
Tests for inserting and updating entity ID's.

Namespace

Drupal\Tests\feeds\Kernel

Code

public function testUpdateByNodeId() {
  $feed_type = $this
    ->createFeedTypeForCsv([
    'title' => 'title',
    'beta' => 'beta',
  ], [
    'processor_configuration' => [
      'update_existing' => ProcessorInterface::UPDATE_EXISTING,
      'values' => [
        'type' => 'article',
      ],
    ],
    'mappings' => [
      [
        'target' => 'title',
        'map' => [
          'value' => 'title',
        ],
      ],
      [
        'target' => 'nid',
        'map' => [
          'value' => 'beta',
        ],
        'unique' => [
          'value' => TRUE,
        ],
      ],
    ],
  ]);

  // Create a node with ID 42.
  $node = Node::create([
    'nid' => 42,
    'title' => 'Foo',
    'type' => 'article',
  ]);
  $node
    ->save();

  // Import data.
  $feed = $this
    ->createFeed($feed_type
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/csv/content.csv',
  ]);
  $feed
    ->import();
  $this
    ->assertNodeCount(2);

  // Ensure that the title got updated.
  $node = $this
    ->reloadEntity($node);
  $this
    ->assertEquals('Lorem ipsum', $node->title->value);
}