Skip to content

Commit

Permalink
Merge pull request civicrm#9843 from eileenmcnaughton/test_clean
Browse files Browse the repository at this point in the history
[NFC] towards CRM-19490 - code cleanup only.
  • Loading branch information
eileenmcnaughton authored Feb 16, 2017
2 parents c377f54 + fe8bc54 commit ab14549
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 62 deletions.
6 changes: 2 additions & 4 deletions CRM/Activity/Form/Task/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function preProcess() {
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;
}
Expand Down Expand Up @@ -138,7 +138,6 @@ public function buildQuickForm() {

$this->assign('profileTitle', $this->_title);
$this->assign('componentIds', $this->_activityHolderIds);
$fileFieldExists = FALSE;

// Load all campaigns.
if (array_key_exists('activity_campaign_id', $this->_fields)) {
Expand Down Expand Up @@ -197,7 +196,6 @@ public function setDefaultValues() {

$defaults = array();
foreach ($this->_activityHolderIds as $activityId) {
$details[$activityId] = array();
CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $activityId, 'Activity');
}

Expand Down
4 changes: 1 addition & 3 deletions CRM/Batch/Form/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,7 @@ public function setDefaultValues() {
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,
Expand Down
1 change: 0 additions & 1 deletion CRM/Contribute/Form/Task/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ public function setDefaultValues() {

$defaults = array();
foreach ($this->_contributionIds as $contributionId) {
$details[$contributionId] = array();
CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $contributionId, 'Contribute');
}

Expand Down
4 changes: 3 additions & 1 deletion CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ public static function getValues(
'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);
}
Expand Down Expand Up @@ -2383,7 +2384,7 @@ public static function setProfileDefaults(
$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
Expand Down Expand Up @@ -3254,6 +3255,7 @@ public static function setComponentDefaults(&$fields, $componentId, $component,
}

$formattedGroupTree = array();
// @todo - as we put these on datepicker they need to be removed from here.
$dateTimeFields = array(
'participant_register_date',
'activity_date_time',
Expand Down
1 change: 1 addition & 0 deletions templates/CRM/Batch/Form/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 31 additions & 53 deletions tests/phpunit/api/v3/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,11 @@ public function tearDown() {
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'
);
}
Expand All @@ -82,20 +77,16 @@ public function testProfileGetWithoutProfileId() {
* 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,
Expand All @@ -107,9 +98,9 @@ public function testProfileGet() {
}

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,
Expand Down Expand Up @@ -145,8 +136,6 @@ public function testProfileGetBillingUseIsBillingLocation() {
'contact_id' => $contactId,
));

$expected = current($individual);

$params = array(
'profile_id' => array($this->_profileID, 1, 'Billing'),
'contact_id' => $contactId,
Expand Down Expand Up @@ -184,14 +173,12 @@ public function testProfileGetMultipleHasBillingLocation() {
'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',
Expand Down Expand Up @@ -235,22 +222,19 @@ public function testProfileGetBillingEmptyContact() {
* 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).');
}

/**
Expand Down Expand Up @@ -278,12 +262,10 @@ public function testContactActivityGetWrongActivityType() {

$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.');
}

/**
Expand All @@ -295,7 +277,7 @@ public function testContactActivityGetSuccess() {
$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}"
);
}
}
Expand Down Expand Up @@ -364,15 +346,14 @@ public function testGetFieldsAllProfiles() {
$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',
)
);
}
}
/////////////// test $this->callAPISuccess3_profile_set //////////////////

/**
* Check Without ProfileId.
Expand All @@ -381,7 +362,7 @@ public function testProfileSubmitWithoutProfileId() {
$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'
);
}
Expand Down Expand Up @@ -443,7 +424,7 @@ public function testProfileSubmit() {
'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,
Expand Down Expand Up @@ -584,7 +565,7 @@ public function testContactActivitySubmitWrongActivityId() {
*/
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();

Expand All @@ -608,15 +589,15 @@ public function testContactActivitySubmitWrongActivityType() {

$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.');
}

/**
* Check contact activity profile with success.
*/
public function testContactActivitySubmitSuccess() {
list($params, $expected) = $this->_createContactWithActivity();
list($params) = $this->_createContactWithActivity();

$updateParams = array(
'first_name' => 'abc2',
Expand All @@ -633,7 +614,7 @@ public function testContactActivitySubmitSuccess() {
$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}"
);
}
}
Expand All @@ -645,7 +626,7 @@ public function testProfileApplyWithoutProfileId() {
$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');
}

Expand All @@ -657,16 +638,16 @@ public function testProfileApplyInvalidProfileId() {
'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,
Expand Down Expand Up @@ -810,7 +791,7 @@ public function _createContactWithActivity() {
$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(
Expand Down Expand Up @@ -856,12 +837,9 @@ public function _createContactWithActivity() {
* 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(
Expand Down

0 comments on commit ab14549

Please sign in to comment.