Merge pull request #14266 from seamuslee001/dev_core_369
authorEileen McNaughton <eileen@mcnaughty.com>
Mon, 20 May 2019 23:17:55 +0000 (11:17 +1200)
committerGitHub <noreply@github.com>
Mon, 20 May 2019 23:17:55 +0000 (11:17 +1200)
dev/core#369 Prevent hard fail of API Job when SMS provider has been deleted

18 files changed:
CRM/Admin/Form/SettingTrait.php
CRM/Contact/BAO/Contact.php
CRM/Contribute/BAO/Contribution.php
CRM/Dedupe/Merger.php
CRM/Financial/BAO/Payment.php
CRM/Report/Form/Contribute/Summary.php
Civi/Core/SettingsMetadata.php
LICENSE [moved from agpl-3.0.txt with 100% similarity]
api/v3/Setting.php
tests/phpunit/CRM/Dedupe/MergerTest.php
tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php
tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php
tests/phpunit/CRM/Utils/DeprecatedUtilsTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContactTest.php
tests/phpunit/api/v3/CustomValueTest.php
tests/phpunit/api/v3/GroupNestingTest.php
tests/phpunit/api/v3/dataset/email_contact_17.xml [deleted file]

index f22470803fe66521fcd3ad141c6d8a02bfce1c92..308d409e7ea5b0b69351811740f0dc4a8f7e5a38 100644 (file)
@@ -66,8 +66,7 @@ trait CRM_Admin_Form_SettingTrait {
    */
   protected function getSettingsMetaData() {
     if (empty($this->settingsMetadata)) {
-      $allSettingMetaData = civicrm_api3('setting', 'getfields', []);
-      $this->settingsMetadata = array_intersect_key($allSettingMetaData['values'], $this->_settings);
+      $this->settingsMetadata = \Civi\Core\SettingsMetadata::getMetadata(['name' => array_keys($this->_settings)], NULL, TRUE);
       // This array_merge re-orders to the key order of $this->_settings.
       $this->settingsMetadata = array_merge($this->_settings, $this->settingsMetadata);
     }
@@ -174,10 +173,7 @@ trait CRM_Admin_Form_SettingTrait {
       $quickFormType = $this->getQuickFormType($props);
       if (isset($quickFormType)) {
         $options = CRM_Utils_Array::value('options', $props);
-        if (isset($props['pseudoconstant'])) {
-          $options = civicrm_api3('Setting', 'getoptions', [
-            'field' => $setting,
-          ])['values'];
+        if ($options) {
           if ($props['html_type'] === 'Select' && isset($props['is_required']) && $props['is_required'] === FALSE && !isset($options[''])) {
             // If the spec specifies the field is not required add a null option.
             // Why not if empty($props['is_required']) - basically this has been added to the spec & might not be set to TRUE
index 7280f6d5c75bd9aace4f860d8189a9743130c690..5a22a86d7850614dd166ec3e224723876f565e74 100644 (file)
@@ -1736,7 +1736,7 @@ WHERE     civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer');
    * @return array
    *   Contact details
    */
-  public static function getHierContactDetails($contactId, &$fields) {
+  public static function getHierContactDetails($contactId, $fields) {
     $params = array(array('contact_id', '=', $contactId, 0, 0));
     $options = array();
 
@@ -2073,7 +2073,7 @@ ORDER BY civicrm_email.is_primary DESC";
    */
   public static function formatProfileContactParams(
     &$params,
-    &$fields,
+    $fields,
     $contactID = NULL,
     $ufGroupId = NULL,
     $ctype = NULL,
index d5f7a0b76e0c8a0b379ba2a67e308960bafeaa34..8f1fd8db46e51045e8cf1b3fbaaefcc41c151237 100644 (file)
@@ -3591,8 +3591,12 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
     ) {
       return;
     }
-    if ((($previousContributionStatus == 'Partially paid'
-      && $currentContributionStatus == 'Completed')
+    // The 'right' way to add payments or refunds is through the Payment.create api. That api
+    // then updates the contribution but this process shoud not also record another financial trxn.
+    if ((($previousContributionStatus == 'Partially paid' && $currentContributionStatus == 'Completed')
+      || ($previousContributionStatus == 'Pending refund' && $currentContributionStatus == 'Completed')
+      // This concept of pay_later as different to any other sort of pending is deprecated & it's unclear
+      // why it is here or where it is handled instead.
       || ($previousContributionStatus == 'Pending' && $params['prevContribution']->is_pay_later == TRUE
       && $currentContributionStatus == 'Partially paid'))
       && $context == 'changedStatus'
index f5e1a2428f61650036c379bafda51dd8b572d11e..7e713da3a6e7d5d7f6ab68f0b7777aad2bdf1908 100644 (file)
@@ -1080,8 +1080,6 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
 
     $main = self::getMergeContactDetails($mainId);
     $other = self::getMergeContactDetails($otherId);
-    $specialValues['main'] = self::getSpecialValues($main);
-    $specialValues['other'] = self::getSpecialValues($other);
 
     $compareFields = self::retrieveFields($main, $other);
 
@@ -1093,12 +1091,21 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
         continue;
       }
       foreach (['main' => $main, 'other' => $other] as $moniker => $contact) {
-        $value = CRM_Utils_Array::value($field, $contact);
-        if (isset($specialValues[$moniker][$field]) && is_string($specialValues[$moniker][$field])) {
-          $value = CRM_Core_DAO::VALUE_SEPARATOR . trim($specialValues[$moniker][$field], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
+        $value = $label = CRM_Utils_Array::value($field, $contact);
+        $fieldSpec = $fields[$field];
+        if (!empty($fieldSpec['serialize']) && is_array($value)) {
+          // In practice this only applies to preferred_communication_method as the sub types are skipped above
+          // and no others are serialized.
+          $labels = [];
+          foreach ($value as $individualValue) {
+            $labels[] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $field, $individualValue);
+          }
+          $label = implode(', ', $labels);
+          // We serialize this due to historic handling but it's likely that if we just left it as an
+          // array all would be well & we would have less code.
+          $value = CRM_Core_DAO::serializeField($value, $fieldSpec['serialize']);
         }
-        $label = isset($specialValues[$moniker]["{$field}_display"]) ? $specialValues[$moniker]["{$field}_display"] : $value;
-        if (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_DATE) {
+        elseif (!empty($fieldSpec['type']) && $fieldSpec['type'] == CRM_Utils_Type::T_DATE) {
           if ($value) {
             $value = str_replace('-', '', $value);
             $label = CRM_Utils_Date::customFormat($label);
@@ -1115,15 +1122,8 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
             $label = ts('[x]');
           }
         }
-        elseif ($field == 'prefix_id') {
-          $label = CRM_Utils_Array::value('individual_prefix', $contact);
-        }
-        elseif ($field == 'suffix_id') {
-          $label = CRM_Utils_Array::value('individual_suffix', $contact);
-        }
-        elseif ($field == 'gender_id' && !empty($value)) {
-          $genderOptions = civicrm_api3('contact', 'getoptions', ['field' => 'gender_id']);
-          $label = $genderOptions['values'][$value];
+        elseif (!empty($fieldSpec['pseudoconstant'])) {
+          $label = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $field, $value);
         }
         elseif ($field == 'current_employer_id' && !empty($value)) {
           $label = "$value (" . CRM_Contact_BAO_Contact::displayName($value) . ")";
@@ -1881,38 +1881,6 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     return $cacheKeyString;
   }
 
-  /**
-   * @param array $contact
-   * @return array
-   *   $specialValues
-   */
-  public static function getSpecialValues($contact) {
-    $preferred_communication_method = CRM_Utils_Array::value('preferred_communication_method', $contact);
-    $value = empty($preferred_communication_method) ? [] : $preferred_communication_method;
-    $specialValues = [
-      'preferred_communication_method' => $value,
-      'communication_style_id' => $value,
-    ];
-
-    if (!empty($contact['preferred_communication_method'])) {
-      // api 3 returns pref_comm_method as an array, which breaks the lookup; so we reconstruct
-      $prefCommList = is_array($specialValues['preferred_communication_method']) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $specialValues['preferred_communication_method']) : $specialValues['preferred_communication_method'];
-      $specialValues['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
-    }
-    $names = [
-      'preferred_communication_method' => [
-        'newName' => 'preferred_communication_method_display',
-        'groupName' => 'preferred_communication_method',
-      ],
-    ];
-    CRM_Core_OptionGroup::lookupValues($specialValues, $names);
-
-    if (!empty($contact['communication_style'])) {
-      $specialValues['communication_style_id_display'] = $contact['communication_style'];
-    }
-    return $specialValues;
-  }
-
   /**
    * Get the metadata for the merge fields.
    *
index e743d2d796851b6e7983565a65cb1345fdc4b371..664c193e0cc4f8d7d8533f540730384015f15dad 100644 (file)
@@ -51,6 +51,7 @@ class CRM_Financial_BAO_Payment {
    *
    * @throws \API_Exception
    * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public static function create($params) {
     $contribution = civicrm_api3('Contribution', 'getsingle', ['id' => $params['contribution_id']]);
@@ -104,11 +105,24 @@ class CRM_Financial_BAO_Payment {
     }
 
     if ($isPaymentCompletesContribution) {
-      civicrm_api3('Contribution', 'completetransaction', ['id' => $contribution['id']]);
-      // Get the trxn
-      $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
-      $ftParams = ['id' => $trxnId['financialTrxnId']];
-      $trxn = CRM_Core_BAO_FinancialTrxn::retrieve($ftParams, CRM_Core_DAO::$_nullArray);
+      if ($contributionStatus == 'Pending refund') {
+        // Ideally we could still call completetransaction as non-payment related actions should
+        // be outside this class. However, for now we just update the contribution here.
+        // Unit test cover in CRM_Event_BAO_AdditionalPaymentTest::testTransactionInfo.
+        civicrm_api3('Contribution', 'create',
+          [
+            'id' => $contribution['id'],
+            'contribution_status_id' => 'Completed',
+          ]
+        );
+      }
+      else {
+        civicrm_api3('Contribution', 'completetransaction', ['id' => $contribution['id']]);
+        // Get the trxn
+        $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
+        $ftParams = ['id' => $trxnId['financialTrxnId']];
+        $trxn = CRM_Core_BAO_FinancialTrxn::retrieve($ftParams, CRM_Core_DAO::$_nullArray);
+      }
     }
     elseif ($contributionStatus === 'Pending') {
       civicrm_api3('Contribution', 'create',
index 05d72b807f19a6a919f6c4893cbfa66c90d2491c..81a692cae57cca950f9fbff84c6b092a90a69d62 100644 (file)
@@ -631,7 +631,7 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_
 
     $contriSQL = "SELECT {$contriQuery} {$group} {$this->_having}";
     $contriDAO = CRM_Core_DAO::executeQuery($contriSQL);
-
+    $this->addToDeveloperTab($contriSQL);
     $totalAmount = $average = $mode = $median = $softTotalAmount = $softAverage = array();
     $count = $softCount = 0;
     while ($contriDAO->fetch()) {
@@ -655,6 +655,7 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_
 
     if ($softCredit) {
       $softDAO = CRM_Core_DAO::executeQuery($softSQL);
+      $this->addToDeveloperTab($softSQL);
       while ($softDAO->fetch()) {
         $softTotalAmount[]
           = CRM_Utils_Money::format($softDAO->civicrm_contribution_soft_soft_amount_sum, $softDAO->currency) .
@@ -725,6 +726,7 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_
    */
   public function buildRows($sql, &$rows) {
     $dao = CRM_Core_DAO::executeQuery($sql);
+    $this->addToDeveloperTab($sql);
     if (!is_array($rows)) {
       $rows = array();
     }
@@ -742,6 +744,7 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_
       $this->customDataFrom();
       $contriSQL = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}";
       $contriDAO = CRM_Core_DAO::executeQuery($contriSQL);
+      $this->addToDeveloperTab($contriSQL);
       $contriFields = array(
         'civicrm_contribution_total_amount_sum',
         'civicrm_contribution_total_amount_avg',
index 6aeaa3c490a2613702086dd1af5637890fdf4dad..5ff1bf3bf82772bd5405389cc0e1fe4b5f0b7916 100644 (file)
@@ -51,6 +51,7 @@ class SettingsMetadata {
    *
    * @param array $filters
    * @param int $domainID
+   * @param bool $loadOptions
    *
    * @return array
    *   the following information as appropriate for each setting
@@ -62,8 +63,10 @@ class SettingsMetadata {
    *   - is_contact
    *   - description
    *   - help_text
+   *   - options
+   *   - pseudoconstant
    */
-  public static function getMetadata($filters = [], $domainID = NULL) {
+  public static function getMetadata($filters = [], $domainID = NULL, $loadOptions = FALSE) {
     if ($domainID === NULL) {
       $domainID = \CRM_Core_Config::domainID();
     }
@@ -82,6 +85,9 @@ class SettingsMetadata {
     }
 
     self::_filterSettingsSpecification($filters, $settingsMetadata);
+    if ($loadOptions) {
+      self::loadOptions($settingsMetadata);
+    }
 
     return $settingsMetadata;
   }
@@ -132,20 +138,41 @@ class SettingsMetadata {
    *   Metadata to filter.
    */
   protected static function _filterSettingsSpecification($filters, &$settingSpec) {
-    if (empty($filters)) {
-      return;
-    }
-    elseif (array_keys($filters) == ['name']) {
-      $settingSpec = [$filters['name'] => \CRM_Utils_Array::value($filters['name'], $settingSpec, '')];
-      return;
+    if (!empty($filters['name'])) {
+      $settingSpec = array_intersect_key($settingSpec, array_flip((array) $filters['name']));
+      // FIXME: This is a workaround for settingsBag::setDb() called by unit tests with settings names that don't exist
+      $settingSpec += array_fill_keys((array) $filters['name'], []);
+      unset($filters['name']);
     }
-    else {
+    if (!empty($filters)) {
       foreach ($settingSpec as $field => $fieldValues) {
         if (array_intersect_assoc($fieldValues, $filters) != $filters) {
           unset($settingSpec[$field]);
         }
       }
-      return;
+    }
+  }
+
+  /**
+   * Retrieve options from settings metadata
+   *
+   * @param array $settingSpec
+   */
+  protected static function loadOptions(&$settingSpec) {
+    foreach ($settingSpec as &$spec) {
+      if (empty($spec['pseudoconstant'])) {
+        continue;
+      }
+      // It would be nice if we could leverage CRM_Core_PseudoConstant::get() somehow,
+      // but it's tightly coupled to DAO/field. However, if you really need to support
+      // more pseudoconstant types, then probably best to refactor it. For now, KISS.
+      if (!empty($spec['pseudoconstant']['callback'])) {
+        $spec['options'] = Resolver::singleton()->call($spec['pseudoconstant']['callback'], []);
+      }
+      elseif (!empty($spec['pseudoconstant']['optionGroupName'])) {
+        $keyColumn = \CRM_Utils_Array::value('keyColumn', $spec['pseudoconstant'], 'value');
+        $spec['options'] = \CRM_Core_OptionGroup::values($spec['pseudoconstant']['optionGroupName'], FALSE, FALSE, TRUE, NULL, 'label', TRUE, FALSE, $keyColumn);
+      }
     }
   }
 
similarity index 100%
rename from agpl-3.0.txt
rename to LICENSE
index e7d2338c254f9859b9130045d5d3a37f1d67b9ee..a7ce04b76fcd4356bdd4268096e20674851b1897 100644 (file)
@@ -148,33 +148,14 @@ function _civicrm_api3_setting_getdefaults_spec(&$params) {
  * @throws \API_Exception
  */
 function civicrm_api3_setting_getoptions($params) {
-  $specs = CRM_Core_BAO_Setting::getSettingSpecification();
+  $domainId = CRM_Utils_Array::value('domain_id', $params);
+  $specs = \Civi\Core\SettingsMetadata::getMetadata(['name' => $params['field']], $domainId, TRUE);
 
-  if (empty($specs[$params['field']]) || empty($specs[$params['field']]['pseudoconstant'])) {
+  if (empty($specs[$params['field']]) || !is_array(CRM_Utils_Array::value('options', $specs[$params['field']]))) {
     throw new API_Exception("The field '" . $params['field'] . "' has no associated option list.");
   }
 
-  $pseudoconstant = $specs[$params['field']]['pseudoconstant'];
-
-  // It would be nice if we could leverage CRM_Core_PseudoConstant::get() somehow,
-  // but it's tightly coupled to DAO/field. However, if you really need to support
-  // more pseudoconstant types, then probably best to refactor it. For now, KISS.
-  if (!empty($pseudoconstant['callback'])) {
-    $values = Civi\Core\Resolver::singleton()->call($pseudoconstant['callback'], []);
-    return civicrm_api3_create_success($values, $params, 'Setting', 'getoptions');
-  }
-  elseif (!empty($pseudoconstant['optionGroupName'])) {
-    $keyColumn = 'value';
-    if (!empty($pseudoconstant['keyColumn'])) {
-      $keyColumn = $pseudoconstant['keyColumn'];
-    }
-    return civicrm_api3_create_success(
-      CRM_Core_OptionGroup::values($pseudoconstant['optionGroupName'], FALSE, FALSE, TRUE, NULL, 'label', TRUE, FALSE, $keyColumn),
-      $params, 'Setting', 'getoptions'
-    );
-  }
-
-  throw new API_Exception("The field '" . $params['field'] . "' uses an unsupported option list.");
+  return civicrm_api3_create_success($specs[$params['field']]['options'], $params, 'Setting', 'getoptions');
 }
 
 /**
index 96f440873f980496c62fc6eaf0cdf8823f637c15..78dffbff2925d6c728c07f9dae144c1bf315921b 100644 (file)
@@ -2,27 +2,38 @@
 
 /**
  * Class CRM_Dedupe_DedupeMergerTest
+ *
  * @group headless
  */
 class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
 
   protected $_groupId;
-  protected $_contactIds = array();
 
+  protected $_contactIds = [];
+
+  /**
+   * Tear down.
+   *
+   * @throws \Exception
+   */
   public function tearDown() {
-    $this->quickCleanup(array('civicrm_contact', 'civicrm_group_contact', 'civicrm_group'));
+    $this->quickCleanup([
+      'civicrm_contact',
+      'civicrm_group_contact',
+      'civicrm_group',
+    ]);
     parent::tearDown();
   }
 
   public function createDupeContacts() {
     // create a group to hold contacts, so that dupe checks don't consider any other contacts in the DB
-    $params = array(
-      'name'       => 'Test Dupe Merger Group',
-      'title'      => 'Test Dupe Merger Group',
-      'domain_id'  => 1,
-      'is_active'  => 1,
+    $params = [
+      'name' => 'Test Dupe Merger Group',
+      'title' => 'Test Dupe Merger Group',
+      'domain_id' => 1,
+      'is_active' => 1,
       'visibility' => 'Public Pages',
-    );
+    ];
 
     $result = $this->callAPISuccess('group', 'create', $params);
     $this->_groupId = $result['id'];
@@ -41,62 +52,62 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
     // will   - dale - dale@example.com
     // will   - dale - will@example.com
     // will   - dale - will@example.com
-    $params = array(
-      array(
+    $params = [
+      [
         'first_name' => 'robin',
         'last_name' => 'hood',
         'email' => 'robin@example.com',
         'contact_type' => 'Individual',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'robin',
         'last_name' => 'hood',
         'email' => 'robin@example.com',
         'contact_type' => 'Individual',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'robin',
         'last_name' => 'hood',
         'email' => 'hood@example.com',
         'contact_type' => 'Individual',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'robin',
         'last_name' => 'dale',
         'email' => 'robin@example.com',
         'contact_type' => 'Individual',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'little',
         'last_name' => 'dale',
         'email' => 'dale@example.com',
         'contact_type' => 'Individual',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'little',
         'last_name' => 'dale',
         'email' => 'dale@example.com',
         'contact_type' => 'Individual',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'will',
         'last_name' => 'dale',
         'email' => 'dale@example.com',
         'contact_type' => 'Individual',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'will',
         'last_name' => 'dale',
         'email' => 'will@example.com',
         'contact_type' => 'Individual',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'will',
         'last_name' => 'dale',
         'email' => 'will@example.com',
         'contact_type' => 'Individual',
-      ),
-    );
+      ],
+    ];
 
     $count = 1;
     foreach ($params as $param) {
@@ -104,11 +115,11 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
       $contact = civicrm_api('contact', 'create', $param);
       $this->_contactIds[$count++] = $contact['id'];
 
-      $grpParams = array(
+      $grpParams = [
         'contact_id' => $contact['id'],
-        'group_id'   => $this->_groupId,
-        'version'    => 3,
-      );
+        'group_id' => $this->_groupId,
+        'version' => 3,
+      ];
       $this->callAPISuccess('group_contact', 'create', $grpParams);
     }
   }
@@ -163,7 +174,7 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
     @$object->run();
 
     // Retrieve pairs from prev next cache table
-    $select = array('pn.is_selected' => 'is_selected');
+    $select = ['pn.is_selected' => 'is_selected'];
     $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($dao->id, $this->_groupId);
     $pnDupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, NULL, NULL, 0, 0, $select);
 
@@ -227,7 +238,7 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
     @$object->run();
 
     // Retrieve pairs from prev next cache table
-    $select = array('pn.is_selected' => 'is_selected');
+    $select = ['pn.is_selected' => 'is_selected'];
     $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($dao->id, $this->_groupId);
     $pnDupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, NULL, NULL, 0, 0, $select);
 
@@ -261,18 +272,18 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    * @return array
    */
   public function getHackedInCIDRef() {
-    return array(
-      'civicrm_entity_tag' => array(
+    return [
+      'civicrm_entity_tag' => [
         0 => 'entity_id',
-      ),
-    );
+      ],
+    ];
   }
 
   /**
    * Test function that gets duplicate pairs.
    *
-   * It turns out there are 2 code paths retrieving this data so my initial focus is on ensuring
-   * they match.
+   * It turns out there are 2 code paths retrieving this data so my initial
+   * focus is on ensuring they match.
    */
   public function testGetMatches() {
     $this->setupMatchData();
@@ -284,34 +295,40 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
       FALSE
     );
 
-    $this->assertEquals(array(
-      0 => array(
+    $this->assertEquals([
+      0 => [
         'srcID' => $this->contacts[1]['id'],
         'srcName' => 'Mr. Mickey Mouse II',
         'dstID' => $this->contacts[0]['id'],
         'dstName' => 'Mr. Mickey Mouse II',
         'weight' => 20,
         'canMerge' => TRUE,
-      ),
-      1 => array(
+      ],
+      1 => [
         'srcID' => $this->contacts[3]['id'],
         'srcName' => 'Mr. Minnie Mouse II',
         'dstID' => $this->contacts[2]['id'],
         'dstName' => 'Mr. Minnie Mouse II',
         'weight' => 20,
         'canMerge' => TRUE,
-      ),
-    ), $pairs);
+      ],
+    ], $pairs);
   }
 
   /**
    * Test function that gets organization pairs.
    *
-   * Note the rule will match on organization_name OR email - hence lots of matches.
+   * Note the rule will match on organization_name OR email - hence lots of
+   * matches.
+   *
+   * @throws \Exception
    */
   public function testGetOrganizationMatches() {
     $this->setupMatchData();
-    $ruleGroups = $this->callAPISuccessGetSingle('RuleGroup', array('contact_type' => 'Organization', 'used' => 'Supervised'));
+    $ruleGroups = $this->callAPISuccessGetSingle('RuleGroup', [
+      'contact_type' => 'Organization',
+      'used' => 'Supervised',
+    ]);
 
     $pairs = CRM_Dedupe_Merger::getDuplicatePairs(
       $ruleGroups['id'],
@@ -321,42 +338,42 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
       FALSE
     );
 
-    $expectedPairs = array(
-      0 => array(
+    $expectedPairs = [
+      0 => [
         'srcID' => $this->contacts[5]['id'],
         'srcName' => 'Walt Disney Ltd',
         'dstID' => $this->contacts[4]['id'],
         'dstName' => 'Walt Disney Ltd',
         'weight' => 20,
         'canMerge' => TRUE,
-      ),
-      1 => array(
+      ],
+      1 => [
         'srcID' => $this->contacts[7]['id'],
         'srcName' => 'Walt Disney',
         'dstID' => $this->contacts[6]['id'],
         'dstName' => 'Walt Disney',
         'weight' => 10,
         'canMerge' => TRUE,
-      ),
-      2 => array(
+      ],
+      2 => [
         'srcID' => $this->contacts[6]['id'],
         'srcName' => 'Walt Disney',
         'dstID' => $this->contacts[4]['id'],
         'dstName' => 'Walt Disney Ltd',
         'weight' => 10,
         'canMerge' => TRUE,
-      ),
-      3 => array(
+      ],
+      3 => [
         'srcID' => $this->contacts[6]['id'],
         'srcName' => 'Walt Disney',
         'dstID' => $this->contacts[5]['id'],
         'dstName' => 'Walt Disney Ltd',
         'weight' => 10,
         'canMerge' => TRUE,
-      ),
-    );
-    usort($pairs, array(__CLASS__, 'compareDupes'));
-    usort($expectedPairs, array(__CLASS__, 'compareDupes'));
+      ],
+    ];
+    usort($pairs, [__CLASS__, 'compareDupes']);
+    usort($expectedPairs, [__CLASS__, 'compareDupes']);
     $this->assertEquals($expectedPairs, $pairs);
   }
 
@@ -365,10 +382,11 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    *
    * @param array $a
    * @param array $b
+   *
    * @return int
    */
   public static function compareDupes($a, $b) {
-    foreach (array('srcName', 'dstName', 'srcID', 'dstID') as $field) {
+    foreach (['srcName', 'dstName', 'srcID', 'dstID'] as $field) {
       if ($a[$field] != $b[$field]) {
         return ($a[$field] < $b[$field]) ? 1 : -1;
       }
@@ -378,14 +396,22 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
 
   /**
    *  Test function that gets organization duplicate pairs.
+   *
+   * @throws \Exception
    */
   public function testGetOrganizationMatchesInGroup() {
     $this->setupMatchData();
-    $ruleGroups = $this->callAPISuccessGetSingle('RuleGroup', array('contact_type' => 'Organization', 'used' => 'Supervised'));
+    $ruleGroups = $this->callAPISuccessGetSingle('RuleGroup', [
+      'contact_type' => 'Organization',
+      'used' => 'Supervised',
+    ]);
 
-    $groupID = $this->groupCreate(array('title' => 'she-mice'));
+    $groupID = $this->groupCreate(['title' => 'she-mice']);
 
-    $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $this->contacts[4]['id']));
+    $this->callAPISuccess('GroupContact', 'create', [
+      'group_id' => $groupID,
+      'contact_id' => $this->contacts[4]['id'],
+    ]);
 
     $pairs = CRM_Dedupe_Merger::getDuplicatePairs(
       $ruleGroups['id'],
@@ -395,26 +421,29 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
       FALSE
     );
 
-    $this->assertEquals(array(
-      0 => array(
+    $this->assertEquals([
+      0 => [
         'srcID' => $this->contacts[5]['id'],
         'srcName' => 'Walt Disney Ltd',
         'dstID' => $this->contacts[4]['id'],
         'dstName' => 'Walt Disney Ltd',
         'weight' => 20,
         'canMerge' => TRUE,
-      ),
-      1 => array(
+      ],
+      1 => [
         'srcID' => $this->contacts[6]['id'],
         'srcName' => 'Walt Disney',
         'dstID' => $this->contacts[4]['id'],
         'dstName' => 'Walt Disney Ltd',
         'weight' => 10,
         'canMerge' => TRUE,
-      ),
-    ), $pairs);
+      ],
+    ], $pairs);
 
-    $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $this->contacts[5]['id']));
+    $this->callAPISuccess('GroupContact', 'create', [
+      'group_id' => $groupID,
+      'contact_id' => $this->contacts[5]['id'],
+    ]);
     CRM_Core_DAO::executeQuery("DELETE FROM civicrm_prevnext_cache");
     $pairs = CRM_Dedupe_Merger::getDuplicatePairs(
       $ruleGroups['id'],
@@ -424,46 +453,49 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
       FALSE
     );
 
-    $this->assertEquals(array(
-      0 => array(
+    $this->assertEquals([
+      0 => [
         'srcID' => $this->contacts[5]['id'],
         'srcName' => 'Walt Disney Ltd',
         'dstID' => $this->contacts[4]['id'],
         'dstName' => 'Walt Disney Ltd',
         'weight' => 20,
         'canMerge' => TRUE,
-      ),
-      1 => array(
+      ],
+      1 => [
         'srcID' => $this->contacts[6]['id'],
         'srcName' => 'Walt Disney',
         'dstID' => $this->contacts[4]['id'],
         'dstName' => 'Walt Disney Ltd',
         'weight' => 10,
         'canMerge' => TRUE,
-      ),
-      2 => array(
+      ],
+      2 => [
         'srcID' => $this->contacts[6]['id'],
         'srcName' => 'Walt Disney',
         'dstID' => $this->contacts[5]['id'],
         'dstName' => 'Walt Disney Ltd',
         'weight' => 10,
         'canMerge' => TRUE,
-      ),
-    ), $pairs);
+      ],
+    ], $pairs);
   }
 
   /**
    * Test function that gets duplicate pairs.
    *
-   * It turns out there are 2 code paths retrieving this data so my initial focus is on ensuring
-   * they match.
+   * It turns out there are 2 code paths retrieving this data so my initial
+   * focus is on ensuring they match.
    */
   public function testGetMatchesInGroup() {
     $this->setupMatchData();
 
-    $groupID = $this->groupCreate(array('title' => 'she-mice'));
+    $groupID = $this->groupCreate(['title' => 'she-mice']);
 
-    $this->callAPISuccess('GroupContact', 'create', array('group_id' => $groupID, 'contact_id' => $this->contacts[3]['id']));
+    $this->callAPISuccess('GroupContact', 'create', [
+      'group_id' => $groupID,
+      'contact_id' => $this->contacts[3]['id'],
+    ]);
 
     $pairs = CRM_Dedupe_Merger::getDuplicatePairs(
       1,
@@ -473,16 +505,68 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
       FALSE
     );
 
-    $this->assertEquals(array(
-      0 => array(
+    $this->assertEquals([
+      0 => [
         'srcID' => $this->contacts[3]['id'],
         'srcName' => 'Mr. Minnie Mouse II',
         'dstID' => $this->contacts[2]['id'],
         'dstName' => 'Mr. Minnie Mouse II',
         'weight' => 20,
         'canMerge' => TRUE,
-      ),
-    ), $pairs);
+      ],
+    ], $pairs);
+  }
+
+  /**
+   * Test the special info handling is unchanged after cleanup.
+   *
+   * Note the handling is silly - we are testing to lock in over short term
+   * changes not to imply any contract on the function.
+   */
+  public function testGetRowsElementsAndInfoSpecialInfo() {
+    $contact1 = $this->individualCreate([
+      'preferred_communication_method' => [],
+      'communication_style_id' => 'Familiar',
+      'prefix_id' => 'Mrs.',
+      'suffix_id' => 'III',
+    ]);
+    $contact2 = $this->individualCreate([
+      'preferred_communication_method' => [
+        'SMS',
+        'Fax',
+      ],
+      'communication_style_id' => 'Formal',
+      'gender_id' => 'Female',
+    ]);
+    $rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($contact1, $contact2);
+    $rows = $rowsElementsAndInfo['rows'];
+    $this->assertEquals([
+      'main' => 'Mrs.',
+      'other' => 'Mr.',
+      'title' => 'Individual Prefix',
+    ], $rows['move_prefix_id']);
+    $this->assertEquals([
+      'main' => 'III',
+      'other' => 'II',
+      'title' => 'Individual Suffix',
+    ], $rows['move_suffix_id']);
+    $this->assertEquals([
+      'main' => '',
+      'other' => 'Female',
+      'title' => 'Gender',
+    ], $rows['move_gender_id']);
+    $this->assertEquals([
+      'main' => 'Familiar',
+      'other' => 'Formal',
+      'title' => 'Communication Style',
+    ], $rows['move_communication_style_id']);
+    $this->assertEquals(1, $rowsElementsAndInfo['migration_info']['move_communication_style_id']);
+    $this->assertEquals([
+      'main' => '',
+      'other' => 'SMS, Fax',
+      'title' => 'Preferred Communication Method',
+    ], $rows['move_preferred_communication_method']);
+    $this->assertEquals('\ 14\ 15\ 1', $rowsElementsAndInfo['migration_info']['move_preferred_communication_method']);
   }
 
   /**
@@ -496,7 +580,7 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
 
     //Add Membership for the duplicate contact.
     $memTypeId = $this->membershipTypeCreate();
-    $membership = $this->callAPISuccess('Membership', 'create', [
+    $this->callAPISuccess('Membership', 'create', [
       'membership_type_id' => $memTypeId,
       'contact_id' => $duplicateContactID,
     ]);
@@ -529,7 +613,7 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    */
   public function testCustomDataOverwrite() {
     // Create Custom Field
-    $createGroup  = $this->setupCustomGroupForIndividual();
+    $createGroup = $this->setupCustomGroupForIndividual();
     $createField = $this->setupCustomField('Graduation', $createGroup);
     $customFieldName = "custom_" . $createField['id'];
 
@@ -543,41 +627,41 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
     $duplicateContactID2 = $this->contacts[2]['id'];
 
     // update the text custom field for original contact with value 'abc'
-    $this->callAPISuccess('Contact', 'create', array(
+    $this->callAPISuccess('Contact', 'create', [
       'id' => $originalContactID,
       "{$customFieldName}" => 'abc',
-    ));
+    ]);
     $this->assertCustomFieldValue($originalContactID, 'abc', $customFieldName);
 
     // update the text custom field for duplicate contact 1 with value 'def'
-    $this->callAPISuccess('Contact', 'create', array(
+    $this->callAPISuccess('Contact', 'create', [
       'id' => $duplicateContactID1,
       "{$customFieldName}" => 'def',
-    ));
+    ]);
     $this->assertCustomFieldValue($duplicateContactID1, 'def', $customFieldName);
 
     // update the text custom field for duplicate contact 2 with value 'ghi'
-    $this->callAPISuccess('Contact', 'create', array(
+    $this->callAPISuccess('Contact', 'create', [
       'id' => $duplicateContactID2,
       "{$customFieldName}" => 'ghi',
-    ));
+    ]);
     $this->assertCustomFieldValue($duplicateContactID2, 'ghi', $customFieldName);
 
     /*** USE-CASE 1: DO NOT OVERWRITE CUSTOM FIELD VALUE **/
-    $this->mergeContacts($originalContactID, $duplicateContactID1, array(
+    $this->mergeContacts($originalContactID, $duplicateContactID1, [
       "move_{$customFieldName}" => NULL,
-    ));
+    ]);
     $this->assertCustomFieldValue($originalContactID, 'abc', $customFieldName);
 
     /*** USE-CASE 2: OVERWRITE CUSTOM FIELD VALUE **/
-    $this->mergeContacts($originalContactID, $duplicateContactID2, array(
+    $this->mergeContacts($originalContactID, $duplicateContactID2, [
       "move_{$customFieldName}" => 'ghi',
-    ));
+    ]);
     $this->assertCustomFieldValue($originalContactID, 'ghi', $customFieldName);
 
     // cleanup created custom set
-    $this->callAPISuccess('CustomField', 'delete', array('id' => $createField['id']));
-    $this->callAPISuccess('CustomGroup', 'delete', array('id' => $createGroup['id']));
+    $this->callAPISuccess('CustomField', 'delete', ['id' => $createField['id']]);
+    $this->callAPISuccess('CustomGroup', 'delete', ['id' => $createGroup['id']]);
   }
 
   /**
@@ -588,16 +672,16 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    */
   public function testMigrationOfUnselectedCustomDataOnEmptyCustomRecord() {
     // Create Custom Fields
-    $createGroup  = $this->setupCustomGroupForIndividual();
+    $createGroup = $this->setupCustomGroupForIndividual();
     $customField1 = $this->setupCustomField('TestField', $createGroup);
 
     // Create multi-value custom field
     $multiGroup = $this->CustomGroupMultipleCreateByParams();
-    $multiField = $this->customFieldCreate(array(
+    $multiField = $this->customFieldCreate([
       'custom_group_id' => $multiGroup['id'],
       'label' => 'field_1' . $multiGroup['id'],
       'in_selector' => 1,
-    ));
+    ]);
 
     // Contacts setup
     $this->setupMatchData();
@@ -605,27 +689,27 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
     $duplicateContactID = $this->contacts[1]['id'];
 
     // Update the text custom fields for duplicate contact
-    $this->callAPISuccess('Contact', 'create', array(
+    $this->callAPISuccess('Contact', 'create', [
       'id' => $duplicateContactID,
       "custom_{$customField1['id']}" => 'abc',
       "custom_{$multiField['id']}" => 'def',
-    ));
+    ]);
     $this->assertCustomFieldValue($duplicateContactID, 'abc', "custom_{$customField1['id']}");
     $this->assertCustomFieldValue($duplicateContactID, 'def', "custom_{$multiField['id']}");
 
     // Merge, and ensure that no value was migrated
-    $this->mergeContacts($originalContactID, $duplicateContactID, array(
+    $this->mergeContacts($originalContactID, $duplicateContactID, [
       "move_custom_{$customField1['id']}" => NULL,
       "move_rel_table_custom_{$multiGroup['id']}" => NULL,
-    ));
+    ]);
     $this->assertCustomFieldValue($originalContactID, '', "custom_{$customField1['id']}");
     $this->assertCustomFieldValue($originalContactID, '', "custom_{$multiField['id']}");
 
     // cleanup created custom set
-    $this->callAPISuccess('CustomField', 'delete', array('id' => $customField1['id']));
-    $this->callAPISuccess('CustomGroup', 'delete', array('id' => $createGroup['id']));
-    $this->callAPISuccess('CustomField', 'delete', array('id' => $multiField['id']));
-    $this->callAPISuccess('CustomGroup', 'delete', array('id' => $multiGroup['id']));
+    $this->callAPISuccess('CustomField', 'delete', ['id' => $customField1['id']]);
+    $this->callAPISuccess('CustomGroup', 'delete', ['id' => $createGroup['id']]);
+    $this->callAPISuccess('CustomField', 'delete', ['id' => $multiField['id']]);
+    $this->callAPISuccess('CustomGroup', 'delete', ['id' => $multiGroup['id']]);
   }
 
   /**
@@ -636,17 +720,17 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    */
   public function testMigrationOfSomeCustomDataOnEmptyCustomRecord() {
     // Create Custom Fields
-    $createGroup  = $this->setupCustomGroupForIndividual();
+    $createGroup = $this->setupCustomGroupForIndividual();
     $customField1 = $this->setupCustomField('Test1', $createGroup);
     $customField2 = $this->setupCustomField('Test2', $createGroup);
 
     // Create multi-value custom field
     $multiGroup = $this->CustomGroupMultipleCreateByParams();
-    $multiField = $this->customFieldCreate(array(
+    $multiField = $this->customFieldCreate([
       'custom_group_id' => $multiGroup['id'],
       'label' => 'field_1' . $multiGroup['id'],
       'in_selector' => 1,
-    ));
+    ]);
 
     // Contacts setup
     $this->setupMatchData();
@@ -654,32 +738,32 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
     $duplicateContactID = $this->contacts[1]['id'];
 
     // Update the text custom fields for duplicate contact
-    $this->callAPISuccess('Contact', 'create', array(
+    $this->callAPISuccess('Contact', 'create', [
       'id' => $duplicateContactID,
       "custom_{$customField1['id']}" => 'abc',
       "custom_{$customField2['id']}" => 'def',
       "custom_{$multiField['id']}" => 'ghi',
-    ));
+    ]);
     $this->assertCustomFieldValue($duplicateContactID, 'abc', "custom_{$customField1['id']}");
     $this->assertCustomFieldValue($duplicateContactID, 'def', "custom_{$customField2['id']}");
     $this->assertCustomFieldValue($duplicateContactID, 'ghi', "custom_{$multiField['id']}");
 
     // Perform merge
-    $this->mergeContacts($originalContactID, $duplicateContactID, array(
+    $this->mergeContacts($originalContactID, $duplicateContactID, [
       "move_custom_{$customField1['id']}" => NULL,
       "move_custom_{$customField2['id']}" => 'def',
       "move_rel_table_custom_{$multiGroup['id']}" => '1',
-    ));
+    ]);
     $this->assertCustomFieldValue($originalContactID, '', "custom_{$customField1['id']}");
     $this->assertCustomFieldValue($originalContactID, 'def', "custom_{$customField2['id']}");
     $this->assertCustomFieldValue($originalContactID, 'ghi', "custom_{$multiField['id']}");
 
     // cleanup created custom set
-    $this->callAPISuccess('CustomField', 'delete', array('id' => $customField1['id']));
-    $this->callAPISuccess('CustomField', 'delete', array('id' => $customField2['id']));
-    $this->callAPISuccess('CustomGroup', 'delete', array('id' => $createGroup['id']));
-    $this->callAPISuccess('CustomField', 'delete', array('id' => $multiField['id']));
-    $this->callAPISuccess('CustomGroup', 'delete', array('id' => $multiGroup['id']));
+    $this->callAPISuccess('CustomField', 'delete', ['id' => $customField1['id']]);
+    $this->callAPISuccess('CustomField', 'delete', ['id' => $customField2['id']]);
+    $this->callAPISuccess('CustomGroup', 'delete', ['id' => $createGroup['id']]);
+    $this->callAPISuccess('CustomField', 'delete', ['id' => $multiField['id']]);
+    $this->callAPISuccess('CustomGroup', 'delete', ['id' => $multiGroup['id']]);
   }
 
   /**
@@ -692,14 +776,17 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    * @param $params
    *   Array of fields to be merged from source into target contact, of the form
    *   ['move_<fieldName>' => <fieldValue>]
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   private function mergeContacts($originalContactID, $duplicateContactID, $params) {
     $rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($originalContactID, $duplicateContactID);
 
-    $migrationData = array(
+    $migrationData = [
       'main_details' => $rowsElementsAndInfo['main_details'],
       'other_details' => $rowsElementsAndInfo['other_details'],
-    );
+    ];
 
     // Migrate data of duplicate contact
     CRM_Dedupe_Merger::moveAllBelongings($originalContactID, $duplicateContactID, array_merge($migrationData, $params));
@@ -714,10 +801,10 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    * @param $customFieldName
    */
   private function assertCustomFieldValue($contactID, $expectedValue, $customFieldName) {
-    $data = $this->callAPISuccess('Contact', 'getsingle', array(
+    $data = $this->callAPISuccess('Contact', 'getsingle', [
       'id' => $contactID,
-      'return' => array($customFieldName),
-    ));
+      'return' => [$customFieldName],
+    ]);
 
     $this->assertEquals($expectedValue, $data[$customFieldName], "Custom field value was supposed to be '{$expectedValue}', '{$data[$customFieldName]}' found.");
   }
@@ -729,22 +816,22 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    *   Data for the created custom group record
    */
   private function setupCustomGroupForIndividual() {
-    $customGroup = $this->callAPISuccess('custom_group', 'get', array(
+    $customGroup = $this->callAPISuccess('custom_group', 'get', [
       'name' => 'test_group',
-    ));
+    ]);
 
     if ($customGroup['count'] > 0) {
-      $this->callAPISuccess('CustomGroup', 'delete', array('id' => $customGroup['id']));
+      $this->callAPISuccess('CustomGroup', 'delete', ['id' => $customGroup['id']]);
     }
 
-    $customGroup = $this->callAPISuccess('custom_group', 'create', array(
+    $customGroup = $this->callAPISuccess('custom_group', 'create', [
       'title' => 'Test_Group',
       'name' => 'test_group',
-      'extends' => array('Individual'),
+      'extends' => ['Individual'],
       'style' => 'Inline',
       'is_multiple' => FALSE,
       'is_active' => 1,
-    ));
+    ]);
 
     return $customGroup;
   }
@@ -760,65 +847,65 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    *   Data for the created custom field record
    */
   private function setupCustomField($fieldLabel, $createGroup) {
-    return $this->callAPISuccess('custom_field', 'create', array(
+    return $this->callAPISuccess('custom_field', 'create', [
       'label' => $fieldLabel,
       'data_type' => 'Alphanumeric',
       'html_type' => 'Text',
       'custom_group_id' => $createGroup['id'],
-    ));
+    ]);
   }
 
   /**
    * Set up some contacts for our matching.
    */
   public function setupMatchData() {
-    $fixtures = array(
-      array(
+    $fixtures = [
+      [
         'first_name' => 'Mickey',
         'last_name' => 'Mouse',
         'email' => 'mickey@mouse.com',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'Mickey',
         'last_name' => 'Mouse',
         'email' => 'mickey@mouse.com',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'Minnie',
         'last_name' => 'Mouse',
         'email' => 'mickey@mouse.com',
-      ),
-      array(
+      ],
+      [
         'first_name' => 'Minnie',
         'last_name' => 'Mouse',
         'email' => 'mickey@mouse.com',
-      ),
-    );
+      ],
+    ];
     foreach ($fixtures as $fixture) {
       $contactID = $this->individualCreate($fixture);
-      $this->contacts[] = array_merge($fixture, array('id' => $contactID));
+      $this->contacts[] = array_merge($fixture, ['id' => $contactID]);
     }
-    $organizationFixtures = array(
-      array(
+    $organizationFixtures = [
+      [
         'organization_name' => 'Walt Disney Ltd',
         'email' => 'walt@disney.com',
-      ),
-      array(
+      ],
+      [
         'organization_name' => 'Walt Disney Ltd',
         'email' => 'walt@disney.com',
-      ),
-      array(
+      ],
+      [
         'organization_name' => 'Walt Disney',
         'email' => 'walt@disney.com',
-      ),
-      array(
+      ],
+      [
         'organization_name' => 'Walt Disney',
         'email' => 'walter@disney.com',
-      ),
-    );
+      ],
+    ];
     foreach ($organizationFixtures as $fixture) {
       $contactID = $this->organizationCreate($fixture);
-      $this->contacts[] = array_merge($fixture, array('id' => $contactID));
+      $this->contacts[] = array_merge($fixture, ['id' => $contactID]);
     }
   }
 
@@ -827,203 +914,204 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase {
    *
    * This is a statically maintained (in this test list).
    *
-   * There is also a check against an automated list but having both seems to add extra stability to me. They do
-   * not change often.
+   * There is also a check against an automated list but having both seems to
+   * add extra stability to me. They do not change often.
    */
   public function getStaticCIDRefs() {
-    return array(
-      'civicrm_acl_cache' => array(
+    return [
+      'civicrm_acl_cache' => [
         0 => 'contact_id',
-      ),
-      'civicrm_acl_contact_cache' => array(
+      ],
+      'civicrm_acl_contact_cache' => [
         0 => 'contact_id',
-      ),
-      'civicrm_action_log' => array(
+      ],
+      'civicrm_action_log' => [
         0 => 'contact_id',
-      ),
-      'civicrm_activity_contact' => array(
+      ],
+      'civicrm_activity_contact' => [
         0 => 'contact_id',
-      ),
-      'civicrm_address' => array(
+      ],
+      'civicrm_address' => [
         0 => 'contact_id',
-      ),
-      'civicrm_batch' => array(
+      ],
+      'civicrm_batch' => [
         0 => 'created_id',
         1 => 'modified_id',
-      ),
-      'civicrm_campaign' => array(
+      ],
+      'civicrm_campaign' => [
         0 => 'created_id',
         1 => 'last_modified_id',
-      ),
-      'civicrm_case_contact' => array(
+      ],
+      'civicrm_case_contact' => [
         0 => 'contact_id',
-      ),
-      'civicrm_contact' => array(
+      ],
+      'civicrm_contact' => [
         0 => 'primary_contact_id',
         1 => 'employer_id',
-      ),
-      'civicrm_contribution' => array(
+      ],
+      'civicrm_contribution' => [
         0 => 'contact_id',
-      ),
-      'civicrm_contribution_page' => array(
+      ],
+      'civicrm_contribution_page' => [
         0 => 'created_id',
-      ),
-      'civicrm_contribution_recur' => array(
+      ],
+      'civicrm_contribution_recur' => [
         0 => 'contact_id',
-      ),
-      'civicrm_contribution_soft' => array(
+      ],
+      'civicrm_contribution_soft' => [
         0 => 'contact_id',
-      ),
-      'civicrm_custom_group' => array(
+      ],
+      'civicrm_custom_group' => [
         0 => 'created_id',
-      ),
-      'civicrm_dashboard_contact' => array(
+      ],
+      'civicrm_dashboard_contact' => [
         0 => 'contact_id',
-      ),
-      'civicrm_dedupe_exception' => array(
+      ],
+      'civicrm_dedupe_exception' => [
         0 => 'contact_id1',
         1 => 'contact_id2',
-      ),
-      'civicrm_domain' => array(
+      ],
+      'civicrm_domain' => [
         0 => 'contact_id',
-      ),
-      'civicrm_email' => array(
+      ],
+      'civicrm_email' => [
         0 => 'contact_id',
-      ),
-      'civicrm_event' => array(
+      ],
+      'civicrm_event' => [
         0 => 'created_id',
-      ),
-      'civicrm_event_carts' => array(
+      ],
+      'civicrm_event_carts' => [
         0 => 'user_id',
-      ),
-      'civicrm_financial_account' => array(
+      ],
+      'civicrm_financial_account' => [
         0 => 'contact_id',
-      ),
-      'civicrm_financial_item' => array(
+      ],
+      'civicrm_financial_item' => [
         0 => 'contact_id',
-      ),
-      'civicrm_grant' => array(
+      ],
+      'civicrm_grant' => [
         0 => 'contact_id',
-      ),
-      'civicrm_group' => array(
+      ],
+      'civicrm_group' => [
         0 => 'created_id',
         1 => 'modified_id',
-      ),
-      'civicrm_group_contact' => array(
+      ],
+      'civicrm_group_contact' => [
         0 => 'contact_id',
-      ),
-      'civicrm_group_contact_cache' => array(
+      ],
+      'civicrm_group_contact_cache' => [
         0 => 'contact_id',
-      ),
-      'civicrm_group_organization' => array(
+      ],
+      'civicrm_group_organization' => [
         0 => 'organization_id',
-      ),
-      'civicrm_im' => array(
+      ],
+      'civicrm_im' => [
         0 => 'contact_id',
-      ),
-      'civicrm_log' => array(
+      ],
+      'civicrm_log' => [
         0 => 'modified_id',
-      ),
-      'civicrm_mailing' => array(
+      ],
+      'civicrm_mailing' => [
         0 => 'created_id',
         1 => 'scheduled_id',
         2 => 'approver_id',
-      ),
-      'civicrm_file' => array(
+      ],
+      'civicrm_file' => [
         'created_id',
-      ),
-      'civicrm_mailing_abtest' => array(
+      ],
+      'civicrm_mailing_abtest' => [
         0 => 'created_id',
-      ),
-      'civicrm_mailing_event_queue' => array(
+      ],
+      'civicrm_mailing_event_queue' => [
         0 => 'contact_id',
-      ),
-      'civicrm_mailing_event_subscribe' => array(
+      ],
+      'civicrm_mailing_event_subscribe' => [
         0 => 'contact_id',
-      ),
-      'civicrm_mailing_recipients' => array(
+      ],
+      'civicrm_mailing_recipients' => [
         0 => 'contact_id',
-      ),
-      'civicrm_membership' => array(
+      ],
+      'civicrm_membership' => [
         0 => 'contact_id',
-      ),
-      'civicrm_membership_log' => array(
+      ],
+      'civicrm_membership_log' => [
         0 => 'modified_id',
-      ),
-      'civicrm_membership_type' => array(
+      ],
+      'civicrm_membership_type' => [
         0 => 'member_of_contact_id',
-      ),
-      'civicrm_note' => array(
+      ],
+      'civicrm_note' => [
         0 => 'contact_id',
-      ),
-      'civicrm_openid' => array(
+      ],
+      'civicrm_openid' => [
         0 => 'contact_id',
-      ),
-      'civicrm_participant' => array(
+      ],
+      'civicrm_participant' => [
         0 => 'contact_id',
         //CRM-16761
         1 => 'transferred_to_contact_id',
-      ),
-      'civicrm_payment_token' => array(
+      ],
+      'civicrm_payment_token' => [
         0 => 'contact_id',
         1 => 'created_id',
-      ),
-      'civicrm_pcp' => array(
+      ],
+      'civicrm_pcp' => [
         0 => 'contact_id',
-      ),
-      'civicrm_phone' => array(
+      ],
+      'civicrm_phone' => [
         0 => 'contact_id',
-      ),
-      'civicrm_pledge' => array(
+      ],
+      'civicrm_pledge' => [
         0 => 'contact_id',
-      ),
-      'civicrm_print_label' => array(
+      ],
+      'civicrm_print_label' => [
         0 => 'created_id',
-      ),
-      'civicrm_relationship' => array(
+      ],
+      'civicrm_relationship' => [
         0 => 'contact_id_a',
         1 => 'contact_id_b',
-      ),
-      'civicrm_report_instance' => array(
+      ],
+      'civicrm_report_instance' => [
         0 => 'created_id',
         1 => 'owner_id',
-      ),
-      'civicrm_setting' => array(
+      ],
+      'civicrm_setting' => [
         0 => 'contact_id',
         1 => 'created_id',
-      ),
-      'civicrm_subscription_history' => array(
+      ],
+      'civicrm_subscription_history' => [
         0 => 'contact_id',
-      ),
-      'civicrm_survey' => array(
+      ],
+      'civicrm_survey' => [
         0 => 'created_id',
         1 => 'last_modified_id',
-      ),
-      'civicrm_tag' => array(
+      ],
+      'civicrm_tag' => [
         0 => 'created_id',
-      ),
-      'civicrm_uf_group' => array(
+      ],
+      'civicrm_uf_group' => [
         0 => 'created_id',
-      ),
-      'civicrm_uf_match' => array(
+      ],
+      'civicrm_uf_match' => [
         0 => 'contact_id',
-      ),
-      'civicrm_value_testgetcidref_1' => array(
+      ],
+      'civicrm_value_testgetcidref_1' => [
         0 => 'entity_id',
-      ),
-      'civicrm_website' => array(
+      ],
+      'civicrm_website' => [
         0 => 'contact_id',
-      ),
-    );
+      ],
+    ];
   }
 
   /**
    * Get a list of CIDs that is calculated off the schema.
    *
-   * Note this is an expensive and table locking query. Should be safe in tests though.
+   * Note this is an expensive and table locking query. Should be safe in tests
+   * though.
    */
   public function getCalculatedCIDRefs() {
-    $cidRefs = array();
+    $cidRefs = [];
     $sql = "
 SELECT
     table_name,
index aa4cd9e4313a619862cd286eddaa4ee0c2ca7745..9e70d946bfb8c90c0f68df9500540963e6de25f1 100644 (file)
@@ -214,20 +214,23 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
     $result = $this->addParticipantWithPayment($feeAmt, $amtPaid);
     $contributionID = $result['contribution']['id'];
 
-    //Complete the partial payment.
-    $submittedValues = array(
+    $this->callAPISuccess('Payment', 'create', [
+      'contribution_id' => $contributionID,
       'total_amount' => 20,
       'payment_instrument_id' => 3,
-    );
-    CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contributionID, $submittedValues, 'owed', $result['participant']['id']);
+      'participant_id' => $result['participant']['id'],
+    ]);
 
     //Change selection to a lower amount.
     $params['price_2'] = 50;
     CRM_Price_BAO_LineItem::changeFeeSelections($params, $result['participant']['id'], 'participant', $contributionID, $result['feeBlock'], $result['lineItem']);
 
-    //Record a refund of the remaining amount.
-    $submittedValues['total_amount'] = 50;
-    CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contributionID, $submittedValues, 'refund', $result['participant']['id']);
+    $this->callAPISuccess('Payment', 'create', [
+      'total_amount' => -50,
+      'contribution_id' => $contributionID,
+      'participant_id' => $result['participant']['id'],
+      'payment_instrument_id' => 3,
+    ]);
     $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($result['participant']['id'], 'event', TRUE);
     $transaction = $paymentInfo['transaction'];
 
index a2fc34fbbcefbb96a72955bc8b693e852905af32..047fcb652d6ae48131ddee1f95445787de88f23a 100644 (file)
@@ -308,12 +308,12 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
     $contributionBalance = ($this->_cheapFee - $actualPaidAmount);
     $this->assertEquals($contributionBalance, CRM_Contribute_BAO_Contribution::getContributionBalance($this->_contributionId));
 
-    //Complete the refund payment.
-    $submittedValues = array(
-      'total_amount' => 120,
+    $this->callAPISuccess('Payment', 'create', [
+      'contribution_id' => $this->_contributionId,
+      'total_amount' => -120,
       'payment_instrument_id' => 3,
-    );
-    CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $submittedValues, 'refund', $this->_participantId);
+      'participant_id' => $this->_participantId,
+    ]);
     $contributionBalance += 120;
     $this->assertEquals($contributionBalance, CRM_Contribute_BAO_Contribution::getContributionBalance($this->_contributionId));
 
index 9c7277504c360aa2896c7b3c3ac5f1998cf26745..e202473a214b5eed1258aa55f6a729dc54dfcf61 100644 (file)
@@ -38,28 +38,17 @@ class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase {
    *  and request the error in array format
    */
   public function testCheckParamsWithDuplicateContact2() {
-    //  Insert a row in civicrm_contact creating individual contact
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/../../api/v3/dataset/contact_17.xml'
-      )
-    );
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml'
-      )
-    );
+    $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact', 'email' => 'TestContact@example.com']);
 
-    $params = array(
+    $params = [
       'first_name' => 'Test',
       'last_name' => 'Contact',
       'email' => 'TestContact@example.com',
       'contact_type' => 'Individual',
-    );
+    ];
     $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE);
     $this->assertEquals(1, $contact['is_error']);
-    $this->assertRegexp("/matching contacts.*17/s",
+    $this->assertRegexp("/matching contacts.*1/s",
       $contact['error_message']['message']
     );
   }
index 63c6a363de46fa4f81d35c6bbec42e5643b0b7ca..7777476325f9577a7890a21286712b9fdcf29d40 100644 (file)
@@ -118,6 +118,16 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    */
   private $tx = NULL;
 
+  /**
+   * Array of IDs created to support the test.
+   *
+   * e.g
+   * $this->ids = ['Contact' => ['descriptive_key' => $contactID], 'Group' => [$groupID]];
+   *
+   * @var array
+   */
+  protected $ids = [];
+
   /**
    * Class used for hooks during tests.
    *
index 818068d0363ab29d6678c56c0528a47a09e6b43d..bd178c7300ad7b085076341a6fbe9ebf78277a58 100644 (file)
@@ -1479,16 +1479,10 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * Verify successful update of individual contact.
    */
   public function testUpdateIndividualWithAll() {
-    // Insert a row in civicrm_contact creating individual contact.
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/contact_ind.xml'
-      )
-    );
+    $contactID = $this->individualCreate();
 
-    $params = array(
-      'id' => 23,
+    $params = [
+      'id' => $contactID,
       'first_name' => 'abcd',
       'contact_type' => 'Individual',
       'nick_name' => 'This is nickname first',
@@ -1500,8 +1494,7 @@ class api_v3_ContactTest extends CiviUnitTestCase {
       'external_identifier' => '1928837465',
       'image_URL' => 'http://some.url.com/image.jpg',
       'home_url' => 'http://www.example.org',
-
-    );
+    ];
 
     $this->callAPISuccess('Contact', 'Update', $params);
     $getResult = $this->callAPISuccess('Contact', 'Get', $params);
@@ -1510,50 +1503,28 @@ class api_v3_ContactTest extends CiviUnitTestCase {
     //reducing this test partially back to api v2 level to get it through
     unset($params['home_url']);
     foreach ($params as $key => $value) {
-      $this->assertEquals($value, $getResult['values'][23][$key]);
+      $this->assertEquals($value, $getResult['values'][$contactID][$key]);
     }
-    // Check updated civicrm_contact against expected.
-    $expected = $this->createXMLDataSet(
-      dirname(__FILE__) . '/dataset/contact_ind_upd.xml'
-    );
-    $actual = new PHPUnit_Extensions_Database_DataSet_QueryDataSet(
-      $this->_dbconn
-    );
-    $actual->addTable('civicrm_contact');
-    $expected->matches($actual);
   }
 
   /**
    * Verify successful update of organization contact.
+   *
+   * @throws \Exception
    */
   public function testUpdateOrganizationWithAll() {
-    // Insert a row in civicrm_contact creating organization contact
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/contact_org.xml'
-      )
-    );
+    $contactID = $this->organizationCreate();
 
-    $params = array(
-      'id' => 24,
+    $params = [
+      'id' => $contactID,
       'organization_name' => 'WebAccess India Pvt Ltd',
       'legal_name' => 'WebAccess',
       'sic_code' => 'ABC12DEF',
       'contact_type' => 'Organization',
-    );
+    ];
 
     $this->callAPISuccess('Contact', 'Update', $params);
-
-    // Check updated civicrm_contact against expected.
-    $expected = $this->createXMLDataSet(
-      dirname(__FILE__) . '/dataset/contact_org_upd.xml'
-    );
-    $actual = new PHPUnit_Extensions_Database_DataSet_QueryDataSet(
-      $this->_dbconn
-    );
-    $actual->addTable('civicrm_contact');
-    $expected->matches($actual);
+    $this->getAndCheck($params, $contactID, 'Contact');
   }
 
   /**
@@ -1629,30 +1600,24 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * Verify successful update of household contact.
    */
   public function testUpdateHouseholdWithAll() {
-    // Insert a row in civicrm_contact creating household contact
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/contact_hld.xml'
-      )
-    );
+    $contactID = $this->householdCreate();
 
-    $params = array(
-      'id' => 25,
+    $params = [
+      'id' => $contactID ,
       'household_name' => 'ABC household',
       'nick_name' => 'ABC House',
       'contact_type' => 'Household',
-    );
+    ];
 
     $result = $this->callAPISuccess('Contact', 'Update', $params);
 
-    $expected = array(
+    $expected = [
       'contact_type' => 'Household',
       'is_opt_out' => 0,
       'sort_name' => 'ABC household',
       'display_name' => 'ABC household',
       'nick_name' => 'ABC House',
-    );
+    ];
     $this->getAndCheck($expected, $result['id'], 'contact');
   }
 
@@ -1664,20 +1629,12 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * CRM-7645.
    */
   public function testUpdateCreateWithID() {
-    // Insert a row in civicrm_contact creating individual contact.
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/contact_ind.xml'
-      )
-    );
-
-    $params = array(
-      'id' => 23,
+    $contactID = $this->individualCreate();
+    $this->callAPISuccess('Contact', 'Update', [
+      'id' => $contactID,
       'first_name' => 'abcd',
       'last_name' => 'wxyz',
-    );
-    $this->callAPISuccess('Contact', 'Update', $params);
+    ]);
   }
 
   /**
@@ -1788,55 +1745,31 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * Test civicrm_contact_getquick() with empty name param.
    */
   public function testContactGetQuick() {
-    // Insert a row in civicrm_contact creating individual contact.
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/contact_17.xml'
-      )
-    );
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/email_contact_17.xml'
-      )
-    );
-    $params = array(
-      'name' => "T",
-    );
+    $contactID = $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact', 'email' => 'TestContact@example.com']);
 
-    $result = $this->callAPISuccess('contact', 'getquick', $params);
-    $this->assertEquals(17, $result['values'][0]['id']);
-    $params = array(
+    $result = $this->callAPISuccess('contact', 'getquick', ['name' => 'T']);
+    $this->assertEquals($contactID, $result['values'][0]['id']);
+    $params = [
       'name' => "TestContact@example.com",
       'field_name' => 'sort_name',
-    );
+    ];
     $result = $this->callAPISuccess('contact', 'getquick', $params);
-    $this->assertEquals(17, $result['values'][0]['id']);
+    $this->assertEquals($contactID, $result['values'][0]['id']);
   }
 
   /**
    * Test civicrm_contact_get) with empty params.
    */
   public function testContactGetEmptyParams() {
-    $this->callAPISuccess('contact', 'get', array());
+    $this->callAPISuccess('contact', 'get', []);
   }
 
   /**
    * Test civicrm_contact_get(,true) with no matches.
    */
   public function testContactGetOldParamsNoMatches() {
-    // Insert a row in civicrm_contact creating contact 17.
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/contact_17.xml'
-      )
-    );
-
-    $params = array(
-      'first_name' => 'Fred',
-    );
-    $result = $this->callAPISuccess('contact', 'get', $params);
+    $this->individualCreate();
+    $result = $this->callAPISuccess('contact', 'get', ['first_name' => 'Fred']);
     $this->assertEquals(0, $result['count']);
   }
 
@@ -1844,19 +1777,11 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * Test civicrm_contact_get(,true) with one match.
    */
   public function testContactGetOldParamsOneMatch() {
-    // Insert a row in civicrm_contact creating contact 17
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml'
-      )
-    );
+    $contactID = $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact']);
 
-    $params = array(
-      'first_name' => 'Test',
-    );
-    $result = $this->callAPISuccess('contact', 'get', $params);
-    $this->assertEquals(17, $result['values'][17]['contact_id']);
-    $this->assertEquals(17, $result['id']);
+    $result = $this->callAPISuccess('contact', 'get', ['first_name' => 'Test']);
+    $this->assertEquals($contactID, $result['values'][$contactID]['contact_id']);
+    $this->assertEquals($contactID, $result['id']);
   }
 
   /**
@@ -2488,11 +2413,11 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * Test TrueFalse format - I couldn't come up with an easy way to get an error on Get.
    */
   public function testContactGetFormatIsSuccessTrue() {
-    $this->createContactFromXML();
+    $contactID = $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact']);
     $description = "This demonstrates use of the 'format.is_success' param.
     This param causes only the success or otherwise of the function to be returned as BOOLEAN";
     $subfile = "FormatIsSuccess_True";
-    $params = array('id' => 17, 'format.is_success' => 1);
+    $params = ['id' => $contactID, 'format.is_success' => 1];
     $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
     $this->assertEquals(1, $result);
     $this->callAPISuccess('Contact', 'Delete', $params);
@@ -2562,25 +2487,24 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * Test Single Entity format.
    */
   public function testContactGetSingleEntityArray() {
-    $this->createContactFromXML();
+    $contactID = $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact']);
     $description = "This demonstrates use of the 'format.single_entity_array' param.
       This param causes the only contact to be returned as an array without the other levels.
       It will be ignored if there is not exactly 1 result";
     $subfile = "GetSingleContact";
-    $params = array('id' => 17);
-    $result = $this->callAPIAndDocument('Contact', 'GetSingle', $params, __FUNCTION__, __FILE__, $description, $subfile);
-    $this->assertEquals('Test Contact', $result['display_name']);
-    $this->callAPISuccess('Contact', 'Delete', $params);
+    $result = $this->callAPIAndDocument('Contact', 'GetSingle', ['id' => $contactID], __FUNCTION__, __FILE__, $description, $subfile);
+    $this->assertEquals('Mr. Test Contact II', $result['display_name']);
+    $this->callAPISuccess('Contact', 'Delete', ['id' => $contactID]);
   }
 
   /**
    * Test Single Entity format.
    */
   public function testContactGetFormatCountOnly() {
-    $this->createContactFromXML();
+    $contactID = $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact']);
     $description = "This demonstrates use of the 'getCount' action.
       This param causes the count of the only function to be returned as an integer.";
-    $params = array('id' => 17);
+    $params = ['id' => $contactID];
     $result = $this->callAPIAndDocument('Contact', 'GetCount', $params, __FUNCTION__, __FILE__, $description,
       'GetCountContact');
     $this->assertEquals('1', $result);
@@ -2591,14 +2515,14 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * Test id only format.
    */
   public function testContactGetFormatIDOnly() {
-    $this->createContactFromXML();
+    $contactID = $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact']);
     $description = "This demonstrates use of the 'format.id_only' param.
       This param causes the id of the only entity to be returned as an integer.
       It will be ignored if there is not exactly 1 result";
     $subfile = "FormatOnlyID";
-    $params = array('id' => 17, 'format.only_id' => 1);
+    $params = ['id' => $contactID, 'format.only_id' => 1];
     $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
-    $this->assertEquals('17', $result);
+    $this->assertEquals($contactID, $result);
     $this->callAPISuccess('Contact', 'Delete', $params);
   }
 
@@ -2606,14 +2530,14 @@ class api_v3_ContactTest extends CiviUnitTestCase {
    * Test id only format.
    */
   public function testContactGetFormatSingleValue() {
-    $this->createContactFromXML();
+    $contactID = $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact']);
     $description = "This demonstrates use of the 'format.single_value' param.
       This param causes only a single value of the only entity to be returned as an string.
       It will be ignored if there is not exactly 1 result";
     $subFile = "FormatSingleValue";
-    $params = array('id' => 17, 'return' => 'display_name');
+    $params = ['id' => $contactID, 'return' => 'display_name'];
     $result = $this->callAPIAndDocument('Contact', 'getvalue', $params, __FUNCTION__, __FILE__, $description, $subFile);
-    $this->assertEquals('Test Contact', $result);
+    $this->assertEquals('Mr. Test Contact II', $result);
     $this->callAPISuccess('Contact', 'Delete', $params);
   }
 
index 6b29420744fe9617ebda9ee74db9ac98c1271aaa..c99b72debb03e8ba75d5996a2b08689caac9d3ce 100644 (file)
@@ -31,7 +31,7 @@
  */
 class api_v3_CustomValueTest extends CiviUnitTestCase {
   protected $_apiversion = 3;
-  protected $ids;
+
   protected $optionGroup;
 
   public $DBResetRequired = FALSE;
index 30820f4862835813a0674b7a6ac864ba0878d7ce..5b00f456290c247a86ff2072bcc55a8d83fe7e89 100644 (file)
  * @group headless
  */
 class api_v3_GroupNestingTest extends CiviUnitTestCase {
-  protected $_apiversion;
 
   /**
    * Sets up the fixture, for example, opens a network connection.
+   *
    * This method is called before a test is executed.
    */
   protected function setUp() {
-    $this->_apiversion = 3;
     parent::setUp();
 
-    //  Insert a row in civicrm_group creating option group
-    //  from_email_address group
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/group_admins.xml'
-      )
-    );
-
-    //  Insert a row in civicrm_group creating option group
-    //  from_email_address group
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/group_subscribers.xml'
-      )
-    );
+    $this->ids['Group'] = [];
+    $this->ids['Group']['parent'] = $this->callAPISuccess('Group', 'create', [
+      'name' => 'Administrators',
+      'title' => 'Administrators',
+    ])['id'];
+    $this->ids['Group']['child'] = $this->callAPISuccess('Group', 'create', [
+      'name' => 'Newsletter Subscribers',
+      'title' => 'Newsletter Subscribers',
+      'parents' => $this->ids['Group']['parent'],
+    ])['id'];
+    $this->ids['Group']['child2'] = $this->callAPISuccess('Group', 'create', [
+      'name' => 'Another Newsletter Subscribers',
+      'title' => 'Another Newsletter Subscribers',
+      'parents' => $this->ids['Group']['parent'],
+    ])['id'];
+    $this->ids['Group']['child3'] = $this->callAPISuccess('Group', 'create', [
+      'name' => 'Super Special Newsletter Subscribers',
+      'title' => 'Super Special Newsletter Subscribers',
+      'parents' => [$this->ids['Group']['parent'], $this->ids['Group']['child']],
+    ])['id'];
 
-    //  Insert a row in civicrm_group creating option group
-    //  from_email_address group
-    $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    $op->execute($this->_dbconn,
-      $this->createXMLDataSet(
-        dirname(__FILE__) . '/dataset/group_nesting.xml'
-      )
-    );
   }
 
   /**
-   * Tears down the fixture, for example, closes a network connection.
+   * Tears down the fixture.
+   *
    * This method is called after a test is executed.
+   *
+   * @throws \Exception
    */
   protected function tearDown() {
-    //  Truncate the tables
     $this->quickCleanup(
-      array(
+      [
         'civicrm_group',
         'civicrm_group_nesting',
         'civicrm_contact',
         'civicrm_uf_group',
         'civicrm_uf_join',
         'civicrm_uf_match',
-      )
+      ]
     );
   }
 
-  ///////////////// civicrm_group_nesting_get methods
-
   /**
    * Test civicrm_group_nesting_get.
    */
   public function testGet() {
-    $params = array(
-      'parent_group_id' => 1,
-      'child_group_id' => 2,
-    );
+    $params = [
+      'parent_group_id' => $this->ids['Group']['parent'],
+      'child_group_id' => $this->ids['Group']['child'],
+    ];
 
     $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__, __FILE__);
-    // expected data loaded in setUp
-    $expected = array(
-      1 => array(
+    $expected = [
+      1 => [
         'id' => 1,
-        'child_group_id' => 2,
-        'parent_group_id' => 1,
-      ),
-    );
+        'child_group_id' => $this->ids['Group']['child'],
+        'parent_group_id' => $this->ids['Group']['parent'],
+      ],
+    ];
 
     $this->assertEquals($expected, $result['values']);
   }
 
   /**
-   * Test civicrm_group_nesting_get with just one
-   * param (child_group_id).
+   * Test civicrm_group_nesting_get with just one param (child_group_id).
    */
   public function testGetWithChildGroupId() {
-    $params = array(
-      'child_group_id' => 4,
-    );
+    $params = [
+      'child_group_id' => $this->ids['Group']['child3'],
+    ];
 
     $result = $this->callAPISuccess('group_nesting', 'get', $params);
 
     // expected data loaded in setUp
-    $expected = array(
-      3 => array(
+    $expected = [
+      3 => [
         'id' => 3,
-        'child_group_id' => 4,
-        'parent_group_id' => 1,
-      ),
-      4 => array(
+        'child_group_id' => $this->ids['Group']['child3'],
+        'parent_group_id' => $this->ids['Group']['parent'],
+      ],
+      4 => [
         'id' => 4,
-        'child_group_id' => 4,
-        'parent_group_id' => 2,
-      ),
-    );
+        'child_group_id' => $this->ids['Group']['child3'],
+        'parent_group_id' => $this->ids['Group']['child'],
+      ],
+    ];
 
     $this->assertEquals($expected, $result['values']);
   }
 
   /**
-   * Test civicrm_group_nesting_get with just one
-   * param (parent_group_id).
+   * Test civicrm_group_nesting_get with just one param (parent_group_id).
    */
   public function testGetWithParentGroupId() {
-    $params = array(
-      'parent_group_id' => 1,
-    );
+    $params = [
+      'parent_group_id' => $this->ids['Group']['parent'],
+    ];
 
     $result = $this->callAPISuccess('group_nesting', 'get', $params);
 
     // expected data loaded in setUp
-    $expected = array(
-      1 => array(
+    $expected = [
+      1 => [
         'id' => 1,
-        'child_group_id' => 2,
-        'parent_group_id' => 1,
-      ),
-      2 => array(
+        'child_group_id' => $this->ids['Group']['child'],
+        'parent_group_id' => $this->ids['Group']['parent'],
+      ],
+      2 => [
         'id' => 2,
-        'child_group_id' => 3,
-        'parent_group_id' => 1,
-      ),
-      3 => array(
+        'child_group_id' => $this->ids['Group']['child2'],
+        'parent_group_id' => $this->ids['Group']['parent'],
+      ],
+      3 => [
         'id' => 3,
-        'child_group_id' => 4,
-        'parent_group_id' => 1,
-      ),
-    );
+        'child_group_id' => $this->ids['Group']['child3'],
+        'parent_group_id' => $this->ids['Group']['parent'],
+      ],
+    ];
 
     $this->assertEquals($expected, $result['values']);
   }
 
   /**
    * Test civicrm_group_nesting_get for no records results.
+   *
    * Success expected. (these tests are of marginal value as are in syntax conformance,
    * don't copy & paste
    */
   public function testGetEmptyResults() {
-    $params = array(
-      'parent_group_id' => 1,
+    $params = [
+      'parent_group_id' => $this->ids['Group']['parent'],
       'child_group_id' => 700,
-    );
+    ];
     $this->callAPISuccess('group_nesting', 'get', $params);
   }
 
-  ///////////////// civicrm_group_nesting_create methods
-
   /**
    * Test civicrm_group_nesting_create.
+   *
+   * @throws \Exception
    */
   public function testCreate() {
-    // groups id=1 and id=2 loaded in setUp
-    $params = array(
-      'parent_group_id' => 1,
-      'child_group_id' => 3,
-    );
+    $params = [
+      'parent_group_id' => $this->ids['Group']['parent'],
+      'child_group_id' => $this->ids['Group']['child2'],
+    ];
 
     $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__, __FILE__);
     $this->callAPISuccessGetCount('GroupNesting', $params, 1);
@@ -206,16 +197,15 @@ class api_v3_GroupNestingTest extends CiviUnitTestCase {
    * Test civicrm_group_nesting_remove.
    */
   public function testDelete() {
-    // groups id=1 and id=2 loaded in setUp
-    $getparams = array(
-      'parent_group_id' => 1,
-      'child_group_id' => 2,
-    );
+    $params = [
+      'parent_group_id' => $this->ids['Group']['parent'],
+      'child_group_id' => $this->ids['Group']['child'],
+    ];
 
-    $result = $this->callAPISuccess('group_nesting', 'get', $getparams);
-    $params = array('id' => $result['id']);
+    $result = $this->callAPISuccess('group_nesting', 'get', $params);
+    $params = ['id' => $result['id']];
     $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__, __FILE__);
-    $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $getparams));
+    $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $params));
   }
 
   /**
@@ -224,7 +214,7 @@ class api_v3_GroupNestingTest extends CiviUnitTestCase {
    * Error expected.
    */
   public function testDeleteWithEmptyParams() {
-    $this->callAPIFailure('group_nesting', 'delete', array());
+    $this->callAPIFailure('group_nesting', 'delete', []);
   }
 
 }
