Add unit test cover for location in event emails
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 22 May 2023 02:34:27 +0000 (14:34 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 16 Jun 2023 01:42:02 +0000 (13:42 +1200)
CRM/Event/Tokens.php
tests/phpunit/CRM/Event/Form/ParticipantTest.php
tests/phpunit/CRM/Utils/TokenConsistencyTest.php
tests/templates/message_templates/event_offline_receipt_html.tpl [new file with mode: 0644]

index 2968b8c4d48c88f5e897a4cfe3360fefcd3fb261..6652723bcc260ccef4d79eb28ab2df81dd218b70 100644 (file)
@@ -209,8 +209,8 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens {
         'city' => $event['loc_block_id.address_id.city'],
         'state_province' => $event['loc_block_id.address_id.state_province_id:label'],
         'postal_code' => $event['loc_block_id.address_id.postal_code'],
-
       ]);
+      $tokens['location']['text/html'] = nl2br(trim($tokens['location']['text/plain']));
       $tokens['info_url']['text/html'] = \CRM_Utils_System::url('civicrm/event/info', 'reset=1&id=' . $eventID, TRUE, NULL, FALSE, TRUE);
       $tokens['registration_url']['text/html'] = \CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $eventID, TRUE, NULL, FALSE, TRUE);
       $tokens['start_date']['text/html'] = !empty($event['start_date']) ? new DateTime($event['start_date']) : '';
index 169294cc4077d162d8043842036839cd56aeb86c..aae49b9649dcd4418584b83f8f45d5879af75a1a 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+use Civi\Api4\Address;
 use Civi\Api4\LocBlock;
 use Civi\Api4\Participant;
 use Civi\Api4\Phone;
@@ -259,6 +260,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
   public function testParticipantOfflineReceipt(string $thousandSeparator): void {
     $this->setCurrencySeparators($thousandSeparator);
     $this->swapMessageTemplateForTestTemplate('event_offline_receipt', 'text');
+    $this->swapMessageTemplateForTestTemplate('event_offline_receipt', 'html');
     $mut = new CiviMailUtils($this, TRUE);
     // Create an email associated with the logged in contact
     $loggedInContactID = $this->createLoggedInUser();
@@ -332,6 +334,12 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
       'contribution.balance_amount|raw string is zero:::Yes',
       'contribution.balance_amount|boolean:::No',
       'contribution.paid_amount|boolean:::Yes',
+      '<p>Test event type - 1</p>event.location:8 Baker Street<br />
+London,',
+      '$location.address.1.display:<div class="location vcard"><span class="adr"><span class="street-address">8 Baker Street</span><br />
+<span class="extended-address">Upstairs</span><br />
+<span class="locality">London</span>,<br />
+</span></div>',
     ]);
 
     $this->callAPISuccess('Email', 'delete', ['id' => $email['id']]);
@@ -352,7 +360,8 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
 
     if (!empty($eventParams['is_monetary'])) {
       $phone = Phone::create()->setValues(['phone' => 1235, 'phone_type_id:name' => 'Mobile', 'phone_ext' => 456])->execute()->first();
-      $locationBlockID = LocBlock::create()->setValues(['phone_id' => $phone['id']])->execute()->first()['id'];
+      $address = Address::create()->setValues(['street_address' => '8 Baker Street', 'supplemental_address_1' => 'Upstairs', 'city' => 'London'])->execute()->first();
+      $locationBlockID = LocBlock::create()->setValues(['phone_id' => $phone['id'], 'address_id' => $address['id']])->execute()->first()['id'];
       $event = $this->legacyEventCreatePaid(array_merge([
         'name' => 'big',
         'amount' => 1550.55,
index 7f8ba1af5b09a1045bd4c28cce7b8613803d8fd6..fbf138e1bd950a9ea8b96f0384f76dda9a02d794 100644 (file)
@@ -668,9 +668,8 @@ event.summary :If you have any CiviCRM related issues or want to track where Civ
 event.loc_block_id.email_id.email :event@example.com
 event.loc_block_id.phone_id.phone :456 789
 event.description :event description
-event.location :15 Walton St
+event.location :15 Walton St<br />
 Emerald City, Maine 90210
-
 event.info_url :' . CRM_Utils_System::url('civicrm/event/info', NULL, TRUE) . '&reset=1&id=1
 event.registration_url :' . CRM_Utils_System::url('civicrm/event/register', NULL, TRUE) . '&reset=1&id=1
 event.pay_later_receipt :Please transfer funds to our bank account.
@@ -889,7 +888,7 @@ United States', $tokenProcessor->getRow(0)->render('message'));
     $mut->checkMailLog($toCheck);
     $tokens = array_keys($this->getEventTokens());
     $html = $this->getTokenString($tokens);
-    $tokenProcessor->addMessage('html', $html, 'text/plain');
+    $tokenProcessor->addMessage('html', $html, 'text/html');
     $tokenProcessor->addRow(['eventId' => $this->ids['Event'][0]]);
     $tokenProcessor->evaluate();
     $this->assertEquals($expectedEventString, $tokenProcessor->getRow(0)->render('html'));
@@ -919,7 +918,7 @@ United States', $tokenProcessor->getRow(0)->render('message'));
     ]);
     $html = $this->getTokenString(array_keys($this->getEventTokens()));
 
-    $tokenProcessor->addMessage('html', $html, 'text/plain');
+    $tokenProcessor->addMessage('html', $html, 'text/html');
     $tokenProcessor->addRow(['eventId' => $this->ids['Event'][0]]);
     $tokenProcessor->evaluate();
     $this->assertEquals($expected, $tokenProcessor->getRow(0)->render('html'));
diff --git a/tests/templates/message_templates/event_offline_receipt_html.tpl b/tests/templates/message_templates/event_offline_receipt_html.tpl
new file mode 100644 (file)
index 0000000..703eed9
--- /dev/null
@@ -0,0 +1,3 @@
+event.location:{event.location}
+$location.address.1.display:{$location.address.1.display|nl2br}
+