Merge pull request #18544 from magnolia61/participant_status_notification_default
[civicrm-core.git] / tests / phpunit / CRM / Upgrade / Incremental / php / FiveTwentyTest.php
1 <?php
2 require_once 'CiviTest/CiviCaseTestCase.php';
3
4 /**
5 * Class CRM_Upgrade_Incremental_php_FiveTwentyTest
6 * @group headless
7 */
8 class CRM_Upgrade_Incremental_php_FiveTwentyTest extends CiviCaseTestCase {
9
10 public function setUp() {
11 parent::setUp();
12 }
13
14 /**
15 * Test that the upgrade task changes the direction but only
16 * for bidirectional relationship types that are b_a.
17 */
18 public function testChangeCaseTypeAutoassignee() {
19
20 // We don't know what the ids are for the relationship types since it
21 // seems to depend what ran before us, so retrieve them first and go by
22 // name.
23 // Also spouse might not exist.
24
25 $result = $this->callAPISuccess('RelationshipType', 'get', ['limit' => 0])['values'];
26 // Get list of ids keyed on name.
27 $relationshipTypeNames = array_column($result, 'id', 'name_b_a');
28
29 // Create spouse if none.
30 if (!isset($relationshipTypeNames['Spouse of'])) {
31 $spouseId = $this->relationshipTypeCreate([
32 'name_a_b' => 'Spouse of',
33 'name_b_a' => 'Spouse of',
34 'label_a_b' => 'Spouse of',
35 'label_b_a' => 'Spouse of',
36 'contact_type_a' => 'Individual',
37 'contact_type_b' => 'Individual',
38 ]);
39 $relationshipTypeNames['Spouse of'] = $spouseId;
40 }
41 // Maybe unnecessary but why not. Slightly different than an undefined
42 // index later when it doesn't exist at all.
43 $this->assertGreaterThan(0, $relationshipTypeNames['Spouse of']);
44
45 /**
46 * Set up xml.
47 * In this sample case type for autoassignees we have:
48 * - a_b unidirectional: Case Coordinator is
49 * - b_a unidirectional: Benefits Specialist
50 * - Bidirectional the way it's stored in 5.16+: Spouse of
51 * - config entry pre-5.16, where it's a bidirectional relationship stored as b_a: Spouse of
52 *
53 * Also just for extra some non-ascii chars in here to show they
54 * don't get borked.
55 */
56 $newCaseTypeXml = <<<ENDXML
57 <?xml version="1.0" encoding="UTF-8"?>
58 <CaseType>
59 <name>test_type</name>
60 <ActivityTypes>
61 <ActivityType>
62 <name>Open Case</name>
63 <max_instances>1</max_instances>
64 </ActivityType>
65 <ActivityType>
66 <name>Email</name>
67 </ActivityType>
68 <ActivityType>
69 <name>Follow up</name>
70 </ActivityType>
71 <ActivityType>
72 <name>Meeting</name>
73 </ActivityType>
74 <ActivityType>
75 <name>Phone Call</name>
76 </ActivityType>
77 <ActivityType>
78 <name>давид</name>
79 </ActivityTypes>
80 <ActivitySets>
81 <ActivitySet>
82 <name>standard_timeline</name>
83 <label>Standard Timeline</label>
84 <timeline>true</timeline>
85 <ActivityTypes>
86 <ActivityType>
87 <name>Open Case</name>
88 <status>Completed</status>
89 <label>Open Case</label>
90 <default_assignee_type>1</default_assignee_type>
91 </ActivityType>
92 </ActivityTypes>
93 </ActivitySet>
94 <ActivitySet>
95 <name>timeline_1</name>
96 <label>AnotherTimeline</label>
97 <timeline>true</timeline>
98 <ActivityTypes>
99 <ActivityType>
100 <name>Follow up</name>
101 <label>Follow up</label>
102 <status>Scheduled</status>
103 <reference_activity>Open Case</reference_activity>
104 <reference_offset>7</reference_offset>
105 <reference_select>newest</reference_select>
106 <default_assignee_type>2</default_assignee_type>
107 <default_assignee_relationship>{$relationshipTypeNames['Senior Services Coordinator']}_b_a</default_assignee_relationship>
108 <default_assignee_contact></default_assignee_contact>
109 </ActivityType>
110 <ActivityType>
111 <name>Follow up</name>
112 <label>Follow up</label>
113 <status>Scheduled</status>
114 <reference_activity>Open Case</reference_activity>
115 <reference_offset>14</reference_offset>
116 <reference_select>newest</reference_select>
117 <default_assignee_type>2</default_assignee_type>
118 <default_assignee_relationship>{$relationshipTypeNames['Benefits Specialist']}_a_b</default_assignee_relationship>
119 <default_assignee_contact></default_assignee_contact>
120 </ActivityType>
121 <ActivityType>
122 <name>Follow up</name>
123 <label>Follow up</label>
124 <status>Scheduled</status>
125 <reference_activity>Open Case</reference_activity>
126 <reference_offset>21</reference_offset>
127 <reference_select>newest</reference_select>
128 <default_assignee_type>2</default_assignee_type>
129 <default_assignee_relationship>{$relationshipTypeNames['Spouse of']}_a_b</default_assignee_relationship>
130 <default_assignee_contact></default_assignee_contact>
131 </ActivityType>
132 <ActivityType>
133 <name>Follow up</name>
134 <label>Follow up</label>
135 <status>Scheduled</status>
136 <reference_activity>Open Case</reference_activity>
137 <reference_offset>28</reference_offset>
138 <reference_select>newest</reference_select>
139 <default_assignee_type>2</default_assignee_type>
140 <default_assignee_relationship>{$relationshipTypeNames['Spouse of']}_b_a</default_assignee_relationship>
141 <default_assignee_contact></default_assignee_contact>
142 </ActivityType>
143 </ActivityTypes>
144 </ActivitySet>
145 </ActivitySets>
146 <CaseRoles>
147 <RelationshipType>
148 <name>Senior Services Coordinator</name>
149 <creator>1</creator>
150 <manager>1</manager>
151 </RelationshipType>
152 <RelationshipType>
153 <name>Spouse of</name>
154 </RelationshipType>
155 <RelationshipType>
156 <name>Benefits Specialist is</name>
157 </RelationshipType>
158 </CaseRoles>
159 <RestrictActivityAsgmtToCmsUser>0</RestrictActivityAsgmtToCmsUser>
160 </CaseType>
161
162 ENDXML;
163
164 $dao = new CRM_Case_DAO_CaseType();
165 $dao->name = 'test_type';
166 $dao->title = 'Test Type';
167 $dao->is_active = 1;
168 $dao->definition = $newCaseTypeXml;
169 $dao->insert();
170
171 $caseTypeId = $dao->id;
172
173 // run the task
174 $upgrader = new CRM_Upgrade_Incremental_php_FiveTwenty();
175 $upgrader->changeCaseTypeAutoassignee();
176
177 // Check if the case type is what we expect. It should be identical except
178 // the b_a spouse one should get converted to the a_b direction.
179 $expectedCaseTypeXml = str_replace(
180 "<default_assignee_relationship>{$relationshipTypeNames['Spouse of']}_b_a",
181 "<default_assignee_relationship>{$relationshipTypeNames['Spouse of']}_a_b",
182 $newCaseTypeXml
183 );
184
185 //echo $expectedCaseTypeXml;
186
187 // Get the updated case type and check.
188 $dao = CRM_Core_DAO::executeQuery("SELECT definition FROM civicrm_case_type WHERE id = {$caseTypeId}");
189 $dao->fetch();
190
191 $this->assertEquals($expectedCaseTypeXml, $dao->definition);
192 }
193
194 /**
195 * Test that the upgrade task converts case role <name>'s that
196 * are labels to their name.
197 */
198 public function testConvertRoleLabelsToNames() {
199
200 // We don't know what the ids are for the relationship types since it
201 // seems to depend what ran before us, so retrieve them first and go by
202 // name.
203 // Also spouse might not exist.
204
205 $result = $this->callAPISuccess('RelationshipType', 'get', ['limit' => 0])['values'];
206 // Get list of ids keyed on name.
207 $relationshipTypeNames = array_column($result, 'id', 'name_b_a');
208
209 // Create spouse if none.
210 if (!isset($relationshipTypeNames['Spouse of'])) {
211 $spouseId = $this->relationshipTypeCreate([
212 'name_a_b' => 'Spouse of',
213 'name_b_a' => 'Spouse of',
214 'label_a_b' => 'Spouse of',
215 'label_b_a' => 'Spouse of',
216 'contact_type_a' => 'Individual',
217 'contact_type_b' => 'Individual',
218 ]);
219 $relationshipTypeNames['Spouse of'] = $spouseId;
220 }
221 // Maybe unnecessary but why not. Slightly different than an undefined
222 // index later when it doesn't exist at all.
223 $this->assertGreaterThan(0, $relationshipTypeNames['Spouse of']);
224
225 // Add one with changed labels
226 $id = $this->relationshipTypeCreate([
227 'name_a_b' => 'Wallet Inspector is',
228 'name_b_a' => 'Wallet Inspector',
229 'label_a_b' => 'has as Wallet Inspector',
230 'label_b_a' => 'is Wallet Inspector of',
231 'contact_type_a' => 'Individual',
232 'contact_type_b' => 'Individual',
233 ]);
234 $relationshipTypeNames['Wallet Inspector'] = $id;
235
236 // Add one with non-ascii characters.
237 $id = $this->relationshipTypeCreate([
238 'name_a_b' => 'абвгде is',
239 'name_b_a' => 'абвгде',
240 'label_a_b' => 'абвгде is',
241 'label_b_a' => 'абвгде',
242 'contact_type_a' => 'Individual',
243 'contact_type_b' => 'Individual',
244 ]);
245 $relationshipTypeNames['Ascii'] = $id;
246
247 // Add one with non-ascii characters changed labels.
248 $id = $this->relationshipTypeCreate([
249 'name_a_b' => 'αβγδ is',
250 'name_b_a' => 'αβγδ',
251 'label_a_b' => 'αβγδ is changed',
252 'label_b_a' => 'αβγδ changed',
253 'contact_type_a' => 'Individual',
254 'contact_type_b' => 'Individual',
255 ]);
256 $relationshipTypeNames['Ascii changed'] = $id;
257
258 // Create some case types
259 $caseTypes = $this->createCaseTypes($relationshipTypeNames, 1);
260
261 // run the task
262 $upgrader = new CRM_Upgrade_Incremental_php_FiveTwenty();
263 // first, preupgrade messages should be blank here
264 $preupgradeMessages = $upgrader->_changeCaseTypeLabelToName(TRUE);
265 $this->assertEmpty($preupgradeMessages);
266
267 // Now the actual run
268 $upgrader->changeCaseTypeLabelToName();
269
270 // Get the updated case types and check.
271 $sqlParams = [
272 1 => [implode(',', array_keys($caseTypes)), 'String'],
273 ];
274 $dao = CRM_Core_DAO::executeQuery("SELECT id, name, definition FROM civicrm_case_type WHERE id IN (%1)", $sqlParams);
275 while ($dao->fetch()) {
276 $this->assertEquals($caseTypes[$dao->id]['expected'], $dao->definition, "Case type {$dao->name}");
277 // clean up
278 CRM_Core_DAO::executeQuery("DELETE FROM civicrm_case_type WHERE id = {$dao->id}");
279 }
280
281 //
282 // Second pass, where we have some edge cases.
283 //
284
285 // Add a relationship type that has the same labels as another.
286 $id = $this->relationshipTypeCreate([
287 'name_a_b' => 'mixedupab',
288 'name_b_a' => 'mixedupba',
289 'label_a_b' => 'Benefits Specialist',
290 'label_b_a' => 'Benefits Specialist is',
291 'contact_type_a' => 'Individual',
292 'contact_type_b' => 'Individual',
293 ]);
294 $relationshipTypeNames['mixedup'] = $id;
295
296 // Add a relationship type that appears to be bidirectional but different
297 // names.
298 $id = $this->relationshipTypeCreate([
299 'name_a_b' => 'diffnameab',
300 'name_b_a' => 'diffnameba',
301 'label_a_b' => 'Archenemy of',
302 'label_b_a' => 'Archenemy of',
303 'contact_type_a' => 'Individual',
304 'contact_type_b' => 'Individual',
305 ]);
306 $relationshipTypeNames['diffname'] = $id;
307
308 // Second pass for case type creation.
309 $caseTypes = $this->createCaseTypes($relationshipTypeNames, 2);
310
311 // run the task
312 $upgrader = new CRM_Upgrade_Incremental_php_FiveTwenty();
313 // first, check preupgrade messages
314 $preupgradeMessages = $upgrader->_changeCaseTypeLabelToName(TRUE);
315 $this->assertEquals($this->getExpectedUpgradeMessages(), $preupgradeMessages);
316
317 // Now the actual run
318 $upgrader->changeCaseTypeLabelToName();
319
320 // Get the updated case types and check.
321 $sqlParams = [
322 1 => [implode(',', array_keys($caseTypes)), 'String'],
323 ];
324 $dao = CRM_Core_DAO::executeQuery("SELECT id, name, definition FROM civicrm_case_type WHERE id IN (%1)", $sqlParams);
325 while ($dao->fetch()) {
326 $this->assertEquals($caseTypes[$dao->id]['expected'], $dao->definition, "Case type {$dao->name}");
327 // clean up
328 CRM_Core_DAO::executeQuery("DELETE FROM civicrm_case_type WHERE id = {$dao->id}");
329 }
330 }
331
332 /**
333 * Set up some original and expected xml pairs.
334 *
335 * @param $relationshipTypeNames array
336 * @param $stage int
337 * We run it in a couple passes because we want to test with and without
338 * warning messages.
339 * @return array
340 */
341 private function createCaseTypes($relationshipTypeNames, $stage) {
342 $xmls = [];
343
344 switch ($stage) {
345 case 1:
346 $newCaseTypeXml = <<<ENDXMLSIMPLE
347 <?xml version="1.0" encoding="UTF-8"?>
348 <CaseType>
349 <name>simple</name>
350 <ActivityTypes>
351 <ActivityType>
352 <name>Open Case</name>
353 <max_instances>1</max_instances>
354 </ActivityType>
355 <ActivityType>
356 <name>Email</name>
357 </ActivityType>
358 <ActivityType>
359 <name>Follow up</name>
360 </ActivityType>
361 <ActivityType>
362 <name>Meeting</name>
363 </ActivityType>
364 <ActivityType>
365 <name>Phone Call</name>
366 </ActivityType>
367 </ActivityTypes>
368 <ActivitySets>
369 <ActivitySet>
370 <name>standard_timeline</name>
371 <label>Standard Timeline</label>
372 <timeline>true</timeline>
373 <ActivityTypes>
374 <ActivityType>
375 <name>Open Case</name>
376 <status>Completed</status>
377 <label>Open Case</label>
378 <default_assignee_type>1</default_assignee_type>
379 </ActivityType>
380 </ActivityTypes>
381 </ActivitySet>
382 <ActivitySet>
383 <name>timeline_1</name>
384 <label>AnotherTimeline</label>
385 <timeline>true</timeline>
386 <ActivityTypes>
387 <ActivityType>
388 <name>Follow up</name>
389 <label>Follow up</label>
390 <status>Scheduled</status>
391 <reference_activity>Open Case</reference_activity>
392 <reference_offset>7</reference_offset>
393 <reference_select>newest</reference_select>
394 <default_assignee_type>2</default_assignee_type>
395 <default_assignee_relationship>{$relationshipTypeNames['Senior Services Coordinator']}_b_a</default_assignee_relationship>
396 <default_assignee_contact></default_assignee_contact>
397 </ActivityType>
398 </ActivityTypes>
399 </ActivitySet>
400 </ActivitySets>
401 <CaseRoles>
402 <RelationshipType>
403 <name>Senior Services Coordinator</name>
404 <creator>1</creator>
405 <manager>1</manager>
406 </RelationshipType>
407 <RelationshipType>
408 <name>Spouse of</name>
409 </RelationshipType>
410 <RelationshipType>
411 <name>Benefits Specialist is</name>
412 </RelationshipType>
413 <RelationshipType>
414 <name>is Wallet Inspector of</name>
415 </RelationshipType>
416 <RelationshipType>
417 <name>has as Wallet Inspector</name>
418 </RelationshipType>
419 <RelationshipType>
420 <name>абвгде</name>
421 </RelationshipType>
422 <RelationshipType>
423 <name>αβγδ changed</name>
424 </RelationshipType>
425 </CaseRoles>
426 <RestrictActivityAsgmtToCmsUser>0</RestrictActivityAsgmtToCmsUser>
427 </CaseType>
428
429 ENDXMLSIMPLE;
430
431 $expectedCaseTypeXml = <<<ENDXMLSIMPLEEXPECTED
432 <?xml version="1.0" encoding="UTF-8"?>
433 <CaseType>
434 <name>simple</name>
435 <ActivityTypes>
436 <ActivityType>
437 <name>Open Case</name>
438 <max_instances>1</max_instances>
439 </ActivityType>
440 <ActivityType>
441 <name>Email</name>
442 </ActivityType>
443 <ActivityType>
444 <name>Follow up</name>
445 </ActivityType>
446 <ActivityType>
447 <name>Meeting</name>
448 </ActivityType>
449 <ActivityType>
450 <name>Phone Call</name>
451 </ActivityType>
452 </ActivityTypes>
453 <ActivitySets>
454 <ActivitySet>
455 <name>standard_timeline</name>
456 <label>Standard Timeline</label>
457 <timeline>true</timeline>
458 <ActivityTypes>
459 <ActivityType>
460 <name>Open Case</name>
461 <status>Completed</status>
462 <label>Open Case</label>
463 <default_assignee_type>1</default_assignee_type>
464 </ActivityType>
465 </ActivityTypes>
466 </ActivitySet>
467 <ActivitySet>
468 <name>timeline_1</name>
469 <label>AnotherTimeline</label>
470 <timeline>true</timeline>
471 <ActivityTypes>
472 <ActivityType>
473 <name>Follow up</name>
474 <label>Follow up</label>
475 <status>Scheduled</status>
476 <reference_activity>Open Case</reference_activity>
477 <reference_offset>7</reference_offset>
478 <reference_select>newest</reference_select>
479 <default_assignee_type>2</default_assignee_type>
480 <default_assignee_relationship>{$relationshipTypeNames['Senior Services Coordinator']}_b_a</default_assignee_relationship>
481 <default_assignee_contact></default_assignee_contact>
482 </ActivityType>
483 </ActivityTypes>
484 </ActivitySet>
485 </ActivitySets>
486 <CaseRoles>
487 <RelationshipType>
488 <name>Senior Services Coordinator</name>
489 <creator>1</creator>
490 <manager>1</manager>
491 </RelationshipType>
492 <RelationshipType>
493 <name>Spouse of</name>
494 </RelationshipType>
495 <RelationshipType>
496 <name>Benefits Specialist is</name>
497 </RelationshipType>
498 <RelationshipType>
499 <name>Wallet Inspector</name>
500 </RelationshipType>
501 <RelationshipType>
502 <name>Wallet Inspector is</name>
503 </RelationshipType>
504 <RelationshipType>
505 <name>абвгде</name>
506 </RelationshipType>
507 <RelationshipType>
508 <name>αβγδ</name>
509 </RelationshipType>
510 </CaseRoles>
511 <RestrictActivityAsgmtToCmsUser>0</RestrictActivityAsgmtToCmsUser>
512 </CaseType>
513
514 ENDXMLSIMPLEEXPECTED;
515
516 $caseTypeId = $this->addCaseType('simple', $newCaseTypeXml);
517 $xmls[$caseTypeId] = [
518 'id' => $caseTypeId,
519 'expected' => $expectedCaseTypeXml,
520 ];
521 break;
522
523 case 2:
524 // Note for these ones the roles that have warnings should remain
525 // unchanged if they choose to continue with the upgrade.
526
527 $newCaseTypeXml = <<<ENDXMLMIXEDUP
528 <?xml version="1.0" encoding="UTF-8"?>
529 <CaseType>
530 <name>mixedup</name>
531 <ActivityTypes>
532 <ActivityType>
533 <name>Open Case</name>
534 <max_instances>1</max_instances>
535 </ActivityType>
536 <ActivityType>
537 <name>Email</name>
538 </ActivityType>
539 <ActivityType>
540 <name>Follow up</name>
541 </ActivityType>
542 <ActivityType>
543 <name>Meeting</name>
544 </ActivityType>
545 <ActivityType>
546 <name>Phone Call</name>
547 </ActivityType>
548 </ActivityTypes>
549 <ActivitySets>
550 <ActivitySet>
551 <name>standard_timeline</name>
552 <label>Standard Timeline</label>
553 <timeline>true</timeline>
554 <ActivityTypes>
555 <ActivityType>
556 <name>Open Case</name>
557 <status>Completed</status>
558 <label>Open Case</label>
559 <default_assignee_type>1</default_assignee_type>
560 </ActivityType>
561 </ActivityTypes>
562 </ActivitySet>
563 <ActivitySet>
564 <name>timeline_1</name>
565 <label>AnotherTimeline</label>
566 <timeline>true</timeline>
567 <ActivityTypes>
568 <ActivityType>
569 <name>Follow up</name>
570 <label>Follow up</label>
571 <status>Scheduled</status>
572 <reference_activity>Open Case</reference_activity>
573 <reference_offset>7</reference_offset>
574 <reference_select>newest</reference_select>
575 <default_assignee_type>2</default_assignee_type>
576 <default_assignee_relationship>{$relationshipTypeNames['Senior Services Coordinator']}_b_a</default_assignee_relationship>
577 <default_assignee_contact></default_assignee_contact>
578 </ActivityType>
579 </ActivityTypes>
580 </ActivitySet>
581 </ActivitySets>
582 <CaseRoles>
583 <RelationshipType>
584 <name>Senior Services Coordinator</name>
585 <creator>1</creator>
586 <manager>1</manager>
587 </RelationshipType>
588 <RelationshipType>
589 <name>Spouse of</name>
590 </RelationshipType>
591 <RelationshipType>
592 <name>Benefits Specialist is</name>
593 </RelationshipType>
594 <RelationshipType>
595 <name>is Wallet Inspector of</name>
596 </RelationshipType>
597 <RelationshipType>
598 <name>has as Wallet Inspector</name>
599 </RelationshipType>
600 <RelationshipType>
601 <name>абвгде</name>
602 </RelationshipType>
603 <RelationshipType>
604 <name>αβγδ changed</name>
605 </RelationshipType>
606 <RelationshipType>
607 <name>Benefits Specialist</name>
608 </RelationshipType>
609 <RelationshipType>
610 <name>Mythical Unicorn</name>
611 </RelationshipType>
612 </CaseRoles>
613 <RestrictActivityAsgmtToCmsUser>0</RestrictActivityAsgmtToCmsUser>
614 </CaseType>
615
616 ENDXMLMIXEDUP;
617
618 $expectedCaseTypeXml = <<<ENDXMLMIXEDUPEXPECTED
619 <?xml version="1.0" encoding="UTF-8"?>
620 <CaseType>
621 <name>mixedup</name>
622 <ActivityTypes>
623 <ActivityType>
624 <name>Open Case</name>
625 <max_instances>1</max_instances>
626 </ActivityType>
627 <ActivityType>
628 <name>Email</name>
629 </ActivityType>
630 <ActivityType>
631 <name>Follow up</name>
632 </ActivityType>
633 <ActivityType>
634 <name>Meeting</name>
635 </ActivityType>
636 <ActivityType>
637 <name>Phone Call</name>
638 </ActivityType>
639 </ActivityTypes>
640 <ActivitySets>
641 <ActivitySet>
642 <name>standard_timeline</name>
643 <label>Standard Timeline</label>
644 <timeline>true</timeline>
645 <ActivityTypes>
646 <ActivityType>
647 <name>Open Case</name>
648 <status>Completed</status>
649 <label>Open Case</label>
650 <default_assignee_type>1</default_assignee_type>
651 </ActivityType>
652 </ActivityTypes>
653 </ActivitySet>
654 <ActivitySet>
655 <name>timeline_1</name>
656 <label>AnotherTimeline</label>
657 <timeline>true</timeline>
658 <ActivityTypes>
659 <ActivityType>
660 <name>Follow up</name>
661 <label>Follow up</label>
662 <status>Scheduled</status>
663 <reference_activity>Open Case</reference_activity>
664 <reference_offset>7</reference_offset>
665 <reference_select>newest</reference_select>
666 <default_assignee_type>2</default_assignee_type>
667 <default_assignee_relationship>{$relationshipTypeNames['Senior Services Coordinator']}_b_a</default_assignee_relationship>
668 <default_assignee_contact></default_assignee_contact>
669 </ActivityType>
670 </ActivityTypes>
671 </ActivitySet>
672 </ActivitySets>
673 <CaseRoles>
674 <RelationshipType>
675 <name>Senior Services Coordinator</name>
676 <creator>1</creator>
677 <manager>1</manager>
678 </RelationshipType>
679 <RelationshipType>
680 <name>Spouse of</name>
681 </RelationshipType>
682 <RelationshipType>
683 <name>Benefits Specialist is</name>
684 </RelationshipType>
685 <RelationshipType>
686 <name>Wallet Inspector</name>
687 </RelationshipType>
688 <RelationshipType>
689 <name>Wallet Inspector is</name>
690 </RelationshipType>
691 <RelationshipType>
692 <name>абвгде</name>
693 </RelationshipType>
694 <RelationshipType>
695 <name>αβγδ</name>
696 </RelationshipType>
697 <RelationshipType>
698 <name>Benefits Specialist</name>
699 </RelationshipType>
700 <RelationshipType>
701 <name>Mythical Unicorn</name>
702 </RelationshipType>
703 </CaseRoles>
704 <RestrictActivityAsgmtToCmsUser>0</RestrictActivityAsgmtToCmsUser>
705 </CaseType>
706
707 ENDXMLMIXEDUPEXPECTED;
708
709 $caseTypeId = $this->addCaseType('mixedup', $newCaseTypeXml);
710 $xmls[$caseTypeId] = [
711 'id' => $caseTypeId,
712 'expected' => $expectedCaseTypeXml,
713 ];
714
715 $newCaseTypeXml = <<<ENDXMLDIFFNAME
716 <?xml version="1.0" encoding="UTF-8"?>
717 <CaseType>
718 <name>diffname</name>
719 <ActivityTypes>
720 <ActivityType>
721 <name>Open Case</name>
722 <max_instances>1</max_instances>
723 </ActivityType>
724 <ActivityType>
725 <name>Email</name>
726 </ActivityType>
727 <ActivityType>
728 <name>Follow up</name>
729 </ActivityType>
730 <ActivityType>
731 <name>Meeting</name>
732 </ActivityType>
733 <ActivityType>
734 <name>Phone Call</name>
735 </ActivityType>
736 </ActivityTypes>
737 <ActivitySets>
738 <ActivitySet>
739 <name>standard_timeline</name>
740 <label>Standard Timeline</label>
741 <timeline>true</timeline>
742 <ActivityTypes>
743 <ActivityType>
744 <name>Open Case</name>
745 <status>Completed</status>
746 <label>Open Case</label>
747 <default_assignee_type>1</default_assignee_type>
748 </ActivityType>
749 </ActivityTypes>
750 </ActivitySet>
751 <ActivitySet>
752 <name>timeline_1</name>
753 <label>AnotherTimeline</label>
754 <timeline>true</timeline>
755 <ActivityTypes>
756 <ActivityType>
757 <name>Follow up</name>
758 <label>Follow up</label>
759 <status>Scheduled</status>
760 <reference_activity>Open Case</reference_activity>
761 <reference_offset>7</reference_offset>
762 <reference_select>newest</reference_select>
763 <default_assignee_type>2</default_assignee_type>
764 <default_assignee_relationship>{$relationshipTypeNames['Senior Services Coordinator']}_b_a</default_assignee_relationship>
765 <default_assignee_contact></default_assignee_contact>
766 </ActivityType>
767 </ActivityTypes>
768 </ActivitySet>
769 </ActivitySets>
770 <CaseRoles>
771 <RelationshipType>
772 <name>Senior Services Coordinator</name>
773 <creator>1</creator>
774 <manager>1</manager>
775 </RelationshipType>
776 <RelationshipType>
777 <name>Spouse of</name>
778 </RelationshipType>
779 <RelationshipType>
780 <name>Benefits Specialist is</name>
781 </RelationshipType>
782 <RelationshipType>
783 <name>is Wallet Inspector of</name>
784 </RelationshipType>
785 <RelationshipType>
786 <name>has as Wallet Inspector</name>
787 </RelationshipType>
788 <RelationshipType>
789 <name>абвгде</name>
790 </RelationshipType>
791 <RelationshipType>
792 <name>αβγδ changed</name>
793 </RelationshipType>
794 <RelationshipType>
795 <name>Archenemy of</name>
796 </RelationshipType>
797 </CaseRoles>
798 <RestrictActivityAsgmtToCmsUser>0</RestrictActivityAsgmtToCmsUser>
799 </CaseType>
800
801 ENDXMLDIFFNAME;
802
803 $expectedCaseTypeXml = <<<ENDXMLDIFFNAMEEXPECTED
804 <?xml version="1.0" encoding="UTF-8"?>
805 <CaseType>
806 <name>diffname</name>
807 <ActivityTypes>
808 <ActivityType>
809 <name>Open Case</name>
810 <max_instances>1</max_instances>
811 </ActivityType>
812 <ActivityType>
813 <name>Email</name>
814 </ActivityType>
815 <ActivityType>
816 <name>Follow up</name>
817 </ActivityType>
818 <ActivityType>
819 <name>Meeting</name>
820 </ActivityType>
821 <ActivityType>
822 <name>Phone Call</name>
823 </ActivityType>
824 </ActivityTypes>
825 <ActivitySets>
826 <ActivitySet>
827 <name>standard_timeline</name>
828 <label>Standard Timeline</label>
829 <timeline>true</timeline>
830 <ActivityTypes>
831 <ActivityType>
832 <name>Open Case</name>
833 <status>Completed</status>
834 <label>Open Case</label>
835 <default_assignee_type>1</default_assignee_type>
836 </ActivityType>
837 </ActivityTypes>
838 </ActivitySet>
839 <ActivitySet>
840 <name>timeline_1</name>
841 <label>AnotherTimeline</label>
842 <timeline>true</timeline>
843 <ActivityTypes>
844 <ActivityType>
845 <name>Follow up</name>
846 <label>Follow up</label>
847 <status>Scheduled</status>
848 <reference_activity>Open Case</reference_activity>
849 <reference_offset>7</reference_offset>
850 <reference_select>newest</reference_select>
851 <default_assignee_type>2</default_assignee_type>
852 <default_assignee_relationship>{$relationshipTypeNames['Senior Services Coordinator']}_b_a</default_assignee_relationship>
853 <default_assignee_contact></default_assignee_contact>
854 </ActivityType>
855 </ActivityTypes>
856 </ActivitySet>
857 </ActivitySets>
858 <CaseRoles>
859 <RelationshipType>
860 <name>Senior Services Coordinator</name>
861 <creator>1</creator>
862 <manager>1</manager>
863 </RelationshipType>
864 <RelationshipType>
865 <name>Spouse of</name>
866 </RelationshipType>
867 <RelationshipType>
868 <name>Benefits Specialist is</name>
869 </RelationshipType>
870 <RelationshipType>
871 <name>Wallet Inspector</name>
872 </RelationshipType>
873 <RelationshipType>
874 <name>Wallet Inspector is</name>
875 </RelationshipType>
876 <RelationshipType>
877 <name>абвгде</name>
878 </RelationshipType>
879 <RelationshipType>
880 <name>αβγδ</name>
881 </RelationshipType>
882 <RelationshipType>
883 <name>Archenemy of</name>
884 </RelationshipType>
885 </CaseRoles>
886 <RestrictActivityAsgmtToCmsUser>0</RestrictActivityAsgmtToCmsUser>
887 </CaseType>
888
889 ENDXMLDIFFNAMEEXPECTED;
890
891 $caseTypeId = $this->addCaseType('diffname', $newCaseTypeXml);
892 $xmls[$caseTypeId] = [
893 'id' => $caseTypeId,
894 'expected' => $expectedCaseTypeXml,
895 ];
896
897 break;
898
899 default:
900 break;
901 }
902
903 return $xmls;
904 }
905
906 /**
907 * @return array
908 */
909 private function getExpectedUpgradeMessages() {
910 return [
911 "Case Type 'mixedup', role 'Benefits Specialist is' has an ambiguous configuration where the role matches multiple labels and so can't be automatically updated. See the administration console status messages for more info.",
912
913 "Case Type 'mixedup', role 'Benefits Specialist' has an ambiguous configuration where the role matches multiple labels and so can't be automatically updated. See the administration console status messages for more info.",
914
915 "Case Type 'mixedup', role 'Mythical Unicorn' doesn't seem to be a valid role. See the administration console status messages for more info.",
916
917 "Case Type 'diffname', role 'Benefits Specialist is' has an ambiguous configuration where the role matches multiple labels and so can't be automatically updated. See the administration console status messages for more info.",
918
919 "Case Type 'diffname', role 'Archenemy of' has an ambiguous configuration and can't be automatically updated. See the administration console status messages for more info.",
920 ];
921 }
922
923 /**
924 * Helper to add a case type to the database.
925 *
926 * @param $name string
927 * @param $xml string
928 *
929 * @return int
930 */
931 private function addCaseType($name, $xml) {
932 $dao = new CRM_Case_DAO_CaseType();
933 $dao->name = $name;
934 $dao->title = $name;
935 $dao->is_active = 1;
936 $dao->definition = $xml;
937 $dao->insert();
938
939 return $dao->id;
940 }
941
942 }