Version 1
[yaffs-website] / web / core / modules / taxonomy / tests / src / Kernel / Plugin / migrate / source / d6 / TermTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d6;
4
5 use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
6
7 /**
8  * Tests taxonomy term source plugin.
9  *
10  * @covers \Drupal\taxonomy\Plugin\migrate\source\d6\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']['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']['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
113     // The expected results.
114     $tests[0]['expected_data'] = [
115       [
116         'tid' => 1,
117         'vid' => 5,
118         'name' => 'name value 1',
119         'description' => 'description value 1',
120         'weight' => 0,
121         'parent' => [0],
122       ],
123       [
124         'tid' => 2,
125         'vid' => 6,
126         'name' => 'name value 2',
127         'description' => 'description value 2',
128         'weight' => 0,
129         'parent' => [0],
130       ],
131       [
132         'tid' => 3,
133         'vid' => 6,
134         'name' => 'name value 3',
135         'description' => 'description value 3',
136         'weight' => 0,
137         'parent' => [0],
138       ],
139       [
140         'tid' => 4,
141         'vid' => 5,
142         'name' => 'name value 4',
143         'description' => 'description value 4',
144         'weight' => 1,
145         'parent' => [1],
146       ],
147       [
148         'tid' => 5,
149         'vid' => 6,
150         'name' => 'name value 5',
151         'description' => 'description value 5',
152         'weight' => 1,
153         'parent' => [2],
154       ],
155       [
156         'tid' => 6,
157         'vid' => 6,
158         'name' => 'name value 6',
159         'description' => 'description value 6',
160         'weight' => 0,
161         'parent' => [3, 2],
162       ],
163       [
164         'tid' => 7,
165         'vid' => 3,
166         'name' => 'name value 7',
167         'description' => 'description value 7',
168         'weight' => 0,
169         'parent' => [0],
170       ],
171     ];
172
173     $tests[0]['expected_count'] = NULL;
174     // Empty configuration will return terms for all vocabularies.
175     $tests[0]['configuration'] = [];
176
177     // Change configuration to get one vocabulary, 5.
178     $tests[1]['source_data'] = $tests[0]['source_data'];
179     $tests[1]['expected_data'] = [
180       [
181         'tid' => 1,
182         'vid' => 5,
183         'name' => 'name value 1',
184         'description' => 'description value 1',
185         'weight' => 0,
186         'parent' => [0],
187       ],
188       [
189         'tid' => 4,
190         'vid' => 5,
191         'name' => 'name value 4',
192         'description' => 'description value 4',
193         'weight' => 1,
194         'parent' => [1],
195       ],
196     ];
197     $tests[1]['expected_count'] = NULL;
198     $tests[1]['configuration']['bundle'] = ['5'];
199
200     // Same as previous test, but with configuration vocabulary as a string
201     // instead of an array.
202     $tests[2]['source_data'] = $tests[0]['source_data'];
203     $tests[2]['expected_data'] = $tests[1]['expected_data'];
204     $tests[2]['expected_count'] = NULL;
205     $tests[2]['configuration']['bundle'] = '5';
206
207     // Change configuration to get two vocabularies, 5 and 6.
208     $tests[3]['source_data'] = $tests[0]['source_data'];
209     $tests[3]['expected_data'] = $tests[0]['expected_data'];
210     // Remove the last element because it is for vid 3.
211     array_pop($tests[3]['expected_data']);
212     $tests[3]['expected_count'] = NULL;
213     $tests[3]['configuration']['bundle'] = ['5', '6'];
214
215     return $tests;
216   }
217
218 }