-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86eb0e7
commit c93917b
Showing
5 changed files
with
150 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,7 +323,7 @@ public function testContactTokens(): void { | |
$this->hookClass->setHook('civicrm_tokens', [$this, 'hookTokens']); | ||
|
||
$this->createCustomGroupWithFieldsOfAllTypes([]); | ||
$tokenData = $this->getAllContactTokens(); | ||
$tokenData = $this->getOldContactTokens(); | ||
$address = $this->setupContactFromTokeData($tokenData); | ||
$advertisedTokens = CRM_Core_SelectValues::contactTokens(); | ||
$this->assertEquals($this->getAdvertisedTokens(), $advertisedTokens); | ||
|
@@ -458,25 +458,34 @@ public function hookTokens(array &$hookTokens): void { | |
*/ | ||
public function testContactTokensRenderedByTokenProcessor(): void { | ||
$this->createCustomGroupWithFieldsOfAllTypes([]); | ||
$tokenData = $this->getAllContactTokens(); | ||
$tokenData = $this->getOldContactTokens(); | ||
$address = $this->setupContactFromTokeData($tokenData); | ||
$tokenString = ''; | ||
foreach (array_keys($tokenData) as $key) { | ||
$tokenString .= "{$key}:{contact.{$key}}\n"; | ||
} | ||
$newStyleTokenString = ''; | ||
foreach (array_keys($this->getAdvertisedTokens()) as $key) { | ||
$newStyleTokenString .= substr($key, 9, -1) . ' |' . $key . "\n"; | ||
} | ||
$tokenProcessor = new TokenProcessor(Civi::dispatcher(), []); | ||
$tokenProcessor->addMessage('html', $tokenString, 'text/html'); | ||
$tokenProcessor->addMessage('new', $newStyleTokenString, 'text/html'); | ||
|
||
$tokenProcessor->addRow(['contactId' => $tokenData['contact_id']]); | ||
$tokenProcessor->evaluate(); | ||
$rendered = ''; | ||
foreach ($tokenProcessor->getRows() as $row) { | ||
$rendered = (string) $row->render('html'); | ||
$newStyleRendered = $row->render('new'); | ||
} | ||
$expected = $this->getExpectedContactOutput($address['id'], $tokenData, $rendered); | ||
// @todo - this works better in token processor than in CRM_Core_Token. | ||
// once synced we can fix $this->getExpectedContactOutput to return the right thing. | ||
$expected = str_replace("preferred_communication_method:\n", "preferred_communication_method:Phone\n", $expected); | ||
$this->assertEquals($expected, $rendered); | ||
$this->assertEquals($this->getExpectedContactOutputNewStyle($address['id'], $tokenData, $newStyleRendered), $newStyleRendered); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -614,7 +623,7 @@ public function getAdvertisedTokens(): array { | |
* @throws \CRM_Core_Exception | ||
* @throws \CiviCRM_API3_Exception | ||
*/ | ||
public function getAllContactTokens(): array { | ||
public function getOldContactTokens(): array { | ||
return [ | ||
'contact_type' => 'Individual', | ||
'do_not_email' => 1, | ||
|
@@ -666,7 +675,6 @@ public function getAllContactTokens(): array { | |
'postal_code' => '90210', | ||
'geo_code_1' => '48.858093', | ||
'geo_code_2' => '2.294694', | ||
'manual_geo_code' => TRUE, | ||
'address_name' => 'The white house', | ||
'master_id' => $this->callAPISuccess('Address', 'create', [ | ||
'contact_id' => $this->individualCreate(), | ||
|
@@ -807,7 +815,6 @@ protected function getExpectedContactOutput($id, array $tokenData, string $actua | |
postal_code:90210 | ||
geo_code_1:48.858093 | ||
geo_code_2:2.294694 | ||
manual_geo_code:1 | ||
address_name:The white house | ||
master_id:' . $tokenData['master_id'] . ' | ||
county: | ||
|
@@ -841,6 +848,106 @@ protected function getExpectedContactOutput($id, array $tokenData, string $actua | |
custom_13:Purple | ||
checksum:cs=' . $checksum . ' | ||
contact_id:' . $tokenData['contact_id'] . ' | ||
'; | ||
return $expected; | ||
} | ||
|
||
/** | ||
* Get the expected rendered string. | ||
* | ||
* @param int $id | ||
* @param array $tokenData | ||
* @param string $actualOutput | ||
* | ||
* @return string | ||
* @throws \API_Exception | ||
*/ | ||
protected function getExpectedContactOutputNewStyle($id, array $tokenData, string $actualOutput): string { | ||
$checksum = substr($actualOutput, (strpos($actualOutput, 'cs=') + 3), 47); | ||
$contact = Contact::get(FALSE)->addWhere('id', '=', $tokenData['contact_id'])->setSelect(['modified_date', 'employer_id'])->execute()->first(); | ||
$expected = 'contact_type:label |Individual | ||
do_not_email:label |No | ||
do_not_phone:label |No | ||
do_not_mail:label |Yes | ||
do_not_sms:label |Yes | ||
do_not_trade:label |Yes | ||
is_opt_out:label |Yes | ||
external_identifier |blah | ||
sort_name |Smith, Robert | ||
display_name |Mr. Robert Smith II | ||
nick_name |Bob | ||
image_URL |https://example.com | ||
preferred_communication_method:label |Phone | ||
preferred_language |fr_CA | ||
preferred_mail_format:label |Both | ||
hash |xyz | ||
source |Contact Source | ||
first_name |Robert | ||
middle_name |Frank | ||
last_name |Smith | ||
prefix_id:label |Mr. | ||
suffix_id:label |II | ||
formal_title |Dogsbody | ||
communication_style_id:label |Formal | ||
job_title |Busy person | ||
gender_id:label |Female | ||
birth_date |December 31st, 1998 | ||
employer_id |' . $contact['employer_id'] . ' | ||
is_deleted | | ||
created_date |January 1st, 2020 12:00 AM | ||
modified_date |' . CRM_Utils_Date::customFormat($contact['modified_date']) . ' | ||
addressee_display |Mr. Robert Frank Smith II | ||
email_greeting_display |Dear Robert | ||
postal_greeting_display |Dear Robert | ||
employer_id.display_name |Unit Test Organization | ||
primary_address.location_type_id:label |Home | ||
primary_address.id |' . $id . ' | ||
primary_address.street_address |Street Address | ||
primary_address.street_number |123 | ||
primary_address.street_number_suffix |S | ||
primary_address.street_name |Main St | ||
primary_address.street_unit |45B | ||
primary_address.supplemental_address_1 |Round the corner | ||
primary_address.supplemental_address_2 |Up the road | ||
primary_address.supplemental_address_3 |By the big tree | ||
primary_address.city |New York | ||
primary_address.postal_code_suffix |4578 | ||
primary_address.postal_code |90210 | ||
primary_address.geo_code_1 |48.858093 | ||
primary_address.geo_code_2 |2.294694 | ||
primary_address.name |The white house | ||
primary_address.master_id |' . $tokenData['master_id'] . ' | ||
primary_address.county_id:label | | ||
primary_address.state_province_id:label |TX | ||
primary_address.country_id:label |United States | ||
primary_phone.phone |123-456 | ||
primary_phone.phone_ext |77 | ||
primary_phone.phone_type_id |2 | ||
primary_phone.phone_type_id:label |Mobile | ||
primary_email.email |[email protected] | ||
primary_email.on_hold | | ||
primary_email.signature_text |Yours sincerely | ||
primary_email.signature_html |<p>Yours</p> | ||
primary_im.provider_id |1 | ||
primary_im.name |IM Screen Name | ||
primary_OpenID |OpenID | ||
primary_address.world_region |America South, Central, North and Caribbean | ||
primary_website.url |http://civicrm.org | ||
custom_9 |Mr. Spider Man II | ||
custom_7 |New Zealand | ||
custom_8 |France, Canada | ||
custom_1 |Bobsled | ||
custom_2 |Red | ||
custom_3 |01/20/2021 12 |00AM | ||
custom_4 |999 | ||
custom_5 |<a href="http://civicrm.org" target="_blank">http://civicrm.org</a> | ||
custom_6 | | ||
custom_10 |Queensland | ||
custom_11 |Victoria, New South Wales | ||
custom_12 |Yes | ||
custom_13 |Purple | ||
checksum |cs=' . $checksum . ' | ||
id |' . $tokenData['contact_id'] . ' | ||
'; | ||
return $expected; | ||
} | ||
|