Merge pull request #6833 from eileenmcnaughton/email-test-fix
authorEileen McNaughton <eileen@mcnaughty.com>
Tue, 29 Sep 2015 06:22:07 +0000 (19:22 +1300)
committerEileen McNaughton <eileen@mcnaughty.com>
Tue, 29 Sep 2015 06:22:07 +0000 (19:22 +1300)
enable Single Value Alter test for email

CRM/Core/BAO/Email.php
tests/phpunit/api/v3/SyntaxConformanceTest.php

index c4ccb4baccbdea45785a5727321103d4752a88da..c0ff7949b367807da131fa2b22fbec946b1bb3a3 100644 (file)
@@ -72,10 +72,11 @@ class CRM_Core_BAO_Email extends CRM_Core_DAO_Email {
 
     $email = new CRM_Core_DAO_Email();
     $email->copyValues($params);
-
-    // lower case email field to optimize queries
-    $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
-    $email->email = $strtolower($email->email);
+    if (!empty($email->email)) {
+      // lower case email field to optimize queries
+      $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
+      $email->email = $strtolower($email->email);
+    }
 
     /*
      * since we're setting bulkmail for 1 of this contact's emails, first reset all their other emails to is_bulkmail false
@@ -83,7 +84,7 @@ class CRM_Core_BAO_Email extends CRM_Core_DAO_Email {
      *  are about to reset it to avoid contaminating the changelog if logging is enabled
      * (only 1 email address can have is_bulkmail = true)
      */
-    if ($email->is_bulkmail != 'null' && $params['contact_id'] && !self::isMultipleBulkMail()) {
+    if ($email->is_bulkmail != 'null' && !empty($params['contact_id']) && !self::isMultipleBulkMail()) {
       $sql = "
 UPDATE civicrm_email
 SET    is_bulkmail = 0
index a0540c78eae5afd2321420a7671f3e84e87eb0b6..17d8c68d50347a6764f0033bf8d85d2870220cac 100644 (file)
@@ -449,7 +449,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       'MailingEventResubscribe',
       'UFGroup',
       'Activity',
-      'Email',
       'Event',
       'GroupContact',
       'MembershipPayment',
@@ -567,6 +566,12 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
           'pcp_id',
         ),
       ),
+      'Email' => array(
+        'cant_update' => array(
+          // This is being legitimately manipulated to always have a valid primary - skip.
+          'is_primary',
+        ),
+      ),
       'Pledge' => array(
         'cant_update' => array(
           'pledge_original_installment_amount',
@@ -1182,6 +1187,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
           }
           else {
             $entity[$fieldName] = substr('New String', 0, CRM_Utils_Array::Value('maxlength', $specs, 100));
+            if ($fieldName == 'email') {
+              $entity[$fieldName] = strtolower($entity[$fieldName]);
+            }
             // typecast with array to satisfy changes made in CRM-13160
             if ($entityName == 'MembershipType' && in_array($fieldName, array(
                 'relationship_type_id',