You are here

public function FieldTest::testListIntegerTargetUnique in Feeds 8.3

Tests if list integer fields can be used as unique target.

File

tests/src/Kernel/Feeds/Target/FieldTest.php, line 353

Class

FieldTest
Tests for mapping to text and numeric fields.

Namespace

Drupal\Tests\feeds\Kernel\Feeds\Target

Code

public function testListIntegerTargetUnique() {

  // Add a list integer field.
  $this
    ->createFieldWithStorage('field_jota', [
    'type' => 'list_integer',
    'storage' => [
      'settings' => [
        'allowed_values' => [
          1 => 'One',
          2 => 'Two',
        ],
      ],
    ],
  ]);

  // Reload feed type to reset target plugin cache.
  $this->feedType = $this
    ->reloadEntity($this->feedType);

  // Add custom source and add mapping for this field.
  $this->feedType
    ->addCustomSource('guid', [
    'label' => 'GUID',
    'value' => 'guid',
  ]);
  $this->feedType
    ->addMapping([
    'target' => 'field_jota',
    'map' => [
      'value' => 'guid',
    ],
    'unique' => [
      'value' => TRUE,
    ],
  ]);

  // And test!
  $this
    ->testTargetUnique('field_jota', 'value', 6, [
    'field_jota' => 1,
  ]);
}