[NFC] towards CRM-19490 - code cleanup only.
authoreileen <emcnaughton@wikimedia.org>
Thu, 16 Feb 2017 02:45:47 +0000 (15:45 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 16 Feb 2017 02:45:47 +0000 (15:45 +1300)
Removing unused variables & a bit of cruft in the test

CRM/Activity/Form/Task/Batch.php
CRM/Batch/Form/Entry.php
CRM/Contribute/Form/Task/Batch.php
CRM/Core/BAO/UFGroup.php
templates/CRM/Batch/Form/Entry.js
tests/phpunit/api/v3/ProfileTest.php

index 5e0598cb96abc728963f51a711079c713143d4dd..980ef2c808aa8529b52717941ffada57255c28c4 100644 (file)
@@ -78,8 +78,8 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
     if (!empty($contactDetails)) {
       foreach ($contactDetails as $key => $value) {
         $assignee = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($key);
-        foreach ($assignee as $keys => $values) {
-          $assigneeContact[] = CRM_Contact_BAO_Contact::displayname($values);
+        foreach ($assignee as $values) {
+          $assigneeContact[] = CRM_Contact_BAO_Contact::displayName($values);
         }
         $contactDetails[$key]['assignee_display_name'] = !empty($assigneeContact) ? implode(';', $assigneeContact) : NULL;
       }
@@ -138,7 +138,6 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
 
     $this->assign('profileTitle', $this->_title);
     $this->assign('componentIds', $this->_activityHolderIds);
-    $fileFieldExists = FALSE;
 
     // Load all campaigns.
     if (array_key_exists('activity_campaign_id', $this->_fields)) {
@@ -197,7 +196,6 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
 
     $defaults = array();
     foreach ($this->_activityHolderIds as $activityId) {
-      $details[$activityId] = array();
       CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $activityId, 'Activity');
     }
 
index dd61256132df7041de1b6823cad11d4b318decc6..60e967723ddb5b7caa45597acd3e1f25454fcbfc 100644 (file)
@@ -382,9 +382,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
     if ($this->_action & CRM_Core_Action::ADD) {
       list($currentDate, $currentTime) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
 
-      //get all status
-      $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
-      $completeStatus = array_search('Completed', $allStatus);
+      $completeStatus = CRM_Contribute_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
       $specialFields = array(
         'join_date' => $currentDate,
         'receive_date' => $currentDate,
index ca6c15eeb99ec373eb9653b326663f9a007167ba..f1b47a4375ebb2e1518c97cc4fcf1a9ba43050ed 100644 (file)
@@ -187,7 +187,6 @@ class CRM_Contribute_Form_Task_Batch extends CRM_Contribute_Form_Task {
 
     $defaults = array();
     foreach ($this->_contributionIds as $contributionId) {
-      $details[$contributionId] = array();
       CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $contributionId, 'Contribute');
     }
 
index 392905e8b86f1ba445a1dd19e66bfbbf7ae0d18f..510f38a6bd0fa56f71d3b26f2c94d48ff29ae96a 100644 (file)
@@ -1197,6 +1197,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
               'membership_end_date',
               'join_date',
             ))) {
+              // @todo this set should be determined from metadata, not hard-coded.
               $values[$index] = CRM_Utils_Date::customFormat($details->$name);
               $params[$index] = CRM_Utils_Date::isoToMysql($details->$name);
             }
@@ -2383,7 +2384,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
             $defaults[$fldName] = $details['worldregion_id'];
           }
           elseif ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) {
-            //fix for custom fields
+            // @todo retrieving the custom fields here seems obsolete - $field holds more data for the fields.
             $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $details));
 
             // hack to add custom data for components
@@ -3254,6 +3255,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     }
 
     $formattedGroupTree = array();
