X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmigrate_plus%2Ftests%2Fsrc%2FKernel%2FPlugin%2Fmigrate_plus%2Fdata_parser%2FJsonTest.php;fp=web%2Fmodules%2Fcontrib%2Fmigrate_plus%2Ftests%2Fsrc%2FKernel%2FPlugin%2Fmigrate_plus%2Fdata_parser%2FJsonTest.php;h=2fb4f2458dd4b937e75233dc642e90f6468a5939;hp=0000000000000000000000000000000000000000;hb=059867c3f96750652c80f39e44c442a58c2549ee;hpb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2 diff --git a/web/modules/contrib/migrate_plus/tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php b/web/modules/contrib/migrate_plus/tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php new file mode 100644 index 000000000..2fb4f2458 --- /dev/null +++ b/web/modules/contrib/migrate_plus/tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php @@ -0,0 +1,112 @@ +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); + } + + /** + * Provides multiple test cases for the testMissingProperty method. + * + * @return array + * The test cases. + */ + public function jsonBaseDataProvider() { + return [ + 'missing properties' => [ + 'file' => 'missing_properties.json', + 'ids' => ['id' => ['type' => 'integer']], + 'fields' => [ + [ + 'name' => 'id', + 'label' => 'Id', + 'selector' => '/id', + ], + [ + 'name' => 'title', + 'label' => 'Title', + 'selector' => '/title', + ], + [ + 'name' => 'video_url', + 'label' => 'Video url', + 'selector' => '/video/url', + ], + ], + 'expected' => [ + [ + 'id' => '1', + 'title' => 'Title', + 'video_url' => 'https://localhost/', + ], + [ + 'id' => '2', + 'title' => '', + 'video_url' => 'https://localhost/', + ], + [ + 'id' => '3', + 'title' => 'Title 3', + 'video_url' => '', + ], + ], + ], + ]; + } + +}