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 | |
9 | /** |
10 | * Test message upgrade process. |
11 | */ |
12 | public function testMessageTemplateUpgrade() { |
13 | $workFlowID = civicrm_api3('OptionValue', 'getvalue', ['return' => 'id', 'name' => 'membership_online_receipt', 'options' => ['limit' => 1, 'sort' => 'id DESC']]); |
14 | |
15 | $templates = $this->callAPISuccess('MessageTemplate', 'get', ['workflow_id' => $workFlowID])['values']; |
16 | foreach ($templates as $template) { |
17 | $originalText = $template['msg_text']; |
18 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a cool member you are', 'id' => $template['id']]); |
19 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); |
20 | $this->assertEquals('great what a cool member you are', $msg_text); |
21 | } |
22 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); |
23 | $messageTemplateObject->updateTemplates(); |
24 | |
25 | foreach ($templates as $template) { |
26 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); |
12d387d2 |
27 | $this->assertContains('{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}{$greeting},{/if}', $msg_text); |
fe83c251 |
28 | if ($msg_text !== $originalText) { |
29 | // Reset value for future tests. |
30 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => $originalText, 'id' => $template['id']]); |
31 | } |
32 | } |
33 | } |
34 | |
35 | /** |
36 | * Test message upgrade process only edits the default if the template is customised. |
37 | */ |
38 | public function testMessageTemplateUpgradeAlreadyCustomised() { |
39 | $workFlowID = civicrm_api3('OptionValue', 'getvalue', ['return' => 'id', 'name' => 'membership_online_receipt', 'options' => ['limit' => 1, 'sort' => 'id DESC']]); |
40 | |
41 | $templates = $this->callAPISuccess('MessageTemplate', 'get', ['workflow_id' => $workFlowID])['values']; |
42 | foreach ($templates as $template) { |
43 | if ($template['is_reserved']) { |
44 | $originalText = $template['msg_text']; |
45 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a cool member you are', 'id' => $template['id']]); |
46 | } |
47 | else { |
48 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => 'great what a silly sausage you are', 'id' => $template['id']]); |
49 | } |
50 | } |
51 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); |
52 | $messageTemplateObject->updateTemplates(); |
53 | |
54 | foreach ($templates as $template) { |
55 | $msg_text = $this->callAPISuccessGetValue('MessageTemplate', ['id' => $template['id'], 'return' => 'msg_text']); |
56 | if ($template['is_reserved']) { |
12d387d2 |
57 | $this->assertContains('{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}{$greeting},{/if}', $msg_text); |
fe83c251 |
58 | } |
59 | else { |
60 | $this->assertEquals('great what a silly sausage you are', $msg_text); |
61 | } |
62 | |
63 | if ($msg_text !== $originalText) { |
64 | // Reset value for future tests. |
65 | $this->callAPISuccess('MessageTemplate', 'create', ['msg_text' => $originalText, 'id' => $template['id']]); |
66 | } |
67 | } |
68 | } |
69 | |
70 | /** |
71 | * Test function for messages on upgrade. |
72 | */ |
73 | public function testMessageTemplateGetUpgradeMessages() { |
74 | $messageTemplateObject = new CRM_Upgrade_Incremental_MessageTemplates('5.4.alpha1'); |
75 | $messages = $messageTemplateObject->getUpgradeMessages(); |
12d387d2 |
76 | $this->assertEquals([ |
77 | 'Memberships - Receipt (on-line)' => 'Use email greeting at top where available', |
78 | 'Contributions - Receipt (on-line)' => 'Use email greeting at top where available', |
79 | 'Events - Registration Confirmation and Receipt (on-line)' => 'Use email greeting at top where available', |
80 | ], $messages); |
fe83c251 |
81 | } |
82 | |
7015248a |
83 | /** |
84 | * Test converting a datepicker field. |
85 | */ |
86 | public function testSmartGroupDatePickerConversion() { |
87 | $this->callAPISuccess('SavedSearch', 'create', [ |
88 | 'form_values' => [ |
89 | ['grant_application_received_date_high', '=', '01/20/2019'], |
90 | ['grant_due_date_low', '=', '01/22/2019'], |
91 | ] |
92 | ]); |
93 | $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups('5.11.alpha1'); |
94 | $smartGroupConversionObject->updateGroups(); |
95 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); |
96 | $this->assertEquals('grant_application_received_date_high', $savedSearch['form_values'][0][0]); |
97 | $this->assertEquals('2019-01-20 00:00:00', $savedSearch['form_values'][0][2]); |
98 | $this->assertEquals('grant_due_date_low', $savedSearch['form_values'][1][0]); |
99 | $this->assertEquals('2019-01-22 00:00:00', $savedSearch['form_values'][1][2]); |
100 | } |
101 | |
fe83c251 |
102 | } |