You are here

public function UpdateExistingTest::testImportIntoFieldWithDefaultValue in Feeds 8.3

Tests importing into a base field that has a default value.

File

tests/src/Kernel/UpdateExistingTest.php, line 185

Class

UpdateExistingTest
Tests the feature of updating items.

Namespace

Drupal\Tests\feeds\Kernel

Code

public function testImportIntoFieldWithDefaultValue() {
  $this
    ->installConfig([
    'field',
  ]);

  // Enable a boolean field with a default value.
  \Drupal::state()
    ->set('entity_test.boolean_field', TRUE);
  $this
    ->installEntitySchema('entity_test_bundle');
  $this
    ->installEntitySchema('feeds_test_entity_test_no_links');
  $this
    ->installEntitySchema('user');

  // Create a user.
  $account = $this
    ->createUser();

  // Create a feed type.
  $feed_type = $this
    ->createFeedTypeForCsv([
    'title' => 'title',
    'epsilon' => 'epsilon',
  ], [
    'processor' => 'entity:feeds_test_entity_test_no_links',
    'processor_configuration' => [
      'owner_id' => $account
        ->id(),
      'values' => [
        'type' => 'feeds_test_entity_test_no_links',
      ],
    ],
    'mappings' => [
      [
        'target' => 'name',
        'map' => [
          'value' => 'title',
        ],
        'unique' => [
          'value' => TRUE,
        ],
      ],
      [
        'target' => 'boolean_field',
        'map' => [
          'value' => 'epsilon',
        ],
      ],
    ],
  ]);

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

  /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $entity_storage */
  $entity_storage = $this->entityTypeManager
    ->getStorage('feeds_test_entity_test_no_links');
  $entity = $entity_storage
    ->load(1);
  $this
    ->assertEquals('1', $entity->boolean_field->value);
}