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

Add unit test for handling other location in the labels #31192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 27 additions & 3 deletions tests/phpunit/CRM/Contact/Form/Task/PrintMailingLabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ public function testMailingLabelAddressMergeWithTokens(): void {
NETHERLANDS S', $rows[$this->ids['Contact']['collins']][0]);
}

/**
* Test rendering an alternate location.
*/
public function testMailingLabelOtherLocation(): void {
\Civi::settings()->set('mailing_format', $this->getDefaultMailingFormat() . ' {contact.phone}');
$this->createTestAddresses();
$rows = $this->submitForm([
'location_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Address', 'location_type_id', 'Work'),
]);
// Check that the non-primary phone has been appended - ie the one with 0 for non-primary at the end.
$this->assertEquals($this->getExpectedAddress('souza', FALSE) . ' 1230', $rows[$this->ids['Contact']['souza']][0]);
}

/**
* Test the mailing label rows contain the primary addresses when
* location_type_id = none (as primary) is chosen in form.
Expand Down Expand Up @@ -107,19 +120,20 @@ public function testMailingLabel(): void {
* Get the default address we expect for our test contact with the default string.
*
* @param string $identifier
* @param bool $isPrimary
*
* @return string
*/
protected function getExpectedAddress(string $identifier): string {
protected function getExpectedAddress(string $identifier, bool $isPrimary = TRUE): string {
if ($identifier === 'souza') {
return 'Mr. Antonia J. D`souza II
Main Street 231
Main Street 23' . (int) $isPrimary . '
Brummen, 6971 BN
NETHERLANDS';
}
if ($identifier === 'collins') {
return 'Mr. Anthony J. Collins II
Main Street 231
Main Street 23' . (int) $isPrimary . '
Brummen, 6971 BN
NETHERLANDS';
}
Expand Down Expand Up @@ -155,6 +169,16 @@ public function createTestAddresses(): array {
'postal_code' => '6971 BN',
'country_id' => '1152',
'city' => 'Brummen',
// Give them different location types, the actual types are random.
'location_type_id:name' => $isPrimary ? 'Main' : 'Work',
// this doesn't affect for non-primary address so we need to call the Address.update API again, see below at L57
'is_primary' => $isPrimary,
'contact_id' => $contactID,
]);
$this->createTestEntity('Phone', [
'phone' => '123' . (int) $isPrimary,
// Give them different location types, the actual types are random.
'location_type_id:name' => $isPrimary ? 'Main' : 'Work',
// this doesn't affect for non-primary address so we need to call the Address.update API again, see below at L57
'is_primary' => $isPrimary,
'contact_id' => $contactID,
Expand Down