c321185713070c2b740de686c889bc454cb3af3b
[yaffs-website] / web / core / modules / user / tests / src / Kernel / Plugin / migrate / source / ProfileFieldTest.php
1 <?php
2
3 namespace Drupal\Tests\user\Kernel\Plugin\migrate\source;
4
5 use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
6
7 /**
8  * Tests the profile_field source plugin.
9  *
10  * @covers \Drupal\user\Plugin\migrate\source\ProfileField
11  * @group user
12  */
13 class ProfileFieldTest extends MigrateSqlSourceTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['user', 'migrate_drupal'];
19
20   /**
21    * {@inheritdoc}
22    */
23   public function providerSource() {
24     $tests = [
25       [
26         'source_data' => [],
27         'expected_data' => [],
28        ],
29     ];
30
31     $profile_fields = [
32       [
33         'fid' => 1,
34         'title' => 'First name',
35         'name' => 'profile_first_name',
36         'explanation' => 'First name user',
37         'category' => 'profile',
38         'page' => '',
39         'type' => 'textfield',
40         'weight' => 0,
41         'required' => 1,
42         'register' => 0,
43         'visibility' => 2,
44         'autocomplete' => 0,
45         'options' => '',
46       ],
47       [
48         'fid' => 2,
49         'title' => 'Last name',
50         'name' => 'profile_last_name',
51         'explanation' => 'Last name user',
52         'category' => 'profile',
53         'page' => '',
54         'type' => 'textfield',
55         'weight' => 0,
56         'required' => 0,
57         'register' => 0,
58         'visibility' => 2,
59         'autocomplete' => 0,
60         'options' => '',
61       ],
62       [
63         'fid' => 3,
64         'title' => 'Policy',
65         'name' => 'profile_policy',
66         'explanation' => 'A checkbox that say if you accept policy of website',
67         'category' => 'profile',
68         'page' => '',
69         'type' => 'checkbox',
70         'weight' => 0,
71         'required' => 1,
72         'register' => 1,
73         'visibility' => 2,
74         'autocomplete' => 0,
75         'options' => '',
76       ],
77       [
78         'fid' => 4,
79         'title' => 'Color',
80         'name' => 'profile_color',
81         'explanation' => 'A selection that allows user to select a color',
82         'category' => 'profile',
83         'page' => '',
84         'type' => 'selection',
85         'weight' => 0,
86         'required' => 0,
87         'register' => 0,
88         'visibility' => 2,
89         'autocomplete' => 0,
90         'options' => "red\nblue\ngreen",
91       ],
92     ];
93
94     $tests[0]['source_data']['profile_fields'] = $profile_fields;
95
96     // Profile values are merged with pre-set options of a "selection" field.
97     $tests[0]['source_data']['profile_values'] = [
98       [
99         'fid' => 4,
100         'uid' => 1,
101         'value' => 'yellow',
102       ]
103     ];
104
105     // Expected options are:
106     //  for "checkbox" fields - array with NULL options
107     //  for "selection" fields - options in both keys and values
108     $expected_field_options = [
109       '',
110       '',
111       [NULL, NULL],
112       [
113         'red' => 'red',
114         'blue' => 'blue',
115         'green' => 'green',
116         'yellow' => 'yellow',
117       ]
118     ];
119
120     $tests[0]['expected_data'] = $profile_fields;
121
122     foreach ($tests[0]['expected_data'] as $delta => $row) {
123       $tests[0]['expected_data'][$delta]['options'] = $expected_field_options[$delta];
124     }
125
126     return $tests;
127   }
128
129 }