Add test for participant receipts, super minor consistency fix.
authoreileen <emcnaughton@wikimedia.org>
Wed, 16 Oct 2019 22:43:05 +0000 (11:43 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 17 Oct 2019 19:47:54 +0000 (08:47 +1300)
This is mostly adding testing for participant receipts. The one change to core code is to move the assignment
of contactID to the template from a specific path into the shared code. This parameter is not required by
the templates but it is somewhat common for sites to want to have it assigned to templates for
customisation which is presumably why it's there. Since it is there in one path we should either remove or
have it in all & for a field like contactID all makes sense. Tests lock in that var

CRM/Event/BAO/Event.php
CRM/Event/Form/Registration/Confirm.php
tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/templates/message_templates/event_online_receipt_text.tpl [new file with mode: 0644]

index 87c08b579a48684c61d6a9a7b5b0394f210aeb84..313aca05690335191516e690ebdd21ee85decd93 100644 (file)
@@ -1172,6 +1172,7 @@ WHERE civicrm_event.is_active = 1
           'customPost' => $profilePost[0],
           'customPost_grouptitle' => $customPostTitles,
           'participantID' => $participantId,
+          'contactID' => $contactID,
           'conference_sessions' => $sessions,
           'credit_card_number' => CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $participantParams)),
           'credit_card_exp_date' => CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $participantParams))),
index 8a326a4cf2af3bc7353f716a4f8f96f93ce4d6b4..bf4542866be67027463ddb9b6e3e57d2836e27fa 100644 (file)
@@ -915,7 +915,6 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
         $this->_values['params']['isRequireApproval'] = $this->_requireApproval;
 
         //send mail to primary as well as additional participants.
-        $this->assign('contactID', $contactId);
         CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest);
       }
     }
index 12a03668ccfff38e0ab419628b3a43f9c371a105..9bf67fb1fca7b075db8b874b033f4a2bb0aabf05 100644 (file)
@@ -215,11 +215,13 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
    * Test for Tax amount for multiple participant.
    *
    * @throws \CRM_Core_Exception
