From d6d93aa4646ba00fc7a40b9496325c0ee2199a56 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 23 Dec 2021 18:26:19 +1300 Subject: [PATCH] Use new money formatting util for smarty formatting This switches us from the old function to the new function --- CRM/Core/Smarty/plugins/modifier.crmMoney.php | 6 +++--- .../Contact/Page/View/UserDashBoardTest.php | 9 ++++----- .../Contribute/Form/AdditionalPaymentTest.php | 20 +++++++++---------- .../CRM/Contribute/Form/ContributionTest.php | 10 +++++----- .../CRM/Contribute/Form/Task/InvoiceTest.php | 16 +++++++-------- .../Form/Task/PDFLetterCommonTest.php | 10 +++++----- .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 8 ++++---- .../CRM/Core/Smarty/plugins/CrmMoneyTest.php | 4 ++-- .../CRM/Event/Form/ParticipantTest.php | 8 +++++--- .../CRM/Member/Form/MembershipRenewalTest.php | 2 +- .../CRM/Member/Form/MembershipTest.php | 9 ++++----- tests/phpunit/api/v3/ContributionPageTest.php | 10 +++++----- tests/phpunit/api/v3/ContributionTest.php | 2 +- tests/phpunit/api/v3/PaymentTest.php | 20 +++++++++---------- 14 files changed, 66 insertions(+), 68 deletions(-) diff --git a/CRM/Core/Smarty/plugins/modifier.crmMoney.php b/CRM/Core/Smarty/plugins/modifier.crmMoney.php index c2ec12cadf..cc40306789 100644 --- a/CRM/Core/Smarty/plugins/modifier.crmMoney.php +++ b/CRM/Core/Smarty/plugins/modifier.crmMoney.php @@ -20,7 +20,7 @@ * * @param float $amount * The monetary amount up for display. - * @param string $currency + * @param string|null $currency * The (optional) currency. * * @return string @@ -28,6 +28,6 @@ * * @throws \CRM_Core_Exception */ -function smarty_modifier_crmMoney($amount, $currency = NULL) { - return CRM_Utils_Money::format($amount, $currency); +function smarty_modifier_crmMoney($amount, ?string $currency = NULL): string { + return Civi::format()->money($amount, $currency); } diff --git a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php index 7ba28448b5..f85200729e 100644 --- a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php +++ b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php @@ -137,10 +137,9 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase { /** * Test the content of the dashboard. * - * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ - public function testDashboardContentContributions() { + public function testDashboardContentContributions(): void { $this->contributionCreate(['contact_id' => $this->contactID]); $this->contributions[] = civicrm_api3('Contribution', 'get', [ 'contact_id' => $this->contactID, @@ -151,7 +150,7 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase { $expectedStrings = [ 'Your Contribution(s)', '', - '', + '', '', ]; $this->assertPageContains($expectedStrings); @@ -183,8 +182,8 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase { $expectedStrings = [ 'Your Contribution(s)', '
Total AmountFinancial TypeReceived dateReceipt SentBalanceStatus$ 100.00 Donation$100.00 DonationCompleted
', - '', - '', + '', + '', 'Pay Now', ]; $this->assertPageContains($expectedStrings); diff --git a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php index 72a8b8af45..b93b6daaff 100644 --- a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php @@ -146,9 +146,9 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { 'From: site@something.com', 'Dear Anthony,', 'Payment Details', - 'Total Fee: $ 100.00', - 'This Payment Amount: $ 70.00', - 'Balance Owed: $ 0.00 ', + 'Total Fee: $100.00', + 'This Payment Amount: $70.00', + 'Balance Owed: $0.00 ', 'Billing Name and Address', 'Vancouver, AE 1321312', 'Visa', @@ -180,7 +180,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ - public function testMultiplePaymentForPartiallyPaidContribution() { + public function testMultiplePaymentForPartiallyPaidContribution(): void { $this->createPartiallyPaidOrder(); // pay additional amount @@ -236,9 +236,9 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $mut->checkMailLog([ 'Dear Anthony,', 'Below you will find a receipt for this payment.', - 'Total Fee: $ 100.00', - 'This Payment Amount: $ 50.00', - 'Balance Owed: $ 20.00 ', + 'Total Fee: $100.00', + 'This Payment Amount: $50.00', + 'Balance Owed: $20.00 ', 'Paid By: Check', 'Check Number: check-12345', ], @@ -266,9 +266,9 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $mut->checkMailLog([ 'Below you will find a receipt for this payment.', - 'Total Fee: $ 100.00', - 'This Payment Amount: $ 100.00', - 'Balance Owed: $ 0.00 ', + 'Total Fee: $100.00', + 'This Payment Amount: $100.00', + 'Balance Owed: $0.00 ', 'Paid By: Credit Card', '***********1111', 'Billing Name and Address', diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 19b4a7ecbc..fc1ec2efe8 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -698,7 +698,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { --------------------------------------------------------- Item Qty Each Total ---------------------------------------------------------- -Price Field - Price Field 1 1 $ 100.00 $ 100.00 +Price Field - Price Field 1 1 $100.00 $100.00 ', ]); $mut->stop(); @@ -1154,8 +1154,8 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->assertEquals(11000, $contribution['net_amount']); $strings = [ - 'Total Tax Amount : $ ' . $this->formatMoneyInput(1000.00), - 'Total Amount : $ ' . $this->formatMoneyInput(11000.00), + 'Total Tax Amount : $' . $this->formatMoneyInput(1000.00), + 'Total Amount : $' . $this->formatMoneyInput(11000.00), 'Date Received: April 21st, 2015', 'Paid By: Check', 'Check Number: 12345', @@ -1213,8 +1213,8 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->assertEquals(22000, $contribution['net_amount']); $strings = [ - 'Total Tax Amount : $ ' . $this->formatMoneyInput(2000), - 'Total Amount : $ ' . $this->formatMoneyInput(22000.00), + 'Total Tax Amount : $' . $this->formatMoneyInput(2000), + 'Total Amount : $' . $this->formatMoneyInput(22000.00), 'Date Received: April 21st, 2015', 'Paid By: Check', 'Check Number: 12345', diff --git a/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php b/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php index 50bd78df9a..fda6462b28 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php @@ -77,7 +77,7 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase { $this->assertStringContainsString('PAYMENT ADVICE', $invoiceHTML[$contribution['id']]); $this->assertStringContainsString('AMOUNT DUE: - ', $invoiceHTML[$contribution3['id']]); + ', $invoiceHTML[$contribution3['id']]); } /** @@ -86,7 +86,7 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase { * * @throws \CRM_Core_Exception */ - public function testInvoiceForLineItems() { + public function testInvoiceForLineItems(): void { $this->enableTaxAndInvoicing(); @@ -154,12 +154,12 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase { $lineItems = $this->callAPISuccess('LineItem', 'get', ['contribution_id' => $order['id']]); foreach ($lineItems['values'] as $lineItem) { - $this->assertStringContainsString("$ {$lineItem['line_total']}", $invoiceHTML); + $this->assertStringContainsString("$" . $lineItem['line_total'] . '', $invoiceHTML); } $totalAmount = $this->formatMoneyInput($order['values'][$order['id']]['total_amount']); $this->assertStringContainsString("TOTAL USD - - + @@ -457,7 +457,7 @@ emo --> - + @@ -475,7 +475,7 @@ emo --> - + @@ -483,7 +483,7 @@ emo --> - + @@ -491,7 +491,7 @@ emo --> - + diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index c8aa73955b..a3a63e5839 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -297,7 +297,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { $mut->checkAllMailLog([ 'Membership Type: General', 'Mr. Anthony Anderson II" ', - 'Amount: $ 200.00', + 'Amount: $200.00', 'Membership Start Date:', 'Supporter Profile', 'First Name: Anthony', @@ -323,7 +323,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'Membership Type: General', 'Mrs. Antonia Anderson II', 'antonia_anderson@civicrm.org', - 'Amount: $ 200.00', + 'Amount: $200.00', 'Membership Start Date:', 'Transaction #: hers', 'Supporter Profile', @@ -363,7 +363,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { $mut->checkAllMailLog([ 'Membership Type: General', 'Mr. Anthony Anderson II" ', - 'Amount: $ 200.00', + 'Amount: $200.00', 'Membership Start Date:', 'Supporter Profile', 'First Name: Anthony', @@ -387,7 +387,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'Membership Type: General', 'Mrs. Antonia Anderson II', 'antonia_anderson@civicrm.org', - 'Amount: $ 200.00', + 'Amount: $200.00', 'Membership Start Date:', 'Transaction #: hers', 'This membership will be automatically renewed every', diff --git a/tests/phpunit/CRM/Core/Smarty/plugins/CrmMoneyTest.php b/tests/phpunit/CRM/Core/Smarty/plugins/CrmMoneyTest.php index e7e111a1b6..88e7e9b8fc 100644 --- a/tests/phpunit/CRM/Core/Smarty/plugins/CrmMoneyTest.php +++ b/tests/phpunit/CRM/Core/Smarty/plugins/CrmMoneyTest.php @@ -20,8 +20,8 @@ class CRM_Core_Smarty_plugins_CrmMoneyTest extends CiviUnitTestCase { */ public function moneyCases() { $cases = []; - $cases[] = ['$ 4.00', '{assign var="amount" value="4.00"}{$amount|crmMoney:USD}']; - $cases[] = ['€ 1,234.00', '{assign var="amount" value="1234.00"}{$amount|crmMoney:EUR}']; + $cases[] = ['$4.00', '{assign var="amount" value="4.00"}{$amount|crmMoney:USD}']; + $cases[] = ['€1,234.00', '{assign var="amount" value="1234.00"}{$amount|crmMoney:EUR}']; return $cases; } diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 8229939a45..80e654683a 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -537,13 +537,15 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * Test submitting a partially paid event registration. * * In this case the participant status is selected as 'partially paid' and - * a contribution is created for the full amount with a payment equal to the entered amount. + * a contribution is created for the full amount with a payment equal to the + * entered amount. * * @dataProvider getBooleanDataProvider * * @param bool $isQuickConfig * * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public function testSubmitPartialPayment($isQuickConfig) { $mut = new CiviMailUtils($this, TRUE); @@ -728,8 +730,8 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'Annual CiviCRM meet', 'Registered Email', $isQuickConfig ? $this->formatMoneyInput(1550.55) . ' big - 1' : 'Price Field - big', - $isAmountPaidOnForm ? 'Total Paid: $ 20.00' : ' ', - 'Balance: $ 1,530.55', + $isAmountPaidOnForm ? 'Total Paid: $20.00' : ' ', + 'Balance: $1,530.55', 'Financial Type: Event Fee', 'Paid By: Check', 'Check Number: 879', diff --git a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php index 8b50ff875a..e3f6a390ec 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php @@ -464,7 +464,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); $this->assertEquals(1, $contributionRecur['is_email_receipt']); $this->mut->checkMailLog([ - '$ ' . $this->formatMoneyInput(7800.90), + '$' . $this->formatMoneyInput(7800.90), 'Country-multi : Angola, Anguilla', ]); $this->mut->stop(); diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index 9fac1535b2..fa7c3a144c 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -80,9 +80,6 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { * * Connect to the database, truncate the tables that will be used * and redirect stdin to a temporary file. - * - * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception */ public function setUp(): void { $this->_apiversion = 3; @@ -567,7 +564,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { ]), ], 'online'); $this->mut->checkMailLog([ - CRM_Utils_Money::format('1234.56'), + Civi::format()->money('1234.56'), 'Receipt text', ]); $this->mut->stop(); @@ -1269,11 +1266,13 @@ Expires: ', * * @return \CRM_Member_Form_Membership * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ - protected function getForm($formValues = []) { + protected function getForm($formValues = []): CRM_Member_Form_Membership { if (isset($_REQUEST['cid'])) { unset($_REQUEST['cid']); } + /* @var CRM_Member_Form_Membership $form*/ $form = $this->getFormObject('CRM_Member_Form_Membership', $formValues); $form->preProcess(); return $form; diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index f4425dc0ff..6f1241a817 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -476,7 +476,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->assertCount(2, $contributions); $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => ['IN' => array_keys($contributions)]]); $mut->checkMailLog([ - 'Membership Amount -... $ 2.00', + 'Membership Amount -... $2.00', ]); $mut->stop(); $mut->clearMessages(); @@ -555,8 +555,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { // line and no total line. $mut->checkAllMailLog( [ - 'Amount: $ 2.00', - 'Amount: $ 88.00', + 'Amount: $2.00', + 'Amount: $88.00', 'Membership Fee', ], [ @@ -591,7 +591,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->assertEquals($membership['contact_id'], $contributions[$membershipPayment['contribution_id']]['contact_id']); $mut->checkMailLog([ 'Gruff', - 'General Membership: $ 0.00', + 'General Membership: $0.00', 'Membership Fee', ]); $mut->stop(); @@ -662,7 +662,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { } // The total string is currently absent & it seems worse with - although at some point // it may have been intended - $mut->checkAllMailLog(['$ 2.00', 'Contribution Amount', '$ 88.00'], ['Total:']); + $mut->checkAllMailLog(['$2.00', 'Contribution Amount', '$88.00'], ['Total:']); $mut->stop(); $mut->clearMessages(); } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 0fc48fdca9..1bc6d985de 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -3652,7 +3652,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'receipt_from_email' => 'api@civicrm.org', ]); $mut->checkMailLog([ - '$ 100.00', + '$100.00', 'Contribution Information', ], [ 'Event', diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index 8638b5175d..fa0de30c32 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -219,7 +219,7 @@ class api_v3_PaymentTest extends CiviUnitTestCase { $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]); $this->assertNotEmpty($contribution['receipt_date']); $mut->checkMailLog([ - 'Price Field - Price Field 1 1 $ 100.00 $ 100.00', + 'Price Field - Price Field 1 1 $100.00 $100.00', 'event place', 'streety street', ]); @@ -293,10 +293,10 @@ class api_v3_PaymentTest extends CiviUnitTestCase { $mut->checkMailLog([ 'From: "FIXME" ', 'Dear Anthony,', - 'Total Fee: $ 300.00', - 'This Payment Amount: $ 50.00', + 'Total Fee: $300.00', + 'This Payment Amount: $50.00', //150 was paid in the 1st payment. - 'Balance Owed: $ 100.00', + 'Balance Owed: $100.00', 'Event Information and Location', 'Paid By: Check', 'Check Number: 345', @@ -331,9 +331,9 @@ class api_v3_PaymentTest extends CiviUnitTestCase { 'From: "FIXME" ', 'Dear Anthony,', 'Below you will find a receipt for this payment.', - 'Total Fee: $ 300.00', - 'This Payment Amount: $ 150.00', - 'Balance Owed: $ 0.00', + 'Total Fee: $300.00', + 'This Payment Amount: $150.00', + 'Balance Owed: $0.00', 'Thank you for completing this payment.', ]); } @@ -382,12 +382,12 @@ class api_v3_PaymentTest extends CiviUnitTestCase { $mut->checkMailLog([ 'Dear Anthony,', 'A refund has been issued based on changes in your registration selections.', - 'Total Fee: $ 300' . $decimalSeparator . '00', - 'Refund Amount: $ -30' . $decimalSeparator . '00', + 'Total Fee: $300' . $decimalSeparator . '00', + 'Refund Amount: -$30' . $decimalSeparator . '00', 'Event Information and Location', 'Paid By: Check', 'Transaction Date: November 13th, 2018 12:01 PM', - 'Total Paid: $ 170' . $decimalSeparator . '00', + 'Total Paid: $170' . $decimalSeparator . '00', ]); } -- 2.25.1
Total AmountFinancial TypeReceived dateReceipt SentBalanceStatus$ 25.00 Donation$ 14.00Partially paid$25.00 Donation$14.00Partially paid$ 92.00$92.00$ $totalAmount", $invoiceHTML); + $" . $totalAmount . '', $invoiceHTML); } @@ -167,10 +167,8 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase { * Test invoices if payment is made with different currency. * * https://lab.civicrm.org/dev/core/issues/2269 - * - * @throws \CRM_Core_Exception */ - public function testThatInvoiceShowTheActuallContributionCurrencyInsteadOfTheDefaultOne() { + public function testThatInvoiceShowsTheActualContributionCurrencyInsteadOfTheDefaultOne(): void { $this->setDefaultCurrency('USD'); $this->_individualId = $this->individualCreate(); @@ -187,8 +185,8 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase { $this->assertStringNotContainsString('$', $invoiceHTML); $this->assertStringNotContainsString('Amount USD', $invoiceHTML); $this->assertStringNotContainsString('TOTAL USD', $invoiceHTML); - $this->assertStringContainsString('£ 0.00', $invoiceHTML); - $this->assertStringContainsString('£ 100.00', $invoiceHTML); + $this->assertStringContainsString('£0.00', $invoiceHTML); + $this->assertStringContainsString('£100.00', $invoiceHTML); $this->assertStringContainsString('Amount GBP', $invoiceHTML); $this->assertStringContainsString('TOTAL GBP', $invoiceHTML); diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index b9da6917b9..9dc66032a2 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -449,7 +449,7 @@ emo -->
25 December 2016$ 100.00$100.00 Donation
Total$ 100.00$100.00
25 December 2016$ 10.00$10.00 Donation
25 December 2016$ 1.00$1.00 Donation
Total$ 11.00$11.00