Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap {$displayName} smarty for {contact.display_name} token #20867

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Civi/Test/ContactTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public function organizationCreate($params = [], $seq = 0): int {
*
* @return int
* id of Individual created
*
* @throws \CiviCRM_API3_Exception
*/
public function individualCreate($params = [], $seq = 0, $random = FALSE): int {
$params = array_merge($this->sampleContact('Individual', $seq, $random), $params);
Expand Down
4 changes: 2 additions & 2 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

60 changes: 50 additions & 10 deletions tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase {
*/
public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
$this->revertTemplateToReservedTemplate('contribution_invoice_receipt');
CRM_Utils_Hook::singleton()->reset();
}

Expand Down Expand Up @@ -173,22 +174,14 @@ public function testThatInvoiceShowTheActuallContributionCurrencyInsteadOfTheDef

$this->_individualId = $this->individualCreate();

$contributionParams = [
'contact_id' => $this->_individualId,
'total_amount' => 100,
'currency' => 'GBP',
'financial_type_id' => 'Donation',
'contribution_status_id' => 1,
];

$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
$contributionID = $this->setupContribution();

$params = [
'output' => 'pdf_invoice',
'forPage' => 1,
];

$invoiceHTML = CRM_Contribute_Form_Task_Invoice::printPDF([$contribution['id']], $params, [$this->_individualId]);
$invoiceHTML = CRM_Contribute_Form_Task_Invoice::printPDF([$contributionID], $params, [$this->_individualId]);

$this->assertStringNotContainsString('$', $invoiceHTML);
$this->assertStringNotContainsString('Amount USD', $invoiceHTML);
Expand All @@ -200,4 +193,51 @@ public function testThatInvoiceShowTheActuallContributionCurrencyInsteadOfTheDef

}

/**
* Test invoice contact fields.
*/
public function testInvoiceContactFields(): void {
$this->swapMessageTemplateForTestTemplate('contribution_invoice_receipt');
$contactID = $this->individualCreate([
'postal_code' => 2345,
'street_address' => 'on my street',
'supplemental_address_1' => 'and more detail',
'supplemental_address_2' => 'and more',
'stateProvinceAbbreviation' => 'ME',
'city' => 'Baltimore',
'country' => 'US',
'external_identifier' => 2345,
]);
$params = [
'output' => 'pdf_invoice',
'forPage' => 1,
];
$invoiceHTML = CRM_Contribute_Form_Task_Invoice::printPDF([$this->setupContribution(['contact_id' => $contactID])], $params, [$contactID]);
$expected = [
'externalIdentifier (token):::2345',
'displayName (token):::Mr. Anthony Anderson II',
];
foreach ($expected as $string) {
$this->assertStringContainsString($string, $invoiceHTML);
}
}

/**
* Set up a contribution.
*
* @param array $params
*
* @return int
*/
protected function setupContribution(array $params = []): int {
$contributionParams = array_merge([
'contact_id' => $this->_individualId,
'total_amount' => 100,
'currency' => 'GBP',
'financial_type_id' => 'Donation',
'contribution_status_id' => 1,
], $params);
return (int) $this->callAPISuccess('Contribution', 'create', $contributionParams)['id'];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
displayName (token):::{contact.display_name}
organizationName (token):::{contact.organization_name}
externalIdentifier (token):::{contact.external_identifier}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</tr>
<tr>
{if $organization_name}
<td><font size="1" align="center">{$display_name} ({$organization_name})</font></td>
<td><font size="1" align="center">{contact.display_name} ({$organization_name})</font></td>
{else}
<td><font size="1" align="center">{$display_name}</font></td>
<td><font size="1" align="center">{contact.display_name}</font></td>
{/if}
<td><font size="1" align="right">{$invoice_date}</font></td>
<td style="white-space: nowrap">
Expand Down Expand Up @@ -188,7 +188,7 @@
<table cellpadding="5" cellspacing="0" width="100%" border="0">
<tr>
<td width="100%"><font size="1" align="right" style="font-weight:bold;">{ts}Customer:{/ts}</font></td>
<td style="white-space: nowrap"><font size="1" align="right">{$display_name}</font></td>
<td style="white-space: nowrap"><font size="1" align="right">{contact.display_name}</font></td>
</tr>
<tr>
<td><font size="1" align="right" style="font-weight:bold;">{ts}Invoice Number:{/ts}</font></td>
Expand Down Expand Up @@ -234,9 +234,9 @@
</tr>
<tr>
{if $organization_name}
<td style="padding-left:17px;"><font size="1" align="center">{$display_name} ({$organization_name})</font></td>
<td style="padding-left:17px;"><font size="1" align="center">{contact.display_name} ({$organization_name})</font></td>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do organization name because in my testing it was only showing up for organizations not individuals which meant it was repeated - but I'll test that further

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tangential, but since you mention it - I use invoicing a lot, and never found why the organization name was repeated. if an invoice is "care of Some Person", then it would be in the address fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm - good point

{else}
<td style="padding-left:17px;"><font size="1" align="center">{$display_name}</font></td>
<td style="padding-left:17px;"><font size="1" align="center">{contact.display_name}</font></td>
{/if}
<td style="padding-left:30px;"><font size="1" align="right">{$invoice_date}</font></td>
<td>
Expand Down Expand Up @@ -408,7 +408,7 @@
<tr>
<td colspan="2"></td>
<td><font size="1" align="right" style="font-weight:bold;">{ts}Customer:{/ts}</font></td>
<td><font size="1" align="right">{$display_name}</font></td>
<td><font size="1" align="right">{contact.display_name}</font></td>
</tr>
<tr>
<td colspan="2"></td>
Expand Down