Commit | Line | Data |
---|---|---|
fe83c251 | 1 | <?php |
2 | ||
3 | /** | |
4 | * Class CRM_UF_Page_ProfileEditorTest | |
5 | * @group headless | |
6 | */ | |
12d387d2 | 7 | class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase { |
fe83c251 | 8 | |
b4d67eb2 | 9 | public function tearDown() { |
10 | $this->quickCleanup(['civicrm_saved_search']); | |
11 | } | |
12 | ||
fe83c251 | 13 | /** |
14 | * Test message upgrade process. | |
15 | */ | |
16 | public function testMessageTemplateUpgrade() { | |
17 | $workFlowID = civicrm_api3('OptionValue', 'getvalue', ['return' => 'id', 'name' => 'membership_online_receipt', 'options' => ['limit' => 1, 'sort' => 'id DESC']]); | |
18 | ||
19 | $templates = $this->callAPISuccess('MessageTemplate', 'get', ['workflow_id' => $workFlowID])['values']; | |
20 | foreach ($templates as $template) { | |
21 | $originalText = $template['msg_text']; | |
22 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a cool member you are', 'id' => $template['id']]); | |
23 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); | |
24 | $this->assertEquals('great what a cool member you are', $msg_text); | |
25 | } | |
26 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); | |
27 | $messageTemplateObject->updateTemplates(); | |
28 | ||
29 | foreach ($templates as $template) { | |
30 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); | |
12d387d2 | 31 | $this->assertContains('{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}{$greeting},{/if}', $msg_text); |
fe83c251 | 32 | if ($msg_text !== $originalText) { |
33 | // Reset value for future tests. | |
34 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => $originalText, 'id' => $template['id']]); | |
35 | } | |
36 | } | |
37 | } | |
38 | ||
39 | /** | |
40 | * Test message upgrade process only edits the default if the template is customised. | |
41 | */ | |
42 | public function testMessageTemplateUpgradeAlreadyCustomised() { | |
43 | $workFlowID = civicrm_api3('OptionValue', 'getvalue', ['return' => 'id', 'name' => 'membership_online_receipt', 'options' => ['limit' => 1, 'sort' => 'id DESC']]); | |
44 | ||
45 | $templates = $this->callAPISuccess('MessageTemplate', 'get', ['workflow_id' => $workFlowID])['values']; | |
46 | foreach ($templates as $template) { | |
47 | if ($template['is_reserved']) { | |
48 | $originalText = $template['msg_text']; | |
49 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a cool member you are', 'id' => $template['id']]); | |
50 | } | |
51 | else { | |
52 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a silly sausage you are', 'id' => $template['id']]); | |
53 | } | |
54 | } | |
55 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); | |
56 | $messageTemplateObject->updateTemplates(); | |
57 | ||
58 | foreach ($templates as $template) { | |
59 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); | |
60 | if ($template['is_reserved']) { | |
12d387d2 | 61 | $this->assertContains('{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}{$greeting},{/if}', $msg_text); |
fe83c251 | 62 | } |
63 | else { | |
64 | $this->assertEquals('great what a silly sausage you are', $msg_text); | |
65 | } | |
66 | ||
67 | if ($msg_text !== $originalText) { | |
68 | // Reset value for future tests. | |
69 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => $originalText, 'id' => $template['id']]); | |
70 | } | |
71 | } | |
72 | } | |
73 | ||
74 | /** | |
75 | * Test function for messages on upgrade. | |
76 | */ | |
77 | public function testMessageTemplateGetUpgradeMessages() { | |
78 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); | |
79 | $messages = $messageTemplateObject->getUpgradeMessages(); | |
12d387d2 | 80 | $this->assertEquals([ |
81 | 'Memberships - Receipt (on-line)' => 'Use email greeting at top where available', | |
82 | 'Contributions - Receipt (on-line)' => 'Use email greeting at top where available', | |
83 | 'Events - Registration Confirmation and Receipt (on-line)' => 'Use email greeting at top where available', | |
84 | ], $messages); | |
fe83c251 | 85 | } |
86 | ||
7015248a | 87 | /** |
88 | * Test converting a datepicker field. | |
89 | */ | |
90 | public function testSmartGroupDatePickerConversion() { | |
91 | $this->callAPISuccess('SavedSearch', 'create', [ | |
39b959db | 92 | 'form_values' => [ |
7015248a | 93 | ['grant_application_received_date_high', '=', '01/20/2019'], |
94 | ['grant_due_date_low', '=', '01/22/2019'], | |
39b959db | 95 | ], |
7015248a | 96 | ]); |
ac241c34 CW |
97 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); |
98 | $smartGroupConversionObject->updateGroups([ | |
99 | 'datepickerConversion' => [ | |
100 | 'grant_application_received_date', | |
101 | 'grant_decision_date', | |
102 | 'grant_money_transfer_date', | |
39b959db SL |
103 | 'grant_due_date', |
104 | ], | |
ac241c34 | 105 | ]); |
7015248a | 106 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); |
107 | $this->assertEquals('grant_application_received_date_high', $savedSearch['form_values'][0][0]); | |
929d5a15 | 108 | $this->assertEquals('2019-01-20 23:59:59', $savedSearch['form_values'][0][2]); |
7015248a | 109 | $this->assertEquals('grant_due_date_low', $savedSearch['form_values'][1][0]); |
110 | $this->assertEquals('2019-01-22 00:00:00', $savedSearch['form_values'][1][2]); | |
929d5a15 | 111 | $hasRelative = FALSE; |
112 | foreach ($savedSearch['form_values'] as $form_value) { | |
113 | if ($form_value[0] === 'grant_due_date_relative') { | |
114 | $hasRelative = TRUE; | |
115 | } | |
116 | } | |
117 | $this->assertEquals(TRUE, $hasRelative); | |
7015248a | 118 | } |
119 | ||
b4d67eb2 | 120 | /** |
121 | * Test conversion of on hold group. | |
122 | */ | |
123 | public function testOnHoldConversion() { | |
124 | $this->callAPISuccess('SavedSearch', 'create', [ | |
125 | 'form_values' => [ | |
126 | ['on_hold', '=', '1'], | |
39b959db | 127 | ], |
b4d67eb2 | 128 | ]); |
129 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups('5.11.alpha1'); | |
130 | $smartGroupConversionObject->convertEqualsStringToInArray('on_hold'); | |
131 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); | |
132 | $this->assertEquals('IN', $savedSearch['form_values'][0][1]); | |
133 | $this->assertEquals(['1'], $savedSearch['form_values'][0][2]); | |
7bab3351 | 134 | |
135 | } | |
136 | ||
137 | /** | |
138 | * Test renaming a field. | |
139 | */ | |
140 | public function testRenameField() { | |
141 | $this->callAPISuccess('SavedSearch', 'create', [ | |
142 | 'form_values' => [ | |
143 | ['activity_date_low', '=', '01/22/2019'], | |
39b959db | 144 | ], |
7bab3351 | 145 | ]); |
146 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); | |
147 | $smartGroupConversionObject->renameField('activity_date_low', 'activity_date_time_low'); | |
148 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); | |
149 | $this->assertEquals('activity_date_time_low', $savedSearch['form_values'][0][0]); | |
150 | } | |
151 | ||
152 | /** | |
153 | * Test renaming multiple fields. | |
154 | */ | |
155 | public function testRenameFields() { | |
156 | $this->callAPISuccess('SavedSearch', 'create', [ | |
157 | 'form_values' => [ | |
158 | ['activity_date_low', '=', '01/22/2019'], | |
159 | ['activity_date_relative', '=', 0], | |
39b959db | 160 | ], |
7bab3351 | 161 | ]); |
162 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); | |
163 | $smartGroupConversionObject->renameFields([ | |
164 | ['old' => 'activity_date_low', 'new' => 'activity_date_time_low'], | |
165 | ['old' => 'activity_date_relative', 'new' => 'activity_date_time_relative'], | |
166 | ]); | |
167 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); | |
168 | $this->assertEquals('activity_date_time_low', $savedSearch['form_values'][0][0]); | |
169 | $this->assertEquals('activity_date_time_relative', $savedSearch['form_values'][1][0]); | |
b4d67eb2 | 170 | } |
171 | ||
fe83c251 | 172 | } |