Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / taxonomy / tests / src / Kernel / Plugin / migrate / source / d7 / TermTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d7;
4
5 use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
6
7 /**
8  * Tests taxonomy term source plugin.
9  *
10  * @covers \Drupal\taxonomy\Plugin\migrate\source\d7\Term
11  * @group taxonomy
12  */
13 class TermTest extends MigrateSqlSourceTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['taxonomy', 'migrate_drupal'];
19
20   /**
21    * {@inheritdoc}
22    */
23   public function providerSource() {
24     $tests = [];
25
26     // The source data.
27     $tests[0]['source_data']['taxonomy_term_data'] = [
28       [
29         'tid' => 1,
30         'vid' => 5,
31         'name' => 'name value 1',
32         'description' => 'description value 1',
33         'weight' => 0,
34       ],
35       [
36         'tid' => 2,
37         'vid' => 6,
38         'name' => 'name value 2',
39         'description' => 'description value 2',
40         'weight' => 0,
41       ],
42       [
43         'tid' => 3,
44         'vid' => 6,
45         'name' => 'name value 3',
46         'description' => 'description value 3',
47         'weight' => 0,
48       ],
49       [
50         'tid' => 4,
51         'vid' => 5,
52         'name' => 'name value 4',
53         'description' => 'description value 4',
54         'weight' => 1,
55       ],
56       [
57         'tid' => 5,
58         'vid' => 6,
59         'name' => 'name value 5',
60         'description' => 'description value 5',
61         'weight' => 1,
62       ],
63       [
64         'tid' => 6,
65         'vid' => 6,
66         'name' => 'name value 6',
67         'description' => 'description value 6',
68         'weight' => 0,
69       ],
70       [
71         'tid' => 7,
72         'vid' => 3,
73         'name' => 'name value 7',
74         'description' => 'description value 7',
75         'weight' => 0,
76       ],
77     ];
78     $tests[0]['source_data']['taxonomy_term_hierarchy'] = [
79       [
80         'tid' => 1,
81         'parent' => 0,
82       ],
83       [
84         'tid' => 2,
85         'parent' => 0,
86       ],
87       [
88         'tid' => 3,
89         'parent' => 0,
90       ],
91       [
92         'tid' => 4,
93         'parent' => 1,
94       ],
95       [
96         'tid' => 5,
97         'parent' => 2,
98       ],
99       [
100         'tid' => 6,
101         'parent' => 3,
102       ],
103       [
104         'tid' => 6,
105         'parent' => 2,
106       ],
107       [
108         'tid' => 7,
109         'parent' => 0,
110       ],
111     ];
112     $tests[0]['source_data']['taxonomy_vocabulary'] = [
113       [
114         'vid' => 5,
115         'machine_name' => 'tags',
116       ],
117       [
118         'vid' => 6,
119         'machine_name' => 'categories',
120       ],
121     ];
122     $tests[0]['source_data']['field_config_instance'] = [
123       [
124         'field_name' => 'field_term_field',
125         'entity_type' => 'taxonomy_term',
126         'bundle' => 'tags',
127         'deleted' => 0,
128       ],
129       [
130         'field_name' => 'field_term_field',
131         'entity_type' => 'taxonomy_term',
132         'bundle' => 'categories',
133         'deleted' => 0,
134       ],
135     ];
136     $tests[0]['source_data']['field_data_field_term_field'] = [
137       [
138         'entity_type' => 'taxonomy_term',
139         'bundle' => 'tags',
140         'deleted' => 0,
141         'entity_id' => 1,
142         'delta' => 0,
143       ],
144       [
145         'entity_type' => 'taxonomy_term',
146         'bundle' => 'categories',
147         'deleted' => 0,
148         'entity_id' => 1,
149         'delta' => 0,
150       ],
151     ];
152
153     // The expected results.
154     $tests[0]['expected_data'] = [
155       [
156         'tid' => 1,
157         'vid' => 5,
158         'name' => 'name value 1',
159         'description' => 'description value 1',
160         'weight' => 0,
161         'parent' => [0],
162       ],
163       [
164         'tid' => 2,
165         'vid' => 6,
166         'name' => 'name value 2',
167         'description' => 'description value 2',
168         'weight' => 0,
169         'parent' => [0],
170       ],
171       [
172         'tid' => 3,
173         'vid' => 6,
174         'name' => 'name value 3',
175         'description' => 'description value 3',
176         'weight' => 0,
177         'parent' => [0],
178       ],
179       [
180         'tid' => 4,
181         'vid' => 5,
182         'name' => 'name value 4',
183         'description' => 'description value 4',
184         'weight' => 1,
185         'parent' => [1],
186       ],
187       [
188         'tid' => 5,
189         'vid' => 6,
190         'name' => 'name value 5',
191         'description' => 'description value 5',
192         'weight' => 1,
193         'parent' => [2],
194       ],
195       [
196         'tid' => 6,
197         'vid' => 6,
198         'name' => 'name value 6',
199         'description' => 'description value 6',
200         'weight' => 0,
201         'parent' => [3, 2],
202       ],
203       [
204         'tid' => 7,
205         'vid' => 3,
206         'name' => 'name value 7',
207         'description' => 'description value 7',
208         'weight' => 0,
209         'parent' => [0],
210       ],
211     ];
212
213     $tests[0]['expected_count'] = NULL;
214     // Empty configuration will return terms for all vocabularies.
215     $tests[0]['configuration'] = [];
216
217     // Change configuration to get one vocabulary, "tags".
218     $tests[1]['source_data'] = $tests[0]['source_data'];
219     $tests[1]['expected_data'] = [
220       [
221         'tid' => 1,
222         'vid' => 5,
223         'name' => 'name value 1',
224         'description' => 'description value 1',
225         'weight' => 0,
226         'parent' => [0],
227       ],
228       [
229         'tid' => 4,
230         'vid' => 5,
231         'name' => 'name value 4',
232         'description' => 'description value 4',
233         'weight' => 1,
234         'parent' => [1],
235       ],
236     ];
237     $tests[1]['expected_count'] = NULL;
238     $tests[1]['configuration']['bundle'] = ['tags'];
239
240     // Same as previous test, but with configuration vocabulary as a string
241     // instead of an array.
242     $tests[2]['source_data'] = $tests[0]['source_data'];
243     $tests[2]['expected_data'] = $tests[1]['expected_data'];
244     $tests[2]['expected_count'] = NULL;
245     $tests[2]['configuration']['bundle'] = 'tags';
246
247     // Change configuration to get two vocabularies, "tags" and "categories".
248     $tests[3]['source_data'] = $tests[0]['source_data'];
249     $tests[3]['expected_data'] = $tests[0]['expected_data'];
250     // Remove the last element because it is for vid 3.
251     array_pop($tests[3]['expected_data']);
252     $tests[3]['expected_count'] = NULL;
253     $tests[3]['configuration']['bundle'] = ['tags', 'categories'];
254
255     return $tests;
256   }
257
258 }