7fb3a918f836e1485c193a4f6076b0c7c9ef0d3e
[yaffs-website] / web / core / modules / menu_link_content / tests / src / Kernel / Plugin / migrate / source / MenuLinkTest.php
1 <?php
2
3 namespace Drupal\Tests\menu_link_content\Kernel\Plugin\migrate\source;
4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
7
8 /**
9  * Tests the menu link source plugin.
10  *
11  * @covers \Drupal\menu_link_content\Plugin\migrate\source\MenuLink
12  *
13  * @group menu_link_content
14  */
15 class MenuLinkTest extends MigrateSqlSourceTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['menu_link_content', 'migrate_drupal'];
21
22   /**
23    * {@inheritdoc}
24    */
25   public function providerSource() {
26     $tests = [];
27
28     // The source data.
29     $tests[0]['source_data']['menu_links'] = [
30       [
31         // Customized menu link, provided by system module.
32         'menu_name' => 'menu-test-menu',
33         'mlid' => 140,
34         'plid' => 0,
35         'link_path' => 'admin/config/system/cron',
36         'router_path' => 'admin/config/system/cron',
37         'link_title' => 'Cron',
38         'options' => [],
39         'module' => 'system',
40         'hidden' => 0,
41         'external' => 0,
42         'has_children' => 0,
43         'expanded' => 0,
44         'weight' => 0,
45         'depth' => 0,
46         'customized' => 1,
47         'p1' => '0',
48         'p2' => '0',
49         'p3' => '0',
50         'p4' => '0',
51         'p5' => '0',
52         'p6' => '0',
53         'p7' => '0',
54         'p8' => '0',
55         'p9' => '0',
56         'updated' => '0',
57         'description' => '',
58       ],
59       [
60         // D6 customized menu link, provided by menu module.
61         'menu_name' => 'menu-test-menu',
62         'mlid' => 141,
63         'plid' => 0,
64         'link_path' => 'node/141',
65         'router_path' => 'node/%',
66         'link_title' => 'Node 141',
67         'options' => [],
68         'module' => 'menu',
69         'hidden' => 0,
70         'external' => 0,
71         'has_children' => 0,
72         'expanded' => 0,
73         'weight' => 0,
74         'depth' => 0,
75         'customized' => 1,
76         'p1' => '0',
77         'p2' => '0',
78         'p3' => '0',
79         'p4' => '0',
80         'p5' => '0',
81         'p6' => '0',
82         'p7' => '0',
83         'p8' => '0',
84         'p9' => '0',
85         'updated' => '0',
86         'description' => '',
87       ],
88       [
89         // D6 non-customized menu link, provided by menu module.
90         'menu_name' => 'menu-test-menu',
91         'mlid' => 142,
92         'plid' => 0,
93         'link_path' => 'node/142',
94         'router_path' => 'node/%',
95         'link_title' => 'Node 142',
96         'options' => [],
97         'module' => 'menu',
98         'hidden' => 0,
99         'external' => 0,
100         'has_children' => 0,
101         'expanded' => 0,
102         'weight' => 0,
103         'depth' => 0,
104         'customized' => 0,
105         'p1' => '0',
106         'p2' => '0',
107         'p3' => '0',
108         'p4' => '0',
109         'p5' => '0',
110         'p6' => '0',
111         'p7' => '0',
112         'p8' => '0',
113         'p9' => '0',
114         'updated' => '0',
115         'description' => '',
116       ],
117       [
118         'menu_name' => 'menu-test-menu',
119         'mlid' => 138,
120         'plid' => 0,
121         'link_path' => 'admin',
122         'router_path' => 'admin',
123         'link_title' => 'Test 1',
124         'options' => ['attributes' => ['title' => 'Test menu link 1']],
125         'module' => 'menu',
126         'hidden' => 0,
127         'external' => 0,
128         'has_children' => 1,
129         'expanded' => 0,
130         'weight' => 15,
131         'depth' => 1,
132         'customized' => 1,
133         'p1' => '138',
134         'p2' => '0',
135         'p3' => '0',
136         'p4' => '0',
137         'p5' => '0',
138         'p6' => '0',
139         'p7' => '0',
140         'p8' => '0',
141         'p9' => '0',
142         'updated' => '0',
143         'description' => 'Test menu link 1',
144       ],
145       [
146         'menu_name' => 'menu-test-menu',
147         'mlid' => 139,
148         'plid' => 138,
149         'link_path' => 'admin/modules',
150         'router_path' => 'admin/modules',
151         'link_title' => 'Test 2',
152         'options' => ['attributes' => ['title' => 'Test menu link 2']],
153         'module' => 'menu',
154         'hidden' => 0,
155         'external' => 0,
156         'has_children' => 0,
157         'expanded' => 0,
158         'weight' => 12,
159         'depth' => 2,
160         'customized' => 1,
161         'p1' => '138',
162         'p2' => '139',
163         'p3' => '0',
164         'p4' => '0',
165         'p5' => '0',
166         'p6' => '0',
167         'p7' => '0',
168         'p8' => '0',
169         'p9' => '0',
170         'updated' => '0',
171         'description' => 'Test menu link 2',
172       ],
173       [
174         'menu_name' => 'menu-user',
175         'mlid' => 143,
176         'plid' => 0,
177         'link_path' => 'admin/build/menu-customize/navigation',
178         'router_path' => 'admin/build/menu-customize/%',
179         'link_title' => 'Navigation',
180         'options' => [],
181         'module' => 'menu',
182         'hidden' => 0,
183         'external' => 0,
184         'has_children' => 0,
185         'expanded' => 0,
186         'weight' => 0,
187         'depth' => 0,
188         'customized' => 0,
189         'p1' => '0',
190         'p2' => '0',
191         'p3' => '0',
192         'p4' => '0',
193         'p5' => '0',
194         'p6' => '0',
195         'p7' => '0',
196         'p8' => '0',
197         'p9' => '0',
198         'updated' => '0',
199         'description' => '',
200       ],
201     ];
202
203     // Add long link title attributes to source data.
204     $title = $this->getRandomGenerator()->string('500');
205     $tests[0]['source_data']['menu_links'][0]['options']['attributes']['title'] = $title;
206
207     // Build the expected results.
208     $expected = $tests[0]['source_data']['menu_links'];
209
210     // Add long link title attributes to expected results.
211     $expected[0]['description'] = Unicode::truncate($title, 255);
212
213     // Don't expect D6 menu link to a custom menu, provided by menu module.
214     unset($expected[5]);
215
216     array_walk($tests[0]['source_data']['menu_links'], function (&$row) {
217       $row['options'] = serialize($row['options']);
218     });
219
220     $tests[0]['expected_data'] = $expected;
221
222     return $tests;
223   }
224
225 }