+   * @throws \Exception
    */
   public function testTaxMultipleParticipant() {
     $mut = new CiviMailUtils($this);
     $params = ['is_monetary' => 1, 'financial_type_id' => 1];
     $event = $this->eventCreate($params);
+    $this->swapMessageTemplateForTestTemplate('event_online_receipt', 'text');
     CRM_Event_Form_Registration_Confirm::testSubmit([
       'id' => $event['id'],
       'contributeMode' => 'direct',
@@ -236,7 +238,6 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
           'additional_participants' => 2,
           'payment_processor_id' => 0,
           'bypass_payment' => '',
-          'MAX_FILE_SIZE' => '33554432',
           'is_primary' => 1,
           'is_pay_later' => 1,
           'campaign_id' => NULL,
@@ -297,13 +298,27 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
     $this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
     $mailSent = $mut->getAllMessages();
     $this->assertCount(3, $mailSent, 'Three mails should have been sent to the 3 participants.');
+    $this->assertContains('contactID:::' . $contribution['contact_id'], $mailSent[0]);
+    $this->assertContains('contactID:::' . ($contribution['contact_id'] + 1), $mailSent[1]);
+
+    $this->callAPISuccess('Payment', 'create', ['total_amount' => 100, 'payment_type_id' => 'Cash', 'contribution_id' => $contribution['id']]);
+    $mailSent = $mut->getAllMessages();
+    $this->assertCount(6, $mailSent);
+
+    $this->assertContains('participant_status:::Registered', $mailSent[3]);
+    $this->assertContains('Dear Participant2', $mailSent[3]);
+
+    $this->assertContains('contactID:::' . ($contribution['contact_id'] + 1), $mailSent[3]);
+    $this->assertContains('contactID:::' . ($contribution['contact_id'] + 2), $mailSent[4]);
+    $this->assertContains('contactID:::' . $contribution['contact_id'], $mailSent[5]);
+    $this->revertTemplateToReservedTemplate('event_online_receipt', 'text');
   }
 
   /**
    * Test online registration for event with no price options selected as per CRM-19964.
    */
   public function testOnlineRegNoPrice() {
-    $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]);
+    $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]);
     $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE]);
     $params = [
       'start_date' => date('YmdHis', strtotime('+ 1 week')),
index 6efa3a4e86aec744297d6329cff3b6d52eefa7fc..95a616edd8f2656bb99faee6da74d647cbcbb0b1 100644 (file)
@@ -2731,17 +2731,18 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * Replace the template with a test-oriented template designed to show all the variables.
    *
    * @param string $templateName
+   * @param string $type
    */
-  protected function swapMessageTemplateForTestTemplate($templateName = 'contribution_online_receipt') {
-    $testTemplate = file_get_contents(__DIR__ . '/../../templates/message_templates/' . $templateName . '_html.tpl');
+  protected function swapMessageTemplateForTestTemplate($templateName = 'contribution_online_receipt', $type = 'html') {
+    $testTemplate = file_get_contents(__DIR__ . '/../../templates/message_templates/' . $templateName . '_' . $type . '.tpl');
     CRM_Core_DAO::executeQuery(
       "UPDATE civicrm_option_group og
       LEFT JOIN civicrm_option_value ov ON ov.option_group_id = og.id
       LEFT JOIN civicrm_msg_template m ON m.workflow_id = ov.id
-      SET m.msg_html = '{$testTemplate}'
-      WHERE og.name = 'msg_tpl_workflow_contribution'
+      SET m.msg_{$type} = %1
+      WHERE og.name LIKE 'msg_tpl_workflow_%'
       AND ov.name = '{$templateName}'
-      AND m.is_default = 1"
+      AND m.is_default = 1", [1 => [$testTemplate, 'String']]
     );
   }
 
@@ -2749,14 +2750,15 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * Reinstate the default template.
    *
    * @param string $templateName
+   * @param string $type
    */
-  protected function revertTemplateToReservedTemplate($templateName = 'contribution_online_receipt') {
+  protected function revertTemplateToReservedTemplate($templateName = 'contribution_online_receipt', $type = 'html') {
     CRM_Core_DAO::executeQuery(
       "UPDATE civicrm_option_group og
       LEFT JOIN civicrm_option_value ov ON ov.option_group_id = og.id
       LEFT JOIN civicrm_msg_template m ON m.workflow_id = ov.id
       LEFT JOIN civicrm_msg_template m2 ON m2.workflow_id = ov.id AND m2.is_reserved = 1
-      SET m.msg_html = m2.msg_html
+      SET m.msg_{$type} = m2.msg_{$type}
       WHERE og.name = 'msg_tpl_workflow_contribution'
       AND ov.name = '{$templateName}'
       AND m.is_default = 1"
diff --git a/tests/templates/message_templates/event_online_receipt_text.tpl b/tests/templates/message_templates/event_online_receipt_text.tpl
new file mode 100644 (file)
index 0000000..5b9646a
--- /dev/null
@@ -0,0 +1,73 @@
+{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}{$greeting},{/if}
+
+contactID:::{$contactID}
+event.confirm_email_text:::{$event.confirm_email_text}
+isOnWaitlist:::{$isOnWaitlist}
+isRequireApproval:::{$isRequireApproval}
+participant_status:::{$participant_status}
+pricesetFieldsCount:::{$pricesetFieldsCount}
+isPrimary:::{$isPrimary}
+conference_sessions:::{$conference_sessions}
+is_pay_later:::{$is_pay_later}
+isAmountzero:::{$isAmountzero}
+isAdditionalParticipant:::{$isAdditionalParticipant}
+pay_later_receipt:::{$pay_later_receipt}
+event.event_title:::{$event.event_title}
+event.event_start_date:::{$event.event_start_date|date_format:"%A"}
+event.event_end_date:::{$event.event_end_date|date_format:"%Y%m%d"}
+event.is_monetary:::{$event.is_monetary}
+event.fee_label:::{$event.fee_label}
+conference_sessions:::{$conference_sessions}
+event.participant_role::{$event.participant_role}
+defaultRole:::{$defaultRole}
+isShowLocation:::{$isShowLocation}
+location.address.1.display:::{$location.address.1.display}
+location.phone.1.phone:::{$location.phone.1.phone}
+location.phone.1.phone_type_display:::{$location.phone.1.phone_type_display}
+location.phone.1.phone_ext:::{$location.phone.1.phone_ext}
+location.email.1.email:::{$location.email.1.email}
+event.is_public:::{$event.is_public}
+payer.name:::{$payer.name}
+lineitem:::{if $lineItem}
+ {foreach from=$lineItem item=value key=priceset}
+  {foreach from=$value item=line}
+     line.html_type:::{$line.html_type}
+     line.label:::{$line.label}
+     line.field_title:::{$line.field_title}
+     line.description:::{$line.description}
+     line.qty:::{$line.qty}
+     line.unit_price:::{$line.unit_price}
+     line.tax_rate:::{$line.tax_rate}
+     line.tax_amount:::{$line.tax_amount}
+     line.line_total:::{$line.line_total}
+  {/foreach}
+ {/foreach}
+{/if}
+
+part:::{foreach from=$part item=value key=key}
+{$key}{$value}
+{/foreach}
+
+dataArray:::{$dataArray}
+
+totalTaxAmount:::{$totalTaxAmount}
+amounts:::{$amounts}
+register_date:::{$register_date|crmDate}
+receive_date:::{$receive_date|crmDate}
+financialTypeName:::{$financialTypeName}
+trxn_id:::{$trxn_id}
+paidBy:::{$paidBy}
+checkNumber:::{$checkNumber}
+billingName:::{$billingName}
+credit_card_type:::{$credit_card_type}
+credit_card_number:::{$credit_card_number}
+address:::{$address}
+credit_card_exp_date:::{$credit_card_exp_date}
+{foreach from=$customPre item=customValue key=customName}
+  customPre: customName:::$customName
+  customPre: customValue:::$customValue
+{/foreach}
+{foreach from=$customPost item=customValue key=customName}
+  customPost: customName:::$customName
+  customPost: customValue:::$customValue
+{/foreach}