Commit | Line | Data |
---|---|---|
fe83c251 | 1 | <?php |
2 | ||
b2148ce1 | 3 | use Civi\Api4\ActionSchedule; |
8515e10c EM |
4 | use Civi\Api4\MessageTemplate; |
5 | ||
fe83c251 | 6 | /** |
7 | * Class CRM_UF_Page_ProfileEditorTest | |
8 | * @group headless | |
9 | */ | |
12d387d2 | 10 | class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase { |
ff77d525 | 11 | use CRMTraits_Custom_CustomDataTrait; |
fe83c251 | 12 | |
dd09ee0c | 13 | public function tearDown(): void { |
b2148ce1 EM |
14 | $this->quickCleanup(['civicrm_saved_search', 'civicrm_action_schedule']); |
15 | parent::tearDown(); | |
b4d67eb2 | 16 | } |
17 | ||
fe83c251 | 18 | /** |
19 | * Test message upgrade process. | |
20 | */ | |
b2148ce1 EM |
21 | public function testMessageTemplateUpgrade(): void { |
22 | $workFlowID = $this->callAPISuccessGetValue('OptionValue', ['return' => 'id', 'name' => 'membership_online_receipt', 'options' => ['limit' => 1, 'sort' => 'id DESC']]); | |
fe83c251 | 23 | |
24 | $templates = $this->callAPISuccess('MessageTemplate', 'get', ['workflow_id' => $workFlowID])['values']; | |
25 | foreach ($templates as $template) { | |
26 | $originalText = $template['msg_text']; | |
27 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a cool member you are', 'id' => $template['id']]); | |
28 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); | |
29 | $this->assertEquals('great what a cool member you are', $msg_text); | |
30 | } | |
31 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); | |
32 | $messageTemplateObject->updateTemplates(); | |
33 | ||
34 | foreach ($templates as $template) { | |
35 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); | |
275686a3 | 36 | $this->assertStringContainsString('{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}{$greeting},{/if}', $msg_text); |
fe83c251 | 37 | if ($msg_text !== $originalText) { |
38 | // Reset value for future tests. | |
39 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => $originalText, 'id' => $template['id']]); | |
40 | } | |
41 | } | |
42 | } | |
43 | ||
8515e10c EM |
44 | /** |
45 | * Test that a string replacement in a message template can be done. | |
46 | * | |
47 | * @throws \API_Exception | |
48 | */ | |
49 | public function testMessageTemplateStringReplace(): void { | |
50 | MessageTemplate::update()->setValues(['msg_html' => '{$display_name}'])->addWhere( | |
51 | 'workflow_name', '=', 'contribution_invoice_receipt' | |
52 | )->execute(); | |
53 | $upgrader = new CRM_Upgrade_Incremental_MessageTemplates('5.41.0'); | |
58169187 EM |
54 | $check = new CRM_Utils_Check_Component_Tokens(); |
55 | $message = $check->checkTokens()[0]; | |
56 | $this->assertEquals('<p>You are using tokens that have been removed or deprecated.</p><ul><li>Please review your contribution_invoice_receipt message template and remove references to the token {$display_name} as it has been replaced by {contact.display_name}</li></ul></p>', $message->getMessage()); | |
8515e10c EM |
57 | $upgrader->replaceTokenInTemplate('contribution_invoice_receipt', '$display_name', 'contact.display_name'); |
58 | $templates = MessageTemplate::get()->addSelect('msg_html') | |
59 | ->addWhere( | |
60 | 'workflow_name', '=', 'contribution_invoice_receipt' | |
61 | )->execute(); | |
62 | foreach ($templates as $template) { | |
63 | $this->assertEquals('{contact.display_name}', $template['msg_html']); | |
64 | } | |
58169187 EM |
65 | $messages = $check->checkTokens(); |
66 | $this->assertEmpty($messages); | |
8515e10c EM |
67 | $this->revertTemplateToReservedTemplate('contribution_invoice_receipt'); |
68 | } | |
69 | ||
b2148ce1 EM |
70 | /** |
71 | * Test that a $this->string replacement in a message template can be done. | |
72 | * | |
73 | * @throws \API_Exception | |
74 | */ | |
75 | public function testActionScheduleStringReplace(): void { | |
76 | ActionSchedule::create(FALSE)->setValues([ | |
77 | 'title' => 'schedule', | |
78 | 'absolute_date' => '2021-01-01', | |
79 | 'start_action_date' => '2021-01-01', | |
80 | 'mapping_id' => 1, | |
81 | 'entity_value' => 1, | |
82 | 'body_text' => 'blah {contribution.status}', | |
83 | 'body_html' => 'blah {contribution.status}', | |
84 | 'subject' => 'blah {contribution.status}', | |
85 | ])->execute(); | |
86 | ||
87 | $upgrader = new CRM_Upgrade_Incremental_MessageTemplates('5.41.0'); | |
88 | $upgrader->replaceTokenInActionSchedule('contribution.status', 'contribution.contribution_status_id:label'); | |
89 | $templates = ActionSchedule::get()->addSelect('body_html', 'subject', 'body_text')->execute(); | |
90 | foreach ($templates as $template) { | |
91 | $this->assertEquals('blah {contribution.contribution_status_id:label}', $template['body_html']); | |
92 | $this->assertEquals('blah {contribution.contribution_status_id:label}', $template['body_text']); | |
93 | $this->assertEquals('blah {contribution.contribution_status_id:label}', $template['subject']); | |
94 | } | |
95 | } | |
96 | ||
fe83c251 | 97 | /** |
98 | * Test message upgrade process only edits the default if the template is customised. | |
99 | */ | |
100 | public function testMessageTemplateUpgradeAlreadyCustomised() { | |
101 | $workFlowID = civicrm_api3('OptionValue', 'getvalue', ['return' => 'id', 'name' => 'membership_online_receipt', 'options' => ['limit' => 1, 'sort' => 'id DESC']]); | |
102 | ||
103 | $templates = $this->callAPISuccess('MessageTemplate', 'get', ['workflow_id' => $workFlowID])['values']; | |
104 | foreach ($templates as $template) { | |
105 | if ($template['is_reserved']) { | |
106 | $originalText = $template['msg_text']; | |
107 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a cool member you are', 'id' => $template['id']]); | |
108 | } | |
109 | else { | |
110 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a silly sausage you are', 'id' => $template['id']]); | |
111 | } | |
112 | } | |
113 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); | |
114 | $messageTemplateObject->updateTemplates(); | |
115 | ||
116 | foreach ($templates as $template) { | |
117 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); | |
118 | if ($template['is_reserved']) { | |
275686a3 | 119 | $this->assertStringContainsString('{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}{$greeting},{/if}', $msg_text); |
fe83c251 | 120 | } |
121 | else { | |
122 | $this->assertEquals('great what a silly sausage you are', $msg_text); | |
123 | } | |
124 | ||
125 | if ($msg_text !== $originalText) { | |
126 | // Reset value for future tests. | |
127 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => $originalText, 'id' => $template['id']]); | |
128 | } | |
129 | } | |
130 | } | |
131 | ||
132 | /** | |
133 | * Test function for messages on upgrade. | |
134 | */ | |
135 | public function testMessageTemplateGetUpgradeMessages() { | |
136 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); | |
137 | $messages = $messageTemplateObject->getUpgradeMessages(); | |
12d387d2 | 138 | $this->assertEquals([ |
139 | 'Memberships - Receipt (on-line)' => 'Use email greeting at top where available', | |
140 | 'Contributions - Receipt (on-line)' => 'Use email greeting at top where available', | |
141 | 'Events - Registration Confirmation and Receipt (on-line)' => 'Use email greeting at top where available', | |
142 | ], $messages); | |
fe83c251 | 143 | } |
144 | ||
7015248a | 145 | /** |
146 | * Test converting a datepicker field. | |
147 | */ | |
148 | public function testSmartGroupDatePickerConversion() { | |
149 | $this->callAPISuccess('SavedSearch', 'create', [ | |
39b959db | 150 | 'form_values' => [ |
7015248a | 151 | ['grant_application_received_date_high', '=', '01/20/2019'], |
152 | ['grant_due_date_low', '=', '01/22/2019'], | |
39b959db | 153 | ], |
7015248a | 154 | ]); |
ac241c34 CW |
155 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); |
156 | $smartGroupConversionObject->updateGroups([ | |
157 | 'datepickerConversion' => [ | |
158 | 'grant_application_received_date', | |
159 | 'grant_decision_date', | |
160 | 'grant_money_transfer_date', | |
39b959db SL |
161 | 'grant_due_date', |
162 | ], | |
ac241c34 | 163 | ]); |
7015248a | 164 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); |
165 | $this->assertEquals('grant_application_received_date_high', $savedSearch['form_values'][0][0]); | |
929d5a15 | 166 | $this->assertEquals('2019-01-20 23:59:59', $savedSearch['form_values'][0][2]); |
7015248a | 167 | $this->assertEquals('grant_due_date_low', $savedSearch['form_values'][1][0]); |
168 | $this->assertEquals('2019-01-22 00:00:00', $savedSearch['form_values'][1][2]); | |
929d5a15 | 169 | $hasRelative = FALSE; |
170 | foreach ($savedSearch['form_values'] as $form_value) { | |
171 | if ($form_value[0] === 'grant_due_date_relative') { | |
172 | $hasRelative = TRUE; | |
173 | } | |
174 | } | |
175 | $this->assertEquals(TRUE, $hasRelative); | |
7015248a | 176 | } |
177 | ||
1915f8d2 SL |
178 | /** |
179 | * Test Multiple Relative Date conversions | |
180 | */ | |
181 | public function testSmartGroupMultipleRelatvieDateConversions() { | |
182 | $this->callAPISuccess('SavedSearch', 'create', [ | |
183 | 'form_values' => [ | |
184 | ['membership_join_date_low', '=', '20190903000000'], | |
185 | ['membership_join_date_high', '=', '20190903235959'], | |
186 | ['membership_start_date_low', '=' , '20190901000000'], | |
187 | ['membership_start_date_high', '=', '20190907235959'], | |
188 | ['membership_end_date_low', '=', '20190901000000'], | |
189 | ['membership_end_date_high', '=', '20190907235959'], | |
190 | 'relative_dates' => [ | |
191 | 'member_join' => 'this.day', | |
192 | 'member_start' => 'this.week', | |
193 | 'member_end' => 'this.week', | |
194 | ], | |
195 | ], | |
196 | ]); | |
197 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); | |
198 | $smartGroupConversionObject->updateGroups([ | |
199 | 'datepickerConversion' => [ | |
200 | 'membership_join_date', | |
201 | 'membership_start_date', | |
202 | 'membership_end_date', | |
203 | ], | |
204 | ]); | |
205 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); | |
206 | $this->assertContains('6', array_keys($savedSearch['form_values'])); | |
207 | $this->assertEquals('membership_join_date_relative', $savedSearch['form_values'][6][0]); | |
208 | $this->assertEquals('this.day', $savedSearch['form_values'][6][2]); | |
209 | $this->assertContains('7', array_keys($savedSearch['form_values'])); | |
210 | $this->assertEquals('membership_start_date_relative', $savedSearch['form_values'][7][0]); | |
211 | $this->assertEquals('this.week', $savedSearch['form_values'][7][2]); | |
212 | $this->assertContains('8', array_keys($savedSearch['form_values'])); | |
213 | $this->assertEquals('membership_end_date_relative', $savedSearch['form_values'][8][0]); | |
214 | $this->assertEquals('this.week', $savedSearch['form_values'][8][2]); | |
215 | } | |
216 | ||
c1436807 SL |
217 | /** |
218 | * Test upgrading multiple Event smart groups of different formats | |
219 | */ | |
220 | public function testMultipleEventSmartGroupDateConversions() { | |
221 | $this->callAPISuccess('SavedSearch', 'create', [ | |
222 | 'form_values' => [ | |
223 | ['event_start_date_low', '=', '20191001000000'], | |
224 | ['event_end_date_high', '=', '20191031235959'], | |
225 | 'relative_dates' => [ | |
226 | 'event' => 'this.month', | |
227 | ], | |
228 | ], | |
229 | ]); | |
230 | $this->callAPISuccess('SavedSearch', 'create', [ | |
231 | 'form_values' => [ | |
232 | ['event_start_date_low', '=', '20191001000000'], | |
233 | ], | |
234 | ]); | |
235 | $this->callAPISuccess('SavedSearch', 'create', [ | |
236 | 'form_values' => [ | |
237 | 'event_start_date_low' => '20191001000000', | |
238 | 'event_end_date_high' => '20191031235959', | |
239 | 'event_relative' => 'this.month', | |
240 | ], | |
241 | ]); | |
242 | $this->callAPISuccess('SavedSearch', 'create', [ | |
243 | 'form_values' => [ | |
244 | 'event_start_date_low' => '10/01/2019', | |
245 | 'event_end_date_high' => '', | |
246 | 'event_relative' => '0', | |
247 | ], | |
248 | ]); | |
249 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); | |
250 | $smartGroupConversionObject->renameFields([ | |
251 | ['old' => 'event_start_date_low', 'new' => 'event_low'], | |
252 | ['old' => 'event_end_date_high', 'new' => 'event_high'], | |
253 | ]); | |
254 | $smartGroupConversionObject->updateGroups([ | |
255 | 'datepickerConversion' => [ | |
256 | 'event', | |
257 | ], | |
258 | ]); | |
259 | $expectedResults = [ | |
260 | 1 => [ | |
261 | 'relative_dates' => [], | |
262 | 2 => ['event_relative', '=', 'this.month'], | |
263 | ], | |
264 | 2 => [ | |
265 | 0 => ['event_low', '=', '2019-10-01 00:00:00'], | |
266 | 1 => ['event_relative', '=', 0], | |
267 | ], | |
268 | 3 => [ | |
269 | 'event_relative' => 'this.month', | |
270 | ], | |
271 | 4 => [ | |
272 | 'event_relative' => 0, | |
273 | 'event_low' => '2019-10-01 00:00:00', | |
274 | ], | |
275 | ]; | |
276 | $savedSearches = $this->callAPISuccess('SavedSearch', 'get', []); | |
277 | foreach ($savedSearches['values'] as $id => $savedSearch) { | |
278 | $this->assertEquals($expectedResults[$id], $savedSearch['form_values']); | |
279 | } | |
280 | } | |
281 | ||
70e0d21f SL |
282 | /** |
283 | * Test Log Date conversion | |
284 | */ | |
285 | public function testLogDateConversion() { | |
286 | // Create two sets of searches one set for added by and one for modified by | |
287 | // Each set contains a relative search on this.month and a specific date search low | |
288 | $this->callAPISuccess('SavedSearch', 'create', [ | |
289 | 'form_values' => [ | |
290 | ['log_date', '=', 1], | |
291 | ['log_date_low', '=', '20191001000000'], | |
292 | ['log_date_high', '=', '20191031235959'], | |
293 | 'relative_dates' => [ | |
294 | 'log' => 'this.month', | |
295 | ], | |
296 | ], | |
297 | ]); | |
298 | $this->callAPISuccess('SavedSearch', 'create', [ | |
299 | 'form_values' => [ | |
300 | ['log_date', '=', 1], | |
301 | ['log_date_low', '=', '20191001000000'], | |
302 | ], | |
303 | ]); | |
304 | $this->callAPISuccess('SavedSearch', 'create', [ | |
305 | 'form_values' => [ | |
306 | ['log_date', '=', 2], | |
307 | ['log_date_low', '=', '20191001000000'], | |
308 | ['log_date_high', '=', '20191031235959'], | |
309 | 'relative_dates' => [ | |
310 | 'log' => 'this.month', | |
311 | ], | |
312 | ], | |
313 | ]); | |
314 | $this->callAPISuccess('SavedSearch', 'create', [ | |
315 | 'form_values' => [ | |
316 | ['log_date', '=', 2], | |
317 | ['log_date_low', '=', '20191001000000'], | |
318 | ], | |
319 | ]); | |
3a431eaa SL |
320 | // On the original search form you didn't need to select the log_date radio |
321 | // If it wasn't selected it defaulted to created_date filtering. | |
322 | $this->callAPISuccess('SavedSearch', 'create', [ | |
323 | 'form_values' => [ | |
324 | ['log_date_low', '=', '20191001000000'], | |
325 | ['log_date_high', '=', '20191031235959'], | |
326 | 'relative_dates' => [ | |
327 | 'log' => 'this.month', | |
328 | ], | |
329 | ], | |
330 | ]); | |
331 | $this->callAPISuccess('SavedSearch', 'create', [ | |
332 | 'form_values' => [ | |
333 | ['log_date_low', '=', '20191001000000'], | |
334 | ], | |
335 | ]); | |
70e0d21f SL |
336 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); |
337 | $smartGroupConversionObject->renameLogFields(); | |
338 | $smartGroupConversionObject->updateGroups([ | |
339 | 'datepickerConversion' => [ | |
340 | 'created_date', | |
341 | 'modified_date', | |
342 | ], | |
343 | ]); | |
344 | $savedSearhes = $this->callAPISuccess('SavedSearch', 'get', []); | |
345 | $expectedResults = [ | |
346 | 1 => [ | |
347 | 0 => ['log_date', '=', 1], | |
348 | 'relative_dates' => [], | |
349 | 3 => ['created_date_relative', '=', 'this.month'], | |
350 | ], | |
351 | 2 => [ | |
352 | 0 => ['log_date', '=', 1], | |
353 | 1 => ['created_date_low', '=', '2019-10-01 00:00:00'], | |
354 | 2 => ['created_date_relative', '=', 0], | |
355 | ], | |
356 | 3 => [ | |
357 | 0 => ['log_date', '=', 2], | |
358 | 'relative_dates' => [], | |
359 | 3 => ['modified_date_relative', '=', 'this.month'], | |
360 | ], | |
361 | 4 => [ | |
362 | 0 => ['log_date', '=', 2], | |
363 | 1 => ['modified_date_low', '=', '2019-10-01 00:00:00'], | |
364 | 2 => ['modified_date_relative', '=', 0], | |
365 | ], | |
3a431eaa SL |
366 | 5 => [ |
367 | 'relative_dates' => [], | |
368 | 2 => ['created_date_relative', '=', 'this.month'], | |
369 | ], | |
370 | 6 => [ | |
371 | 0 => ['created_date_low', '=', '2019-10-01 00:00:00'], | |
372 | 1 => ['created_date_relative', '=', 0], | |
373 | ], | |
70e0d21f SL |
374 | ]; |
375 | } | |
376 | ||
0d679de5 SL |
377 | /** |
378 | * Test converting relationship fields | |
379 | */ | |
380 | public function testSmartGroupRelationshipDateConversions() { | |
381 | $this->callAPISuccess('SavedSearch', 'create', [ | |
382 | 'form_values' => [ | |
383 | ['relationship_start_date_low', '=', '20191001000000'], | |
384 | ['relationship_start_date_high', '=', '20191031235959'], | |
385 | ['relationship_end_date_low', '=', '20191001000000'], | |
386 | ['relationship_end_date_high', '=', '20191031235959'], | |
387 | 'relative_dates' => [ | |
388 | 'relation_start' => 'this.month', | |
389 | 'relation_end' => 'this.month', | |
390 | ], | |
391 | ], | |
392 | ]); | |
393 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); | |
394 | $smartGroupConversionObject->updateGroups([ | |
395 | 'datepickerConversion' => [ | |
396 | 'relationship_start_date', | |
397 | 'relationship_end_date', | |
398 | ], | |
399 | ]); | |
400 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); | |
401 | $this->assertEquals([], $savedSearch['form_values']['relative_dates']); | |
402 | $this->assertEquals(['relationship_start_date_relative', '=', 'this.month'], $savedSearch['form_values'][4]); | |
403 | $this->assertEquals(['relationship_end_date_relative', '=', 'this.month'], $savedSearch['form_values'][5]); | |
404 | } | |
405 | ||
ff77d525 SL |
406 | /** |
407 | * Test convert custom saved search | |
408 | */ | |
409 | public function testSmartGroupCustomDateRangeSearch() { | |
410 | $this->entity = 'Contact'; | |
411 | $this->createCustomGroupWithFieldOfType([], 'date'); | |
412 | $dateCustomFieldName = $this->getCustomFieldName('date'); | |
413 | $this->callAPISuccess('SavedSearch', 'create', [ | |
414 | 'form_values' => [ | |
415 | [$dateCustomFieldName . '_relative', '=', 0], | |
416 | [$dateCustomFieldName, '=', ['BETWEEN' => ['20191001000000', '20191031235959']]], | |
417 | ], | |
418 | ]); | |
419 | $this->callAPISuccess('SavedSearch', 'create', [ | |
420 | 'form_values' => [ | |
421 | [$dateCustomFieldName . '_relative', '=', 0], | |
422 | [$dateCustomFieldName, '=', ['>=' => '20191001000000']], | |
423 | ], | |
424 | ]); | |
425 | $this->callAPISuccess('SavedSearch', 'create', [ | |
426 | 'form_values' => [ | |
427 | [$dateCustomFieldName . '_relative', '=', 0], | |
428 | [$dateCustomFieldName, '=', ['<=' => '20191031235959']], | |
429 | ], | |
430 | ]); | |
431 | $this->callAPISuccess('SavedSearch', 'create', [ | |
432 | 'form_values' => [ | |
433 | [$dateCustomFieldName . '_relative', '=', 'this.month'], | |
434 | ], | |
435 | ]); | |
436 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); | |
437 | $smartGroupConversionObject->convertCustomSmartGroups(); | |
438 | $expectedResults = [ | |
439 | 1 => [ | |
440 | 0 => [$dateCustomFieldName . '_relative', '=', 0], | |
441 | 2 => [$dateCustomFieldName . '_low', '=', '2019-10-01 00:00:00'], | |
442 | 3 => [$dateCustomFieldName . '_high', '=', '2019-10-31 23:59:59'], | |
443 | ], | |
444 | 2 => [ | |
445 | 0 => [$dateCustomFieldName . '_relative', '=', 0], | |
446 | 2 => [$dateCustomFieldName . '_low', '=', '2019-10-01 00:00:00'], | |
447 | ], | |
448 | 3 => [ | |
449 | 0 => [$dateCustomFieldName . '_relative', '=', 0], | |
450 | 2 => [$dateCustomFieldName . '_high', '=', '2019-10-31 23:59:59'], | |
451 | ], | |
452 | 4 => [ | |
453 | 0 => [$dateCustomFieldName . '_relative', '=', 'this.month'], | |
454 | ], | |
455 | ]; | |
456 | $savedSearches = $this->callAPISuccess('SavedSearch', 'get', []); | |
457 | foreach ($savedSearches['values'] as $id => $savedSearch) { | |
458 | $this->assertEquals($expectedResults[$id], $savedSearch['form_values']); | |
459 | } | |
460 | } | |
461 | ||
b4d67eb2 | 462 | /** |
463 | * Test conversion of on hold group. | |
464 | */ | |
465 | public function testOnHoldConversion() { | |
466 | $this->callAPISuccess('SavedSearch', 'create', [ | |
467 | 'form_values' => [ | |
468 | ['on_hold', '=', '1'], | |
39b959db | 469 | ], |
b4d67eb2 | 470 | ]); |
471 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups('5.11.alpha1'); | |
472 | $smartGroupConversionObject->convertEqualsStringToInArray('on_hold'); | |
473 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); | |
474 | $this->assertEquals('IN', $savedSearch['form_values'][0][1]); | |
475 | $this->assertEquals(['1'], $savedSearch['form_values'][0][2]); | |
7bab3351 | 476 | |
477 | } | |
478 | ||
479 | /** | |
480 | * Test renaming a field. | |
481 | */ | |
482 | public function testRenameField() { | |
483 | $this->callAPISuccess('SavedSearch', 'create', [ | |
484 | 'form_values' => [ | |
485 | ['activity_date_low', '=', '01/22/2019'], | |
39b959db | 486 | ], |
7bab3351 | 487 | ]); |
488 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); | |
489 | $smartGroupConversionObject->renameField('activity_date_low', 'activity_date_time_low'); | |
490 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); | |
491 | $this->assertEquals('activity_date_time_low', $savedSearch['form_values'][0][0]); | |
492 | } | |
493 | ||
494 | /** | |
495 | * Test renaming multiple fields. | |
504770b4 | 496 | * |
497 | * @throws Exception | |
7bab3351 | 498 | */ |
499 | public function testRenameFields() { | |
500 | $this->callAPISuccess('SavedSearch', 'create', [ | |
501 | 'form_values' => [ | |
502 | ['activity_date_low', '=', '01/22/2019'], | |
503 | ['activity_date_relative', '=', 0], | |
39b959db | 504 | ], |
7bab3351 | 505 | ]); |
506 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); | |
507 | $smartGroupConversionObject->renameFields([ | |
508 | ['old' => 'activity_date_low', 'new' => 'activity_date_time_low'], | |
509 | ['old' => 'activity_date_relative', 'new' => 'activity_date_time_relative'], | |
510 | ]); | |
511 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); | |
512 | $this->assertEquals('activity_date_time_low', $savedSearch['form_values'][0][0]); | |
513 | $this->assertEquals('activity_date_time_relative', $savedSearch['form_values'][1][0]); | |
b4d67eb2 | 514 | } |
515 | ||
504770b4 | 516 | /** |
517 | * Test that a mis-saved variable in 'contribute settings' can be converted to a | |
518 | * 'proper' setting. | |
519 | */ | |
520 | public function testConvertUpgradeContributeSettings() { | |
ff6f993e | 521 | $setting = [ |
522 | 'deferred_revenue_enabled' => 1, | |
523 | 'invoice_prefix' => 'G_', | |
524 | 'credit_notes_prefix' => 'XX_', | |
525 | 'due_date' => '20', | |
526 | 'due_date_period' => 'weeks', | |
527 | 'notes' => '<p>Give me money</p>', | |
528 | 'tax_term' => 'Extortion', | |
529 | 'tax_display_settings' => 'Exclusive', | |
530 | ]; | |
531 | CRM_Core_DAO::executeQuery("INSERT INTO civicrm_setting (name, domain_id, value) | |
532 | VALUES ('contribution_invoice_settings', 1, '" . serialize($setting) . "')"); | |
504770b4 | 533 | CRM_Upgrade_Incremental_Base::updateContributeSettings(NULL, 5.1); |
534 | $this->assertEquals(1, Civi::settings()->get('deferred_revenue_enabled')); | |
ff6f993e | 535 | $this->assertEquals('G_', Civi::settings()->get('invoice_prefix')); |
536 | $this->assertEquals('XX_', Civi::settings()->get('credit_notes_prefix')); | |
537 | $this->assertEquals('20', Civi::settings()->get('invoice_due_date')); | |
538 | $this->assertEquals('weeks', Civi::settings()->get('invoice_due_date_period')); | |
539 | $this->assertEquals('<p>Give me money</p>', Civi::settings()->get('invoice_notes')); | |
540 | $this->assertEquals('Extortion', Civi::settings()->get('tax_term')); | |
541 | $this->assertEquals('Exclusive', Civi::settings()->get('tax_display_settings')); | |
504770b4 | 542 | } |
543 | ||
6ebc7a89 SL |
544 | /** |
545 | * dev/core#1405 Test fixing option groups with spaces in the name | |
546 | */ | |
547 | public function testFixOptionGroupName() { | |
548 | $name = 'This is a test Name'; | |
549 | $fixedName = CRM_Utils_String::titleToVar(strtolower($name)); | |
550 | $optionGroup = $this->callAPISuccess('OptionGroup', 'create', [ | |
551 | 'title' => 'Test Option Group', | |
552 | 'name' => $name, | |
553 | ]); | |
554 | // API is hardened to strip the spaces to lets re-add in now | |
555 | CRM_Core_DAO::executeQuery("UPDATE civicrm_option_group SET name = %1 WHERE id = %2", [ | |
556 | 1 => [$name, 'String'], | |
557 | 2 => [$optionGroup['id'], 'Positive'], | |
558 | ]); | |
559 | $preUpgrade = $this->callAPISuccess('OptionGroup', 'getsingle', ['id' => $optionGroup['id']]); | |
560 | $this->assertEquals($name, $preUpgrade['name']); | |
561 | CRM_Upgrade_Incremental_php_FiveTwentyOne::fixOptionGroupName(); | |
562 | $postUpgrade = $this->callAPISuccess('OptionGroup', 'getsingle', ['id' => $optionGroup['id']]); | |
563 | $this->assertEquals($fixedName, $postUpgrade['name'], 'Ensure that the spaces have been removed from OptionGroup name'); | |
564 | $this->assertEquals($postUpgrade['name'], $optionGroup['values'][$optionGroup['id']]['name'], 'Ensure that the fixed name matches what the API would produce'); | |
76c5033a SL |
565 | $this->callAPISuccess('OptionGroup', 'delete', ['id' => $optionGroup['id']]); |
566 | } | |
567 | ||
568 | /** | |
569 | * Test that if there is an option group name as the same as the proposed fix name that doesn't cause a hard fail in the upgrade | |
570 | */ | |
571 | public function testFixOptionGroupNameWithFixedNameInDatabase() { | |
572 | $name = 'This is a test Name'; | |
573 | $fixedName = CRM_Utils_String::titleToVar(strtolower($name)); | |
574 | $optionGroup = $this->callAPISuccess('OptionGroup', 'create', [ | |
575 | 'title' => 'Test Option Group', | |
576 | 'name' => $name, | |
577 | ]); | |
578 | // API is hardened to strip the spaces to lets re-add in now | |
579 | CRM_Core_DAO::executeQuery("UPDATE civicrm_option_group SET name = %1 WHERE id = %2", [ | |
580 | 1 => [$name, 'String'], | |
581 | 2 => [$optionGroup['id'], 'Positive'], | |
582 | ]); | |
583 | $optionGroup2 = $this->callAPISuccess('OptionGroup', 'create', [ | |
584 | 'title' => 'Test Option Group 2', | |
585 | 'name' => $name, | |
586 | ]); | |
587 | $preUpgrade = $this->callAPISuccess('OptionGroup', 'getsingle', ['id' => $optionGroup['id']]); | |
588 | $this->assertEquals($name, $preUpgrade['name']); | |
589 | $preUpgrade = $this->callAPISuccess('OptionGroup', 'getsingle', ['id' => $optionGroup2['id']]); | |
590 | $this->assertEquals($fixedName, $preUpgrade['name']); | |
591 | CRM_Upgrade_Incremental_php_FiveTwentyOne::fixOptionGroupName(); | |
592 | $this->callAPISuccess('OptionGroup', 'delete', ['id' => $optionGroup['id']]); | |
593 | $this->callAPISuccess('OptionGroup', 'delete', ['id' => $optionGroup2['id']]); | |
6ebc7a89 SL |
594 | } |
595 | ||
6d6630cf SL |
596 | /** |
597 | * Test conversion between jcalendar and datepicker in reports | |
598 | */ | |
599 | public function testReportFormConvertDatePicker() { | |
600 | $report = $this->callAPISuccess('ReportInstance', 'create', [ | |
601 | 'report_id' => 'contribute/detail', | |
602 | 'form_values' => [ | |
603 | 'fields' => [ | |
604 | 'sort_name' => 1, | |
605 | 'email' => 1, | |
606 | 'phone' => 1, | |
607 | 'financial_type_id' => 1, | |
608 | 'receive_date' => 1, | |
609 | 'total_amount' => 1, | |
610 | 'country_id' => 1, | |
611 | ], | |
612 | 'sort_name_op' => 'has', | |
613 | 'sort_name_value' => '', | |
614 | 'id_min' => '', | |
615 | 'id_max' => '', | |
616 | 'id_op' => 'lte', | |
617 | 'id_value' => '', | |
618 | 'contact_type_op' => 'in', | |
619 | 'contact_type_value' => [], | |
620 | 'contact_sub_type_op' => 'in', | |
621 | 'contact_sub_type_value' => [], | |
622 | 'is_deleted_op' => 'eq', | |
623 | 'is_deleted_value' => 0, | |
624 | 'preferred_language_op' => 'in', | |
625 | 'preferred_language_value' => [], | |
626 | 'do_not_email_op' => 'eq', | |
627 | 'do_not_email_value' => '', | |
628 | 'do_not_phone_op' => 'eq', | |
629 | 'do_not_phone_value' => '', | |
630 | 'do_not_mail_op' => 'eq', | |
631 | 'do_not_mail_value' => '', | |
632 | 'do_not_sms_op' => 'eq', | |
633 | 'do_not_sms_value' => '', | |
634 | 'is_opt_out_op' => 'eq', | |
635 | 'is_opt_out_value' => '', | |
636 | 'first_name_op' => 'has', | |
637 | 'first_name_value' => '', | |
638 | 'prefix_id_op' => 'in', | |
639 | 'prefix_id_value' => [], | |
640 | 'suffix_id_op' => 'in', | |
641 | 'suffix_id_value' => [], | |
642 | 'gender_id_op' => 'in', | |
643 | 'gender_id_value' => [], | |
644 | 'birth_date_relative' => '', | |
645 | 'birth_date_from' => '', | |
646 | 'birth_date_to' => '', | |
647 | 'is_deceased_op' => 'eq', | |
648 | 'is_deceased_value' => '', | |
649 | 'contribution_or_soft_op' => 'eq', | |
650 | 'contribution_or_soft_value' => 'contributions_only', | |
651 | 'receive_date_relative' => 0, | |
652 | 'receive_date_from' => '11/01/1991', | |
653 | 'receive_date_to' => '', | |
654 | 'thankyou_date_relative' => '', | |
655 | 'thankyou_date_from' => '', | |
656 | 'thankyou_date_to' => '', | |
657 | 'contribution_source_op' => 'has', | |
658 | 'contribution_source_value' => '', | |
659 | 'currency_op' => 'in', | |
660 | 'currency_value' => [], | |
661 | 'non_deductible_amount_min' => '', | |
662 | 'non_deductible_amount_max' => '', | |
663 | 'non_deductible_amount_op' => 'lte', | |
664 | 'non_deductible_amount_value' => '', | |
665 | 'financial_type_id_op' => 'in', | |
666 | 'financial_type_id_value' => [], | |
667 | 'contribution_page_id_op' => 'in', | |
668 | 'contribution_page_id_value' => [], | |
669 | 'payment_instrument_id_op' => 'in', | |
670 | 'payment_instrument_id_value' => [], | |
671 | 'contribution_status_id_op' => 'in', | |
672 | 'contribution_status_id_value' => [0 => 1], | |
673 | 'total_amount_min' => '', | |
674 | 'total_amount_max' => '', | |
675 | 'total_amount_op' => 'lte', | |
676 | 'total_amount_value' => '', | |
677 | 'cancel_date_relative' => '', | |
678 | 'cancel_date_from' => '', | |
679 | 'cancel_date_to' => '', | |
680 | 'cancel_reason_op' => 'has', | |
681 | 'cancel_reason_value' => '', | |
682 | 'soft_credit_type_id_op' => 'in', | |
683 | 'soft_credit_type_id_value' => [], | |
684 | 'card_type_id_op' => 'in', | |
685 | 'card_type_id_value' => [], | |
686 | 'ordinality_op' => 'in', | |
687 | 'ordinality_value' => [], | |
688 | 'note_value' => '', | |
689 | 'street_address_op' => 'has', | |
690 | 'street_address_value' => '', | |
691 | 'postal_code_op' => 'has', | |
692 | 'postal_code_value' => '', | |
693 | 'city_op' => 'has', | |
694 | 'city_value' => '', | |
695 | 'country_id_op' => 'in', | |
696 | 'country_id_value' => [], | |
697 | 'state_province_id_op' => 'in', | |
698 | 'state_province_id_value' => [], | |
699 | 'county_id_op' => 'in', | |
700 | 'county_id_value' => [], | |
701 | 'tagid_op' => 'in', | |
702 | 'tagid_value' => [], | |
703 | 'gid_op' => 'in', | |
704 | 'gid_value' => [], | |
705 | 'group_bys' => ['contribution_id' => 1], | |
706 | 'order_bys' => [ | |
707 | 1 => [ | |
708 | 'column' => 'sort_name', | |
709 | 'order' => 'ASC', | |
710 | ], | |
711 | ], | |
712 | 'description' => 'Lists specific contributions by criteria including contact, time period, contribution type, contributor location, etc. Contribution summary report points to this report for contribution details.', | |
713 | 'email_subject' => '', | |
714 | 'email_to' => '', | |
715 | 'email_cc' => '', | |
716 | 'row_count' => '', | |
717 | 'view_mode' => 'criteria', | |
718 | 'cache_minutes' => 60, | |
719 | 'permission' => 'access CiviContribute', | |
720 | 'parent_id' => '', | |
721 | 'radio_ts' => '', | |
722 | 'groups' => '', | |
723 | 'report_id' => 'contribute/detail', | |
724 | ], | |
725 | 'title' => 'test Report', | |
726 | ]); | |
727 | CRM_Upgrade_Incremental_php_FiveTwentyFive::convertReportsJcalendarToDatePicker(); | |
728 | $reportGet = $this->callAPISuccess('ReportInstance', 'getsingle', ['id' => $report['id']]); | |
729 | $formValues = unserialize($reportGet['form_values']); | |
730 | $this->assertEquals('1991-11-01 00:00:00', $formValues['receive_date_from']); | |
731 | } | |
732 | ||
faf0012b SL |
733 | public function testUpdateContactTypeNameField() { |
734 | CRM_Core_DAO::executeQuery("INSERT INTO civicrm_contact_type (name,label,parent_id, is_active) VALUES ('', 'Test Contact Type', 1, 1)"); | |
735 | CRM_Upgrade_Incremental_php_FiveTwentyEight::populateMissingContactTypeName(); | |
736 | $contactType = $this->callAPISuccess('ContactType', 'getsingle', ['label' => 'Test Contact Type']); | |
737 | $this->assertNotEmpty($contactType['name']); | |
738 | $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType['id']]); | |
739 | } | |
740 | ||
fe83c251 | 741 | } |