+    // @todo - as we put these on datepicker they need to be removed from here.
     $dateTimeFields = array(
       'participant_register_date',
       'activity_date_time',
index 23bf05aef91fc5a6d28fd5afd781384bade9d809..89fcda8db49bf648e2fd1ad93b2f964b6b460a26 100644 (file)
@@ -171,6 +171,7 @@ function checkColumns(parentRow) {
 
   parentRow.find('div .required').each(function () {
     //special case to handle contact autocomplete select
+    // @todo WHY OH WHY is this duplicated on the tpl file?
     var fieldId = cj(this).attr('id');
     if (fieldId.substring(0, 16) == 'primary_contact_') {
       // if display value is set then make sure we also check if contact id is set
index 622491574a7116b1f80763e46f1ed77d9c442399..4c79b94dc13fc4dd277ff6969822636f144af9d7 100644 (file)
@@ -64,16 +64,11 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
   }
 
-  ////////////// test $this->callAPISuccess3_profile_get //////////////////
-
   /**
    * Check Without ProfileId.
    */
   public function testProfileGetWithoutProfileId() {
-    $params = array(
-      'contact_id' => 1,
-    );
-    $this->callAPIFailure('profile', 'get', $params,
+    $this->callAPIFailure('profile', 'get', array('contact_id' => 1),
       'Mandatory key(s) missing from params array: profile_id'
     );
   }
@@ -82,20 +77,16 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    * Check with no invalid profile Id.
    */
   public function testProfileGetInvalidProfileId() {
-    $params = array(
-      'contact_id' => 1,
-      'profile_id' => 1000,
-    );
-    $result = $this->callAPIFailure('profile', 'get', $params);
+    $this->callAPIFailure('profile', 'get', array('contact_id' => 1, 'profile_id' => 1000));
   }
 
   /**
    * Check with success.
    */
   public function testProfileGet() {
-    $pofileFieldValues = $this->_createIndividualContact();
-    $expected = current($pofileFieldValues);
-    $contactId = key($pofileFieldValues);
+    $profileFieldValues = $this->_createIndividualContact();
+    $expected = current($profileFieldValues);
+    $contactId = key($profileFieldValues);
     $params = array(
       'profile_id' => $this->_profileID,
       'contact_id' => $contactId,
@@ -107,9 +98,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
   }
 
   public function testProfileGetMultiple() {
-    $pofileFieldValues = $this->_createIndividualContact();
-    $expected = current($pofileFieldValues);
-    $contactId = key($pofileFieldValues);
+    $profileFieldValues = $this->_createIndividualContact();
+    $expected = current($profileFieldValues);
+    $contactId = key($profileFieldValues);
     $params = array(
       'profile_id' => array($this->_profileID, 1, 'Billing'),
       'contact_id' => $contactId,
@@ -145,8 +136,6 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ));
 
-    $expected = current($individual);
-
     $params = array(
       'profile_id' => array($this->_profileID, 1, 'Billing'),
       'contact_id' => $contactId,
@@ -184,14 +173,12 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
         'is_billing' => 1,
       ));
 
-    $expected = current($individual);
-
     $params = array(
       'profile_id' => array($this->_profileID, 1, 'Billing'),
       'contact_id' => $contactId,
     );
 
-    $result = $this->callAPISuccess('profile', 'get', $params, __FUNCTION__, __FILE__);
+    $result = $this->callAPISuccess('profile', 'get', $params);
     $this->assertEquals('abc1', $result['values'][1]['first_name']);
     $this->assertEquals($result['values']['Billing'], array(
       'billing_first_name' => 'abc1',
@@ -235,22 +222,19 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    * Check contact activity profile without activity id.
    */
   public function testContactActivityGetWithoutActivityId() {
-    list($params, $expected) = $this->_createContactWithActivity();
+    list($params) = $this->_createContactWithActivity();
 
     unset($params['activity_id']);
-    $result = $this->callAPIFailure('profile', 'get', $params,
-      'Mandatory key(s) missing from params array: activity_id');
+    $this->callAPIFailure('profile', 'get', $params, 'Mandatory key(s) missing from params array: activity_id');
   }
 
   /**
    * Check contact activity profile wrong activity id.
    */
   public function testContactActivityGetWrongActivityId() {
-    list($params, $expected) = $this->_createContactWithActivity();
-
+    list($params) = $this->_createContactWithActivity();
     $params['activity_id'] = 100001;
-    $result = $this->callAPIFailure('profile', 'get', $params,
-      'Invalid Activity Id (aid).');
+    $this->callAPIFailure('profile', 'get', $params, 'Invalid Activity Id (aid).');
   }
 
   /**
@@ -278,12 +262,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
 
     $activityValues = array_pop($activity['values']);
 
-    list($params, $expected) = $this->_createContactWithActivity();
+    list($params) = $this->_createContactWithActivity();
 
     $params['activity_id'] = $activityValues['id'];
-    $result = $this->callAPIFailure('profile', 'get', $params,
-      'This activity cannot be edited or viewed via this profile.'
-    );
+    $this->callAPIFailure('profile', 'get', $params, 'This activity cannot be edited or viewed via this profile.');
   }
 
   /**
@@ -295,7 +277,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $result = $this->callAPISuccess('profile', 'get', $params);
 
     foreach ($expected as $profileField => $value) {
-      $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
+      $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), " error message: " . "missing/mismatching value for {$profileField}"
       );
     }
   }
@@ -364,7 +346,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
     $profileIDs = array_keys($result['values']);
     foreach ($profileIDs as $profileID) {
-      $result = $this->callAPISuccess('profile', 'getfields', array(
+      $this->callAPISuccess('profile', 'getfields', array(
           'action' => 'submit',
           'profile_id' => $profileID,
           'get_options' => 'all',
@@ -372,7 +354,6 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
       );
     }
   }
-  /////////////// test $this->callAPISuccess3_profile_set //////////////////
 
   /**
    * Check Without ProfileId.
@@ -381,7 +362,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $params = array(
       'contact_id' => 1,
     );
-    $result = $this->callAPIFailure('profile', 'submit', $params,
+    $this->callAPIFailure('profile', 'submit', $params,
       'Mandatory key(s) missing from params array: profile_id'
     );
   }
@@ -443,7 +424,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ), $updateParams);
 
-    $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__, __FILE__);
+    $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__, __FILE__);
 
     $getParams = array(
       'profile_id' => $this->_profileID,
@@ -584,7 +565,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    */
   public function testContactActivitySubmitWrongActivityType() {
     //flush cache by calling with reset
-    $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
+    CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
 
     $sourceContactId = $this->householdCreate();
 
@@ -608,7 +589,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
 
     $params = array_merge($params, $expected);
     $params['activity_id'] = $activityValues['id'];
-    $result = $this->callAPIFailure('profile', 'submit', $params,
+    $this->callAPIFailure('profile', 'submit', $params,
       'This activity cannot be edited or viewed via this profile.');
   }
 
@@ -616,7 +597,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    * Check contact activity profile with success.
    */
   public function testContactActivitySubmitSuccess() {
-    list($params, $expected) = $this->_createContactWithActivity();
+    list($params) = $this->_createContactWithActivity();
 
     $updateParams = array(
       'first_name' => 'abc2',
@@ -633,7 +614,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $result = $this->callAPISuccess('profile', 'get', $params);
 
     foreach ($updateParams as $profileField => $value) {
-      $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}"
+      $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), " error message: " . "missing/mismatching value for {$profileField}"
       );
     }
   }
@@ -645,7 +626,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $params = array(
       'contact_id' => 1,
     );
-    $result = $this->callAPIFailure('profile', 'apply', $params,
+    $this->callAPIFailure('profile', 'apply', $params,
       'Mandatory key(s) missing from params array: profile_id');
   }
 
@@ -657,16 +638,16 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
       'contact_id' => 1,
       'profile_id' => 1000,
     );
-    $result = $this->callAPIFailure('profile', 'apply', $params);
+    $this->callAPIFailure('profile', 'apply', $params);
   }
 
   /**
    * Check with success.
    */
   public function testProfileApply() {
-    $pofileFieldValues = $this->_createIndividualContact();
-    current($pofileFieldValues);
-    $contactId = key($pofileFieldValues);
+    $profileFieldValues = $this->_createIndividualContact();
+    current($profileFieldValues);
+    $contactId = key($profileFieldValues);
 
     $params = array(
       'profile_id' => $this->_profileID,
@@ -810,7 +791,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $keys = array_keys($contact['values']);
     $contactId = array_pop($keys);
 
-    $this->assertEquals(0, $contact['values'][$contactId]['api.address.create']['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact['values'][$contactId]['api.address.create'])
+    $this->assertEquals(0, $contact['values'][$contactId]['api.address.create']['is_error'], " error message: " . CRM_Utils_Array::value('error_message', $contact['values'][$contactId]['api.address.create'])
     );
 
     $activityParams = array(
@@ -856,12 +837,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
    * Create a profile.
    */
   public function _createIndividualProfile() {
-
-    // creating these via the api as we want to utilise & test the flushing of caches when fields created
-    // via the api
-
     $ufGroupParams = array(
-      'group_type' => 'Individual,Contact', // really we should remove this & test the ufField create sets it
+      'group_type' => 'Individual,Contact',
+      // really we should remove this & test the ufField create sets it
       'name' => 'test_individual_contact_profile',
       'title' => 'Flat Coffee',
       'api.uf_field.create' => array(