Skip to content

Commit

Permalink
Use new money formatting util for smarty formatting
Browse files Browse the repository at this point in the history
This switches us from the old function to the new function
  • Loading branch information
eileenmcnaughton committed Dec 27, 2021
1 parent ddee419 commit 57818f9
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 42 deletions.
6 changes: 3 additions & 3 deletions CRM/Core/Smarty/plugins/modifier.crmMoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*
* @param float $amount
* The monetary amount up for display.
* @param string $currency
* @param string|null $currency
* The (optional) currency.
*
* @return string
* formatted monetary amount
*
* @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);
}
9 changes: 4 additions & 5 deletions tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ public function testDashboardContentContributionsWithInvoicingEnabled(): void {
/**
* 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,
Expand All @@ -151,7 +150,7 @@ public function testDashboardContentContributions() {
$expectedStrings = [
'Your Contribution(s)',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
'<td>$ 100.00 </td><td>Donation</td>',
'<td>$100.00 </td><td>Donation</td>',
'<td>Completed</td>',
];
$this->assertPageContains($expectedStrings);
Expand Down Expand Up @@ -183,8 +182,8 @@ public function testDashboardPartialPayments() {
$expectedStrings = [
'Your Contribution(s)',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
'<td>$ 25.00 </td><td>Donation</td>',
'<td>$ 14.00</td><td>Partially paid</td>',
'<td>$25.00 </td><td>Donation</td>',
'<td>$14.00</td><td>Partially paid</td>',
'Pay Now',
];
$this->assertPageContains($expectedStrings);
Expand Down
22 changes: 11 additions & 11 deletions tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public function testAddPaymentUsingCreditCardForPartiallyPaidContribution() {
'From: [email protected]',
'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',
Expand Down Expand Up @@ -199,8 +199,8 @@ public function testMultiplePaymentForPartiallyPaidContribution() {
'return' => ['target_contact_id', 'assignee_contact_id', 'subject'],
])['values'];
$this->assertCount(3, $activities);
$this->assertEquals('$ 50.00 - Offline Payment for Contribution', $activities[1]['subject']);
$this->assertEquals('$ 20.00 - Offline Payment for Contribution', $activities[2]['subject']);
$this->assertEquals('$50.00 - Offline Payment for Contribution', $activities[1]['subject']);
$this->assertEquals('$20.00 - Offline Payment for Contribution', $activities[2]['subject']);
$this->assertEquals(CRM_Core_Session::singleton()->getLoggedInContactID(), $activities[0]['source_contact_id']);
$this->assertEquals([$this->_individualId], $activities[0]['target_contact_id']);
$this->assertEquals([], $activities[0]['assignee_contact_id']);
Expand Down Expand Up @@ -236,9 +236,9 @@ public function testMultiplePaymentForPartiallyPaidContributionWithOneCreditCard
$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',
],
Expand Down Expand Up @@ -266,9 +266,9 @@ public function testAddPaymentUsingCreditCardForPendingPayLaterContribution() {

$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',
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testInvoiceForDueDate() {
$this->assertStringContainsString('PAYMENT ADVICE', $invoiceHTML[$contribution['id']]);

$this->assertStringContainsString('AMOUNT DUE:</font></b></td>
<td style="text-align:right;"><b><font size="1">$ 92.00</font></b></td>', $invoiceHTML[$contribution3['id']]);
<td style="text-align:right;"><b><font size="1">$92.00</font></b></td>', $invoiceHTML[$contribution3['id']]);
}

/**
Expand Down Expand Up @@ -154,12 +154,12 @@ public function testInvoiceForLineItems() {
$lineItems = $this->callAPISuccess('LineItem', 'get', ['contribution_id' => $order['id']]);

foreach ($lineItems['values'] as $lineItem) {
$this->assertStringContainsString("<font size=\"1\">$ {$lineItem['line_total']}</font>", $invoiceHTML);
$this->assertStringContainsString("<font size=\"1\">${$lineItem['line_total']}</font>", $invoiceHTML);
}

$totalAmount = $this->formatMoneyInput($order['values'][$order['id']]['total_amount']);
$this->assertStringContainsString("TOTAL USD</font></b></td>
<td style=\"text-align:right;\"><font size=\"1\">$ $totalAmount</font>", $invoiceHTML);
<td style=\"text-align:right;\"><font size=\"1\">${$totalAmount}</font>", $invoiceHTML);

}

Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function testIPNPaymentMembershipRecurSuccessNoLeakage(): void {
$mut->checkAllMailLog([
'Membership Type: General',
'Mr. Anthony Anderson II" <[email protected]>',
'Amount: $ 200.00',
'Amount: $200.00',
'Membership Start Date:',
'Supporter Profile',
'First Name: Anthony',
Expand All @@ -323,7 +323,7 @@ public function testIPNPaymentMembershipRecurSuccessNoLeakage(): void {
'Membership Type: General',
'Mrs. Antonia Anderson II',
'[email protected]',
'Amount: $ 200.00',
'Amount: $200.00',
'Membership Start Date:',
'Transaction #: hers',
'Supporter Profile',
Expand Down Expand Up @@ -363,7 +363,7 @@ public function testIPNPaymentMembershipRecurSuccessNoLeakageOnlineThenOffline()
$mut->checkAllMailLog([
'Membership Type: General',
'Mr. Anthony Anderson II" <[email protected]>',
'Amount: $ 200.00',
'Amount: $200.00',
'Membership Start Date:',
'Supporter Profile',
'First Name: Anthony',
Expand All @@ -387,7 +387,7 @@ public function testIPNPaymentMembershipRecurSuccessNoLeakageOnlineThenOffline()
'Membership Type: General',
'Mrs. Antonia Anderson II',
'[email protected]',
'Amount: $ 200.00',
'Amount: $200.00',
'Membership Start Date:',
'Transaction #: hers',
'This membership will be automatically renewed every',
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public function testSubmitMembershipBlockIsSeparatePaymentPayLaterWithEmail(): v
$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();
Expand Down Expand Up @@ -555,8 +555,8 @@ public function testSubmitMembershipBlockIsSeparatePaymentWithEmail(): void {
// line and no total line.
$mut->checkAllMailLog(
[
'Amount: $ 2.00',
'Amount: $ 88.00',
'Amount: $2.00',
'Amount: $88.00',
'Membership Fee',
],
[
Expand Down Expand Up @@ -591,7 +591,7 @@ public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWit
$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();
Expand Down Expand Up @@ -662,7 +662,7 @@ public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow():
}
// 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();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,7 @@ public function testSendMail(): void {
'receipt_from_email' => '[email protected]',
]);
$mut->checkMailLog([
'$ 100.00',
'$100.00',
'Contribution Information',
], [
'Event',
Expand Down
20 changes: 10 additions & 10 deletions tests/phpunit/api/v3/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function testPaymentSendContributionReceipt(): void {
$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',
]);
Expand Down Expand Up @@ -293,10 +293,10 @@ public function testPaymentEmailReceipt(): void {
$mut->checkMailLog([
'From: "FIXME" <[email protected]>',
'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',
Expand Down Expand Up @@ -331,9 +331,9 @@ public function testPaymentEmailReceiptFullyPaid(): void {
'From: "FIXME" <[email protected]>',
'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.',
]);
}
Expand Down Expand Up @@ -382,12 +382,12 @@ public function testRefundEmailReceipt(string $thousandSeparator): void {
$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',
]);
}

Expand Down

0 comments on commit 57818f9

Please sign in to comment.