-
-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRM-18502 - Fix payment reminder activity creation #8309
Conversation
@@ -1079,13 +1079,14 @@ public static function updatePledgeStatus($params) { | |||
$activityType, | |||
'name' | |||
), | |||
'activity_date_time' => CRM_Utils_Date::isoToMysql($now), | |||
'activity_date_time' => CRM_Utils_Date::isoToMysql(date('YmdHis')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you are calling the api to create this it could be simplified to
'activity_date_time' => 'now',
or simply omit the line since I am pretty sure that's the default for new activities via the api.
Have I ever tried to sell you on the joys of writing unit tests....? |
I haven't gotten the sales pitch, but I'm listening. Should there be a unit test for this PR? |
In a perfect world there would be a test on every pr... We'll never get to 100% - but tests are your guarantee that what you fix stays fixed. There are no existing tests on that function :-( I just added a test for another job here https://github.com/civicrm/civicrm-core/pull/8293/files#diff-a95d6214aaf5b8f4e1cdb78f8b95d676R300 (& am building up tests on top of that that will increase the coverage from there) |
In terms of getting started - there are a few resources - generally starting from buildkit is easiest - this stuff is still relevant https://wiki.civicrm.org/confluence/display/CRMDOC/Testing#Testing-PHPunittests - although I think there are a few more methods available now too. |
Marty as Release Manager this month, I'm trying to recruit people to help pare down the backlog of almost 100 PRs, some going back to last summer. I'm wondering if you would be able to help QA another PR if I got someone to QA this PR? |
Tested and it works fine. @eileenmcnaughton @mjwright is there any followup pr for unit test or this PR can be merged for now? |
Jenkin, test this please |
@PalanteJon could you help @mjwright get started with a test for this? |
@mjwright I'm going to try to help! That said, I've only written API tests - and while this is API-related, the API is working fine. That said, I've been studying up on unit tests, so I think I understand what's needed here. So this is us learning together. The unit test should be testing the function that's affected. Unfortunately, test as isIn your dev environment, navigate to /**
* Test that pledges create an activity.
*/
public function testCreatePledgeActivity() {
// These are the wrong params - put whatever legit params make sense here to pass to updatePledgeStatus! If you don't know, add a debug statement to dump params at the top of updatePledgeStatus to screen and/or log, then run manually. Then copy/paste those params.
$params = array(
'contact_id' => $this->_contactId,
'frequency_unit' => 'month',
'frequency_interval' => 1,
etc.
);
// Now call the function!
CRM_Core_BAO_Pledge::updatePledgeStatus($params);
// Now test that the Activity was created.
$this->callAPISuccess('Activity', 'get', array(
'subject' => $params['subject'],
'source_contact_id' => $params['contactId'],
'source_record_id' => $params['paymentId'],
'assignee_contact_id' => $params['contactId'],
'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type',
'Pledge Reminder',
'name'
),
));
} You can run the test with:
Alternative approach: refactor
If you've refactored correctly, everything should work exactly as it had before you changed it. But now you can write a test that tests ONLY those 20 lines, not the 300+ lines of the entire function. That prevents the test failing if something breaks elsewhere in that function. Hope that this is enough to get you started! Let me know if you have any other questions - you can find me on chat.civicrm.org as @JungleBird. |
nice write-up @PalanteJon |
Great stuff @PalanteJon - thanks! For some general background see https://wiki.civicrm.org/confluence/display/CRM/Writing+a+PHPUnit+testcase+HOWTO and even https://wiki.civicrm.org/confluence/display/CRMDOC/Testing#Testing-PHPunittests @eileenmcnaughton would you see a place to add some of this 'how to' guidelines stuff in terms of refactoring and even directories? |
@mjwright are you going to update this PR or create a new, to add a unit test for it ? |
@monishdeb This isn't my PR, so no. I think you meant to ask @mjwright. |
Sorry my bad :( edited. |
I think you should merge this - I am very keen to help @mjwright to get his first unit test written - but lets not keep this one stuck because it is a clear cut improvement |
Call to civicrm_api() fails due to missing "version" parameter, but is undetected due to test for is_a 'CRM_Core_Error'. Changed to use civicrm_api3() and properly test result for civicrm_error.