Skip to content

Commit

Permalink
Fully deprecate getTokenDetails
Browse files Browse the repository at this point in the history
This is only called in legacy mailing code now so stop testing it & deprecate it
  • Loading branch information
eileenmcnaughton committed Jan 12, 2022
1 parent a7dfdd1 commit 6acef27
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 112 deletions.
1 change: 1 addition & 0 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ public static function getTokenDetails(
$className = NULL,
$jobID = NULL
) {
CRM_Core_Error::deprecatedFunctionWarning('If you hit this in mailing code you should use flexmailer - otherwise use the token processor');
$params = [];
foreach ($contactIDs as $contactID) {
$params[] = [
Expand Down
112 changes: 0 additions & 112 deletions tests/phpunit/CRM/Utils/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,6 @@
*/
class CRM_Utils_TokenTest extends CiviUnitTestCase {

/**
* Basic test on getTokenDetails function.
*/
public function testGetTokenDetails() {
$contactID = $this->individualCreate(['preferred_communication_method' => ['Phone', 'Fax']]);
[$resolvedTokens] = CRM_Utils_Token::getTokenDetails([$contactID]);
$this->assertEquals('Phone, Fax', $resolvedTokens[$contactID]['preferred_communication_method']);
}

/**
* Test getting contacts w/o primary location type
*
* Check for situation described in CRM-19876.
*/
public function testSearchByPrimaryLocation() {
// Disable searchPrimaryDetailsOnly civi settings so we could test the functionality without it.
Civi::settings()->set('searchPrimaryDetailsOnly', '0');

// create a contact with multiple email address and among which one is primary
$contactID = $this->individualCreate();
$primaryEmail = uniqid() . '@primary.com';
$this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => $primaryEmail,
'location_type_id' => 'Other',
'is_primary' => 1,
]);
$this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => uniqid() . '@galaxy.com',
'location_type_id' => 'Work',
'is_primary' => 0,
]);
$this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => uniqid() . '@galaxy.com',
'location_type_id' => 'Work',
'is_primary' => 0,
]);

$contactIDs = [$contactID];

// when we are fetching contact details ON basis of primary address fields
[$contactDetails] = CRM_Utils_Token::getTokenDetails($contactIDs);
$this->assertEquals($primaryEmail, $contactDetails[$contactID]['email']);

// restore setting
Civi::settings()->set('searchPrimaryDetailsOnly', '1');
}

/**
* Test for replaceGreetingTokens.
*
Expand Down Expand Up @@ -85,68 +35,6 @@ public function testReplaceGreetingTokens(): void {
$this->assertEquals($tokenString, 'Custom ');
}

/**
* Test getting multiple contacts.
*
* Check for situation described in CRM-19876.
*/
public function testGetTokenDetailsMultipleEmails() {
$i = 0;

$params = [
'do_not_phone' => 1,
'do_not_email' => 0,
'do_not_mail' => 1,
'do_not_sms' => 1,
'do_not_trade' => 1,
'is_opt_out' => 0,
'email' => '[email protected]',
'legal_identifier' => 'convict 56',
'nick_name' => 'bob',
'contact_source' => 'bargain basement',
'formal_title' => 'Your silliness',
'job_title' => 'World Saviour',
'gender_id' => '1',
'birth_date' => '2017-01-01',
// 'city' => 'Metropolis',
];
$contactIDs = [];
while ($i < 27) {
$contactIDs[] = $contactID = $this->individualCreate($params);
$this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => '[email protected]',
'location_type_id' => 'Other',
'is_primary' => 0,
]);
$this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => '[email protected]',
'location_type_id' => 'Work',
'is_primary' => 1,
]);
$i++;
}
unset($params['email']);

[$resolvedTokens] = CRM_Utils_Token::getTokenDetails($contactIDs);
foreach ($contactIDs as $contactID) {
$resolvedContactTokens = $resolvedTokens[$contactID];
$this->assertEquals('Individual', $resolvedContactTokens['contact_type']);
$this->assertEquals('Anderson, Anthony', $resolvedContactTokens['sort_name']);
$this->assertEquals('en_US', $resolvedContactTokens['preferred_language']);
$this->assertEquals('Both', $resolvedContactTokens['preferred_mail_format']);
$this->assertEquals(3, $resolvedContactTokens['prefix_id']);
$this->assertEquals(3, $resolvedContactTokens['suffix_id']);
$this->assertEquals('Mr. Anthony J. Anderson II', $resolvedContactTokens['addressee_display']);
$this->assertEquals('[email protected]', $resolvedContactTokens['email']);

foreach ($params as $key => $value) {
$this->assertEquals($value, $resolvedContactTokens[$key]);
}
}
}

/**
* This is a basic test of the token processor (currently testing TokenCompatSubscriber)
* and makes sure that greeting + contact tokens are replaced.
Expand Down

0 comments on commit 6acef27

Please sign in to comment.