Skip to content

Commit

Permalink
Swap displayName smarty for {contact.display_name token}
Browse files Browse the repository at this point in the history
This swaps over the smartyToken for the token token on the template added on new installs, and adds a test.

Separately I will look at an upgrade script and other templates

To test make sure you enable invoicing & then generate an invoice from search results.
use the demo site due to aforementioned lack of upgrade and check the display name is still on
the left hand side
  • Loading branch information
eileenmcnaughton committed Jul 22, 2021
1 parent 46b9500 commit 24dac2a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 20 deletions.
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>
{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

0 comments on commit 24dac2a

Please sign in to comment.