Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / migrate_plus / tests / src / Kernel / Plugin / migrate_plus / data_parser / SimpleXmlTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_parser;
4
5 use Drupal\KernelTests\KernelTestBase;
6
7 /**
8  * Test of the data_parser SimpleXml migrate_plus plugin.
9  *
10  * @group migrate_plus
11  */
12 class SimpleXmlTest extends KernelTestBase {
13
14   public static $modules = ['migrate', 'migrate_plus'];
15
16   /**
17    * Tests reducing single values.
18    *
19    * @throws \Drupal\Component\Plugin\Exception\PluginException
20    * @throws \Exception
21    */
22   public function testReduceSingleValue() {
23     $path = $this->container
24       ->get('module_handler')
25       ->getModule('migrate_plus')
26       ->getPath();
27     $url = $path . '/tests/data/simple_xml_reduce_single_value.xml';
28
29     /** @var \Drupal\migrate_plus\DataParserPluginManager $plugin_manager */
30     $plugin_manager = $this->container
31       ->get('plugin.manager.migrate_plus.data_parser');
32     $conf = [
33       'plugin' => 'url',
34       'data_fetcher_plugin' => 'file',
35       'data_parser_plugin' => 'simple_xml',
36       'destination' => 'node',
37       'urls' => [$url],
38       'ids' => ['id' => ['type' => 'integer']],
39       'fields' => [
40         [
41           'name' => 'id',
42           'label' => 'Id',
43           'selector' => '@id',
44         ],
45         [
46           'name' => 'values',
47           'label' => 'Values',
48           'selector' => 'values',
49         ],
50       ],
51       'item_selector' => '/items/item',
52     ];
53     $parser = $plugin_manager->createInstance('simple_xml', $conf);
54
55     $data = [];
56     foreach ($parser as $item) {
57       $values = [];
58       foreach ($item['values'] as $value) {
59         $values[] = (string) $value;
60       }
61       $data[] = $values;
62     }
63
64     $expected = [
65       [
66         'Value 1',
67         'Value 2',
68       ],
69       [
70         'Value 1 (single)',
71       ],
72     ];
73
74     $this->assertEquals($expected, $data);
75   }
76
77 }