Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / tests / src / Kernel / Plugin / migrate / source / d7 / NodeEntityTranslationTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Kernel\Plugin\migrate\source\d7;
4
5 use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
6
7 /**
8  * Tests Drupal 7 node entity translations source plugin.
9  *
10  * @covers \Drupal\node\Plugin\migrate\source\d7\NodeEntityTranslation
11  *
12  * @group node
13  */
14 class NodeEntityTranslationTest extends MigrateSqlSourceTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = ['node', 'user', 'migrate_drupal'];
20
21   /**
22    * {@inheritdoc}
23    */
24   public function providerSource() {
25     $tests = [];
26
27     // The source data.
28     $tests[0]['source_data']['entity_translation'] = [
29       [
30         'entity_type' => 'node',
31         'entity_id' => 2,
32         'revision_id' => 2,
33         'language' => 'en',
34         'source' => '',
35         'uid' => 1,
36         'status' => 1,
37         'translate' => 0,
38         'created' => 1531343498,
39         'changed' => 1531343498,
40       ],
41       [
42         'entity_type' => 'node',
43         'entity_id' => 2,
44         'revision_id' => 2,
45         'language' => 'fr',
46         'source' => 'en',
47         'uid' => 2,
48         'status' => 1,
49         'translate' => 1,
50         'created' => 1531343508,
51         'changed' => 1531343508,
52       ],
53       [
54         'entity_type' => 'node',
55         'entity_id' => 2,
56         'revision_id' => 2,
57         'language' => 'es',
58         'source' => 'en',
59         'uid' => 1,
60         'status' => 0,
61         'translate' => 0,
62         'created' => 1531343528,
63         'changed' => 1531343528,
64       ],
65     ];
66     $tests[0]['source_data']['field_config'] = [
67       [
68         'id' => 1,
69         'field_name' => 'body',
70         'type' => 'text_with_summary',
71         'module' => 'text',
72         'active' => 1,
73         'storage_type' => 'field_sql_storage',
74         'storage_module' => 'field_sql_storage',
75         'storage_active' => 1,
76         'locked' => 1,
77         'data' => 'a:0:{}',
78         'cardinality' => 1,
79         'translatable' => 1,
80         'deleted' => 0,
81       ],
82       [
83         'id' => 2,
84         'field_name' => 'title_field',
85         'type' => 'text',
86         'module' => 'text',
87         'active' => 1,
88         'storage_type' => 'field_sql_storage',
89         'storage_module' => 'field_sql_storage',
90         'storage_active' => 1,
91         'locked' => 1,
92         'data' => 'a:0:{}',
93         'cardinality' => 1,
94         'translatable' => 1,
95         'deleted' => 0,
96       ],
97     ];
98     $tests[0]['source_data']['field_config_instance'] = [
99       [
100         'id' => 1,
101         'field_id' => 1,
102         'field_name' => 'body',
103         'entity_type' => 'node',
104         'bundle' => 'article',
105         'data' => 'a:0:{}',
106         'deleted' => 0,
107       ],
108       [
109         'id' => 2,
110         'field_id' => 1,
111         'field_name' => 'body',
112         'entity_type' => 'node',
113         'bundle' => 'page',
114         'data' => 'a:0:{}',
115         'deleted' => 0,
116       ],
117       [
118         'id' => 3,
119         'field_id' => 2,
120         'field_name' => 'title_field',
121         'entity_type' => 'node',
122         'bundle' => 'page',
123         'data' => 'a:0:{}',
124         'deleted' => 0,
125       ],
126     ];
127     $tests[0]['source_data']['field_revision_body'] = [
128       [
129         'entity_type' => 'node',
130         'bundle' => 'article',
131         'deleted' => 0,
132         'entity_id' => 1,
133         'revision_id' => 1,
134         'language' => 'en',
135         'delta' => 0,
136         'body_value' => 'Untranslated body',
137         'body_summary' => 'Untranslated summary',
138         'body_format' => 'filtered_html',
139       ],
140       [
141         'entity_type' => 'node',
142         'bundle' => 'page',
143         'deleted' => 0,
144         'entity_id' => 2,
145         'revision_id' => 2,
146         'language' => 'en',
147         'delta' => 0,
148         'body_value' => 'English body',
149         'body_summary' => 'English summary',
150         'body_format' => 'filtered_html',
151       ],
152       [
153         'entity_type' => 'node',
154         'bundle' => 'page',
155         'deleted' => 0,
156         'entity_id' => 2,
157         'revision_id' => 2,
158         'language' => 'fr',
159         'delta' => 0,
160         'body_value' => 'French body',
161         'body_summary' => 'French summary',
162         'body_format' => 'filtered_html',
163       ],
164       [
165         'entity_type' => 'node',
166         'bundle' => 'page',
167         'deleted' => 0,
168         'entity_id' => 2,
169         'revision_id' => 2,
170         'language' => 'es',
171         'delta' => 0,
172         'body_value' => 'Spanish body',
173         'body_summary' => 'Spanish summary',
174         'body_format' => 'filtered_html',
175       ],
176     ];
177     $tests[0]['source_data']['field_revision_title_field'] = [
178       [
179         'entity_type' => 'node',
180         'bundle' => 'page',
181         'deleted' => '0',
182         'entity_id' => '2',
183         'revision_id' => '2',
184         'language' => 'en',
185         'delta' => '0',
186         'title_field_value' => 'English Source',
187         'title_field_format' => NULL,
188       ],
189       [
190         'entity_type' => 'node',
191         'bundle' => 'page',
192         'deleted' => '0',
193         'entity_id' => '2',
194         'revision_id' => '2',
195         'language' => 'fr',
196         'delta' => '0',
197         'title_field_value' => 'French Translation',
198         'title_field_format' => NULL,
199       ],
200       [
201         'entity_type' => 'node',
202         'bundle' => 'page',
203         'deleted' => '0',
204         'entity_id' => '2',
205         'revision_id' => '2',
206         'language' => 'es',
207         'delta' => '0',
208         'title_field_value' => 'Spanish Translation',
209         'title_field_format' => NULL,
210       ],
211     ];
212     $tests[0]['source_data']['node'] = [
213       [
214         'nid' => 1,
215         'vid' => 1,
216         'type' => 'article',
217         'language' => 'en',
218         'title' => 'Untranslated article',
219         'uid' => 1,
220         'status' => 1,
221         'created' => 1531343456,
222         'changed' => 1531343456,
223         'comment' => 2,
224         'promote' => 1,
225         'sticky' => 0,
226         'tnid' => 0,
227         'translate' => 0,
228       ],
229       [
230         'nid' => 2,
231         'vid' => 2,
232         'type' => 'page',
233         'language' => 'en',
234         'title' => 'Translated page',
235         'uid' => 1,
236         'status' => 1,
237         'created' => 1531343528,
238         'changed' => 1531343528,
239         'comment' => 1,
240         'promote' => 0,
241         'sticky' => 0,
242         'tnid' => 0,
243         'translate' => 0,
244       ],
245     ];
246     $tests[0]['source_data']['node_revision'] = [
247       [
248         'nid' => 1,
249         'vid' => 1,
250         'uid' => 1,
251         'title' => 'Untranslated article',
252         'log' => '',
253         'timestamp' => 1531343456,
254         'status' => 1,
255         'comment' => 2,
256         'promote' => 1,
257         'sticky' => 0,
258       ],
259       [
260         'nid' => 2,
261         'vid' => 2,
262         'uid' => 1,
263         'title' => 'Translated page',
264         'log' => '',
265         'timestamp' => 1531343528,
266         'status' => 1,
267         'comment' => 1,
268         'promote' => 0,
269         'sticky' => 0,
270       ],
271     ];
272     $tests[0]['source_data']['system'] = [
273       [
274         'name' => 'title',
275         'type' => 'module',
276         'status' => 1,
277       ],
278     ];
279
280     // The expected results.
281     $tests[0]['expected_data'] = [
282       [
283         'entity_type' => 'node',
284         'entity_id' => 2,
285         'revision_id' => 2,
286         'language' => 'fr',
287         'source' => 'en',
288         'uid' => 2,
289         'status' => 1,
290         'translate' => 1,
291         'created' => 1531343508,
292         'changed' => 1531343508,
293         'type' => 'page',
294         'title' => 'French Translation',
295         'promote' => 0,
296         'sticky' => 0,
297         'log' => '',
298         'timestamp' => 1531343528,
299         'revision_uid' => 1,
300         'body' => [
301           [
302             'value' => 'French body',
303             'summary' => 'French summary',
304             'format' => 'filtered_html',
305           ],
306         ],
307       ],
308       [
309         'entity_type' => 'node',
310         'entity_id' => 2,
311         'revision_id' => 2,
312         'language' => 'es',
313         'source' => 'en',
314         'uid' => 1,
315         'status' => 0,
316         'translate' => 0,
317         'created' => 1531343528,
318         'changed' => 1531343528,
319         'type' => 'page',
320         'title' => 'Spanish Translation',
321         'promote' => 0,
322         'sticky' => 0,
323         'log' => '',
324         'timestamp' => 1531343528,
325         'revision_uid' => 1,
326         'body' => [
327           [
328             'value' => 'Spanish body',
329             'summary' => 'Spanish summary',
330             'format' => 'filtered_html',
331           ],
332         ],
333       ],
334     ];
335
336     // Do an automatic count.
337     $tests[0]['expected_count'] = NULL;
338
339     // Set up source plugin configuration.
340     $tests[0]['configuration'] = [
341       'node_type' => 'page',
342     ];
343
344     // The source data.
345     $tests[1]['source_data'] = $tests[0]['source_data'];
346
347     // The expected results.
348     $tests[1]['expected_data'] = [];
349
350     // Do an automatic count.
351     $tests[1]['expected_count'] = NULL;
352
353     // Set up source plugin configuration.
354     $tests[1]['configuration'] = [
355       'node_type' => 'article',
356     ];
357
358     return $tests;
359   }
360
361 }