3 namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_parser;
5 use Drupal\KernelTests\KernelTestBase;
8 * Test of the data_parser Json migrate_plus plugin.
12 class JsonTest extends KernelTestBase {
14 public static $modules = ['migrate', 'migrate_plus'];
17 * Tests missing properties in json file.
20 * File name in tests/data/ directory of this module.
22 * Array of ids to pass to the plugin.
23 * @param array $fields
24 * Array of fields to pass to the plugin.
25 * @param array $expected
26 * Expected array from json decoded file.
28 * @dataProvider jsonBaseDataProvider
30 * @throws \Drupal\Component\Plugin\Exception\PluginException
33 public function testMissingProperties($file, array $ids, array $fields, array $expected) {
34 $path = $this->container
35 ->get('module_handler')
36 ->getModule('migrate_plus')
38 $url = $path . '/tests/data/' . $file;
40 /** @var \Drupal\migrate_plus\DataParserPluginManager $plugin_manager */
41 $plugin_manager = $this->container
42 ->get('plugin.manager.migrate_plus.data_parser');
45 'data_fetcher_plugin' => 'file',
46 'data_parser_plugin' => 'json',
47 'destination' => 'node',
51 'item_selector' => NULL,
53 $json_parser = $plugin_manager->createInstance('json', $conf);
56 foreach ($json_parser as $item) {
60 $this->assertEquals($expected, $data);
64 * Provides multiple test cases for the testMissingProperty method.
69 public function jsonBaseDataProvider() {
71 'missing properties' => [
72 'file' => 'missing_properties.json',
73 'ids' => ['id' => ['type' => 'integer']],
83 'selector' => '/title',
86 'name' => 'video_url',
87 'label' => 'Video url',
88 'selector' => '/video/url',
95 'video_url' => 'https://localhost/',
100 'video_url' => 'https://localhost/',
104 'title' => 'Title 3',