5bc608d3 |
1 | <?php |
2 | |
3 | /** |
4 | * Class CRM_Core_BAO_MappingTest. |
5 | * |
6 | * @group headless |
7 | */ |
8 | class CRM_Core_BAO_MappingTest extends CiviUnitTestCase { |
9 | |
d67808ac |
10 | /** |
11 | * Cleanup after test. |
12 | * |
13 | * @throws \CRM_Core_Exception |
14 | */ |
15 | public function tearDown() { |
16 | $this->quickCleanup(['civicrm_mapping_field', 'civicrm_mapping']); |
17 | parent::tearDown(); |
18 | } |
19 | |
5bc608d3 |
20 | /** |
21 | * Test calling saveMapping. |
d67808ac |
22 | * |
23 | * @dataProvider getMappingMaps |
5bc608d3 |
24 | */ |
d67808ac |
25 | public function testSaveMappingFields($params, $expected) { |
5bc608d3 |
26 | $mapping = $this->callAPISuccess('Mapping', 'create', ['name' => 'teest']); |
d34e92cc |
27 | CRM_Core_BAO_Mapping::saveMappingFields($params, $mapping['id']); |
d67808ac |
28 | $saved = $this->callAPISuccess('MappingField', 'get', ['mapping_id' => $mapping['id']])['values']; |
29 | $this->assertEquals($expected, $saved); |
30 | } |
31 | |
32 | /** |
33 | * Get data for mapping test. |
34 | * |
35 | * @return array |
36 | */ |
37 | public function getMappingMaps() { |
38 | return [ |
39 | [ |
40 | 'params' => [ |
41 | 'qfKey' => '8d3bae0f77b62314516c1253176a1c1a_6756', |
42 | 'entryURL' => 'http://dmaster.local/civicrm/contribute/search?reset=1', |
43 | 'saveMappingName' => 'test', |
44 | 'saveMappingDesc' => '', |
45 | 'saveMapping' => '1', |
46 | 'mapper' => [ |
47 | 1 => |
48 | [ |
49 | ['Individual', '10_b_a', 'id'], |
50 | ['Individual', 'city', ' '], |
51 | ['Individual', 'contact_sub_type'], |
52 | ['Student', 'custom_27'], |
53 | ['Individual', 'current_employer'], |
54 | ['Individual', 'phone', '1', '2'], |
55 | ['Individual', 'postal_code', '2'], |
56 | ['Individual', 'im', '1', '1'], |
57 | ['Individual', 'url'], |
58 | ['Individual', '1_b_a', 'phone', '5', '1'], |
59 | ], |
60 | ], |
d34e92cc |
61 | ], |
d67808ac |
62 | 'expected' => $expected = [ |
63 | 1 => |
64 | [ |
65 | 'id' => '1', |
66 | 'mapping_id' => '1', |
67 | 'name' => 'id', |
68 | 'contact_type' => 'Individual', |
69 | 'column_number' => '0', |
70 | 'relationship_type_id' => '10', |
71 | 'relationship_direction' => 'b_a', |
72 | 'grouping' => '1', |
73 | ], |
74 | 2 => |
75 | [ |
76 | 'id' => '2', |
77 | 'mapping_id' => '1', |
78 | 'name' => 'city', |
79 | 'contact_type' => 'Individual', |
80 | 'column_number' => '1', |
81 | 'grouping' => '1', |
82 | ], |
83 | 3 => |
84 | [ |
85 | 'id' => '3', |
86 | 'mapping_id' => '1', |
87 | 'name' => 'contact_sub_type', |
88 | 'contact_type' => 'Individual', |
89 | 'column_number' => '2', |
90 | 'grouping' => '1', |
91 | ], |
92 | 4 => |
93 | [ |
94 | 'id' => '4', |
95 | 'mapping_id' => '1', |
96 | 'name' => 'custom_27', |
97 | 'contact_type' => 'Student', |
98 | 'column_number' => '3', |
99 | 'grouping' => '1', |
100 | ], |
101 | 5 => |
102 | [ |
103 | 'id' => '5', |
104 | 'mapping_id' => '1', |
105 | 'name' => 'current_employer', |
106 | 'contact_type' => 'Individual', |
107 | 'column_number' => '4', |
108 | 'grouping' => '1', |
109 | ], |
110 | 6 => |
111 | [ |
112 | 'id' => '6', |
113 | 'mapping_id' => '1', |
114 | 'name' => 'phone', |
115 | 'contact_type' => 'Individual', |
116 | 'column_number' => '5', |
117 | 'location_type_id' => '1', |
118 | 'phone_type_id' => '2', |
119 | 'grouping' => '1', |
120 | ], |
121 | 7 => |
122 | [ |
123 | 'id' => '7', |
124 | 'mapping_id' => '1', |
125 | 'name' => 'postal_code', |
126 | 'contact_type' => 'Individual', |
127 | 'column_number' => '6', |
128 | 'location_type_id' => '2', |
129 | 'grouping' => '1', |
130 | ], |
131 | 8 => |
132 | [ |
133 | 'id' => '8', |
134 | 'mapping_id' => '1', |
135 | 'name' => 'im', |
136 | 'contact_type' => 'Individual', |
137 | 'column_number' => '7', |
138 | 'location_type_id' => '1', |
139 | 'im_provider_id' => '1', |
140 | 'grouping' => '1', |
141 | ], |
142 | 9 => |
143 | [ |
144 | 'id' => '9', |
145 | 'mapping_id' => '1', |
146 | 'name' => 'url', |
147 | 'contact_type' => 'Individual', |
148 | 'column_number' => '8', |
149 | 'grouping' => '1', |
150 | ], |
151 | 10 => |
152 | [ |
153 | 'id' => '10', |
154 | 'mapping_id' => '1', |
155 | 'name' => 'phone', |
156 | 'contact_type' => 'Individual', |
157 | 'column_number' => '9', |
158 | 'location_type_id' => '5', |
159 | 'phone_type_id' => '1', |
160 | 'relationship_type_id' => '1', |
161 | 'relationship_direction' => 'b_a', |
162 | 'grouping' => '1', |
163 | ], |
d34e92cc |
164 | ], |
d67808ac |
165 | ], |
166 | [ |
167 | 'params' => [ |
168 | 'qfKey' => '054b561dbf948548f7883151f879fe72_533', |
169 | 'entryURL' => 'http://dmaster.local/civicrm/contact/search/builder?reset=1', |
170 | 'mapper' => [ |
171 | [ |
172 | ['Contact', 'addressee_id'], |
173 | ['Individual', 'custom_2'], |
174 | [''], |
175 | [''], |
176 | [''], |
177 | ], |
178 | [[''], [''], [''], [''], ['']], |
179 | [[''], [''], [''], [''], ['']], |
180 | ], |
181 | 'operator' => [ |
182 | ['IS NOT NULL', 'IS NULL', '', '', ''], |
183 | ['', '', '', '', ''], |
184 | ['', '', '', '', ''], |
185 | ], |
186 | 'value' => [ |
187 | ['', '', '', '', ''], |
188 | ['', '', '', '', ''], |
189 | ['', '', '', '', ''], |
190 | ], |
191 | 'task' => '12', |
192 | 'radio_ts' => 'ts_sel', |
193 | 'toggleSelect' => '1', |
194 | 'mark_x_98' => '1', |
195 | 'title' => 'mmo', |
196 | |
d34e92cc |
197 | ], |
d67808ac |
198 | 'expected' => [ |
199 | 1 => [ |
200 | 'id' => '1', |
201 | 'mapping_id' => '1', |
202 | 'name' => 'addressee_id', |
203 | 'contact_type' => 'Contact', |
204 | 'column_number' => '0', |
205 | 'grouping' => '0', |
206 | 'operator' => 'IS NOT NULL', |
207 | ], |
208 | 2 => [ |
209 | 'id' => '2', |
210 | 'mapping_id' => '1', |
211 | 'name' => 'custom_2', |
212 | 'contact_type' => 'Individual', |
213 | 'column_number' => '1', |
214 | 'grouping' => '0', |
215 | 'operator' => 'IS NULL', |
216 | ], |
d34e92cc |
217 | ], |
d67808ac |
218 | ], |
d34e92cc |
219 | ]; |
5bc608d3 |
220 | } |
221 | |
222 | } |