From 7a2ee4179f7198ae42c133356ed206ab3b4e1faa Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 17 Oct 2019 11:43:05 +1300 Subject: [PATCH] Add test for participant receipts, super minor consistency fix. 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 | 1 + CRM/Event/Form/Registration/Confirm.php | 1 - .../Event/Form/Registration/ConfirmTest.php | 19 ++++- tests/phpunit/CiviTest/CiviUnitTestCase.php | 16 ++-- .../event_online_receipt_text.tpl | 73 +++++++++++++++++++ 5 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 tests/templates/message_templates/event_online_receipt_text.tpl diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 87c08b579a..313aca0569 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -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))), diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 8a326a4cf2..bf4542866b 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -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); } } diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index 12a03668cc..9bf67fb1fc 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -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')), diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 6efa3a4e86..95a616edd8 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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 index 0000000000..5b9646a6b9 --- /dev/null +++ b/tests/templates/message_templates/event_online_receipt_text.tpl @@ -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} -- 2.25.1