CRM-20449: enotices from 'send thankyou letter' on contribution search
authoreileen <emcnaughton@wikimedia.org>
Sun, 23 Apr 2017 03:06:38 +0000 (15:06 +1200)
committereileen <emcnaughton@wikimedia.org>
Sun, 23 Apr 2017 08:01:29 +0000 (20:01 +1200)
CRM/Utils/Token.php
tests/phpunit/CRM/Utils/Token.php [new file with mode: 0644]

index 1353e2646008fd249bfbc032ef52f069450497e4..124394cd2e5b2d45d914faae1899ce3113911a43 100644 (file)
@@ -1249,22 +1249,15 @@ class CRM_Utils_Token {
 
     foreach ($contactIDs as $key => $contactID) {
       if (array_key_exists($contactID, $contactDetails)) {
-        if (CRM_Utils_Array::value('preferred_communication_method', $returnProperties) == 1
-          && array_key_exists('preferred_communication_method', $contactDetails[$contactID])
+        if (!empty($contactDetails[$contactID]['preferred_communication_method'])
         ) {
-          $pcm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
-
-          // communication Preference
-          $contactPcm = explode(CRM_Core_DAO::VALUE_SEPARATOR,
-            $contactDetails[$contactID]['preferred_communication_method']
-          );
-          $result = array();
-          foreach ($contactPcm as $key => $val) {
+          $communicationPreferences = array();
+          foreach ($contactDetails[$contactID]['preferred_communication_method'] as $key => $val) {
             if ($val) {
-              $result[$val] = $pcm[$val];
+              $communicationPreferences[$val] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_communication_method', $val);
             }
           }
-          $contactDetails[$contactID]['preferred_communication_method'] = implode(', ', $result);
+          $contactDetails[$contactID]['preferred_communication_method'] = implode(', ', $communicationPreferences);
         }
 
         foreach ($custom as $cfID) {
diff --git a/tests/phpunit/CRM/Utils/Token.php b/tests/phpunit/CRM/Utils/Token.php
new file mode 100644 (file)
index 0000000..5010669
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+/**
+ * Class CRM_Utils_TokenTest
+ * @group headless
+ */
+class CRM_Utils_TokenTest extends CiviUnitTestCase {
+
+  /**
+   * Basic test on getTokenDetails function.
+   */
+  public function testGetTokenDetails() {
+    $contactID = $this->individualCreate(array('preferred_communication_method' => array('Phone', 'Fax')));
+    $resolvedTokens = CRM_Utils_Token::getTokenDetails(array($contactID));
+    $this->assertEquals('Phone, Fax', $resolvedTokens[0][$contactID]['preferred_communication_method']);
+  }
+
+}