diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php
index aa882def57d5..5347d07b0ed6 100644
--- a/CRM/Utils/Token.php
+++ b/CRM/Utils/Token.php
@@ -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[] = [
diff --git a/tests/phpunit/CRM/Mailing/MailingSystemTest.php b/tests/phpunit/CRM/Mailing/MailingSystemTest.php
index 21dc496d0982..9f89c0c22105 100644
--- a/tests/phpunit/CRM/Mailing/MailingSystemTest.php
+++ b/tests/phpunit/CRM/Mailing/MailingSystemTest.php
@@ -21,7 +21,10 @@
*/
/**
- * Class CRM_Mailing_MailingSystemTest
+ * Class CRM_Mailing_MailingSystemTest.
+ *
+ * This class tests the deprecated code that we are moving
+ * away from supporting.
*
* MailingSystemTest checks that overall composition and delivery of
* CiviMail blasts works. It extends CRM_Mailing_BaseMailingSystemTest
@@ -38,6 +41,9 @@ class CRM_Mailing_MailingSystemTest extends CRM_Mailing_BaseMailingSystemTest {
private $counts;
+ /**
+ * Set up the deprecated bao support.
+ */
public function setUp(): void {
parent::setUp();
// If we happen to execute with flexmailer active, use BAO mode.
@@ -47,16 +53,20 @@ public function setUp(): void {
$hooks = \CRM_Utils_Hook::singleton();
$hooks->setHook('civicrm_alterMailParams',
[$this, 'hook_alterMailParams']);
+ error_reporting(E_ALL && !E_USER_DEPRECATED);
}
/**
* @see CRM_Utils_Hook::alterMailParams
*/
- public function hook_alterMailParams(&$params, $context = NULL) {
+ public function hook_alterMailParams(&$params, $context = NULL): void {
$this->counts['hook_alterMailParams'] = 1;
$this->assertEquals('civimail', $context);
}
+ /**
+ * Post test cleanup.
+ */
public function tearDown(): void {
global $dbLocale;
if ($dbLocale) {
@@ -66,6 +76,30 @@ public function tearDown(): void {
$this->assertNotEmpty($this->counts['hook_alterMailParams']);
}
+ /**
+ * Test legacy mailer preview functionality.
+ */
+ public function testMailerPreviewExtraScheme(): void {
+ $contactID = $this->individualCreate();
+ $displayName = $this->callAPISuccess('contact', 'get', ['id' => $contactID]);
+ $displayName = $displayName['values'][$contactID]['display_name'];
+ $this->assertNotEmpty($displayName);
+
+ $params = $this->_params;
+ $params['body_html'] = 'Forward this email written in ckeditor';
+ $params['api.Mailing.preview'] = [
+ 'id' => '$value.id',
+ 'contact_id' => $contactID,
+ ];
+ $params['options']['force_rollback'] = 1;
+
+ $result = $this->callAPISuccess('mailing', 'create', $params);
+ $previewResult = $result['values'][$result['id']]['api.Mailing.preview'];
+ $this->assertRegexp('!>Forward this email written in ckeditor!', $previewResult['values']['body_html']);
+ $this->assertRegexp('!!', $previewResult['values']['body_html']);
+ $this->assertStringNotContainsString("http://http://", $previewResult['values']['body_html']);
+ }
+
// ---- Boilerplate ----
// The remainder of this class contains dummy stubs which make it easier to
diff --git a/tests/phpunit/CRM/Utils/TokenTest.php b/tests/phpunit/CRM/Utils/TokenTest.php
index 3e84ee845c39..ba14fb9c342c 100644
--- a/tests/phpunit/CRM/Utils/TokenTest.php
+++ b/tests/phpunit/CRM/Utils/TokenTest.php
@@ -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.
*
@@ -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' => 'guardians@galaxy.com',
- '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' => 'goodguy@galaxy.com',
- 'location_type_id' => 'Other',
- 'is_primary' => 0,
- ]);
- $this->callAPISuccess('Email', 'create', [
- 'contact_id' => $contactID,
- 'email' => 'villain@galaxy.com',
- '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('villain@galaxy.com', $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.
diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php
index d4b3a2008fed..6c2cff8267b1 100644
--- a/tests/phpunit/api/v3/MailingTest.php
+++ b/tests/phpunit/api/v3/MailingTest.php
@@ -306,37 +306,6 @@ public function testMailerPreview(): void {
$this->assertStringNotContainsString("http://http://", $previewResult['values']['body_html']);
}
- /**
- *
- */
- public function testMailerPreviewExtraScheme() {
- try {
- \Civi::settings()->set('flexmailer_traditional', 'bao');
-
- $contactID = $this->individualCreate();
- $displayName = $this->callAPISuccess('contact', 'get', ['id' => $contactID]);
- $displayName = $displayName['values'][$contactID]['display_name'];
- $this->assertNotEmpty($displayName);
-
- $params = $this->_params;
- $params['body_html'] = 'Forward this email written in ckeditor';
- $params['api.Mailing.preview'] = [
- 'id' => '$value.id',
- 'contact_id' => $contactID,
- ];
- $params['options']['force_rollback'] = 1;
-
- $result = $this->callAPISuccess('mailing', 'create', $params);
- $previewResult = $result['values'][$result['id']]['api.Mailing.preview'];
- $this->assertRegexp('!>Forward this email written in ckeditor!', $previewResult['values']['body_html']);
- $this->assertRegexp('!!', $previewResult['values']['body_html']);
- $this->assertStringNotContainsString("http://http://", $previewResult['values']['body_html']);
-
- } finally {
- \Civi::settings()->revert('flexmailer_traditional');
- }
- }
-
public function testMailerPreviewUnknownContact(): void {
$params = $this->_params;
$params['api.Mailing.preview'] = [