You are here

public function JsonTest::testMissingProperties in Migrate Plus 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php \Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_parser\JsonTest::testMissingProperties()

Tests missing properties in json file.

@dataProvider jsonBaseDataProvider

Parameters

string $file: File name in tests/data/ directory of this module.

array $ids: Array of ids to pass to the plugin.

array $fields: Array of fields to pass to the plugin.

array $expected: Expected array from json decoded file.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Exception

File

tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php, line 36

Class

JsonTest
Test of the data_parser Json migrate_plus plugin.

Namespace

Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_parser

Code

public function testMissingProperties($file, array $ids, array $fields, array $expected) {
  $path = $this->container
    ->get('module_handler')
    ->getModule('migrate_plus')
    ->getPath();
  $url = $path . '/tests/data/' . $file;

  /** @var \Drupal\migrate_plus\DataParserPluginManager $plugin_manager */
  $plugin_manager = $this->container
    ->get('plugin.manager.migrate_plus.data_parser');
  $conf = [
    'plugin' => 'url',
    'data_fetcher_plugin' => 'file',
    'data_parser_plugin' => 'json',
    'destination' => 'node',
    'urls' => [
      $url,
    ],
    'ids' => $ids,
    'fields' => $fields,
    'item_selector' => NULL,
  ];
  $json_parser = $plugin_manager
    ->createInstance('json', $conf);
  $data = [];
  foreach ($json_parser as $item) {
    $data[] = $item;
  }
  $this
    ->assertEquals($expected, $data);
}