From 363544d7eb83cb5c5fae4dd23c54c65c1450fdb7 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 16 Feb 2017 15:45:47 +1300 Subject: [PATCH] [NFC] towards CRM-19490 - code cleanup only. Removing unused variables & a bit of cruft in the test --- CRM/Activity/Form/Task/Batch.php | 6 +- CRM/Batch/Form/Entry.php | 4 +- CRM/Contribute/Form/Task/Batch.php | 1 - CRM/Core/BAO/UFGroup.php | 4 +- templates/CRM/Batch/Form/Entry.js | 1 + tests/phpunit/api/v3/ProfileTest.php | 84 ++++++++++------------------ 6 files changed, 38 insertions(+), 62 deletions(-) diff --git a/CRM/Activity/Form/Task/Batch.php b/CRM/Activity/Form/Task/Batch.php index 5e0598cb96..980ef2c808 100644 --- a/CRM/Activity/Form/Task/Batch.php +++ b/CRM/Activity/Form/Task/Batch.php @@ -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'); } diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index dd61256132..60e967723d 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -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, diff --git a/CRM/Contribute/Form/Task/Batch.php b/CRM/Contribute/Form/Task/Batch.php index ca6c15eeb9..f1b47a4375 100644 --- a/CRM/Contribute/Form/Task/Batch.php +++ b/CRM/Contribute/Form/Task/Batch.php @@ -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'); } diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 392905e8b8..510f38a6bd 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -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', diff --git a/templates/CRM/Batch/Form/Entry.js b/templates/CRM/Batch/Form/Entry.js index 23bf05aef9..89fcda8db4 100644 --- a/templates/CRM/Batch/Form/Entry.js +++ b/templates/CRM/Batch/Form/Entry.js @@ -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 diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index 622491574a..4c79b94dc1 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -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( -- 2.25.1