diff --git a/tests/phpunit/api/v3/dataset/email_contact_17.xml b/tests/phpunit/api/v3/dataset/email_contact_17.xml
deleted file mode 100644 (file)
index 4239ae0..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--  $Id: email_contact_17.xml 30511 2010-11-03 11:36:36Z shot $  -->
-<dataset>
-  <table name="civicrm_email">
-    <column>id</column>
-    <column>contact_id</column>
-    <column>location_type_id</column>
-    <column>email</column>
-    <column>is_primary</column>
-    <column>is_billing</column>
-    <column>on_hold</column>
-    <column>is_bulkmail</column>
-    <column>hold_date</column>
-    <column>reset_date</column>
-    <row>
-      <value>100</value>  <!--  id  -->
-      <value>17</value> <!--  contact_id  -->
-      <value>1</value>  <!--  location_type_id  -->
-      <value>TestContact@example.com</value>  <!--  email  -->
-      <value>1</value>  <!--  is_primary  -->
-      <value>1</value>  <!--  is_billing  -->
-      <value>0</value>  <!--  on_hold  -->
-      <value>0</value>  <!--  is_bulkmail  -->
-      <null />          <!--  hold_date  -->
-      <null />          <!--  reset_date  -->
-    </row>
-  </table>
-</dataset>