You are here

public function CSVTest::fields in Migrate Source CSV 8

Tests that fields have a machine name and description.

@test

@covers ::fields

File

tests/src/Unit/Plugin/migrate/source/CSVTest.php, line 243
Code for CSVTest.php.

Class

CSVTest
@coversDefaultClass \Drupal\migrate_source_csv\Plugin\migrate\source\CSV

Namespace

Drupal\Tests\migrate_source_csv\Unit\Plugin\migrate\source

Code

public function fields() {
  $configuration = [
    'path' => $this->happyPath,
    'keys' => [
      'id',
    ],
    'header_row_count' => 1,
  ];
  $fields = [
    'id' => 'identifier',
    'first_name' => 'User first name',
  ];
  $expected = $fields + [
    'last_name' => 'last_name',
    'email' => 'email',
    'country' => 'country',
    'ip_address' => 'ip_address',
  ];
  $csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->plugin);
  $csv = new CSV($configuration + [
    'fields' => $fields,
  ], $this->pluginId, $this->pluginDefinition, $this->plugin);
  $this
    ->assertArrayEquals($expected, $csv
    ->fields());
  $column_names = [
    0 => [
      'id' => 'identifier',
    ],
    2 => [
      'first_name' => 'User first name',
    ],
  ];
  $csv = new CSV($configuration + [
    'fields' => $fields,
    'column_names' => $column_names,
  ], $this->pluginId, $this->pluginDefinition, $this->plugin);
  $this
    ->assertArrayEquals($fields, $csv
    ->fields());
}