Skip to content
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-16526 [needs-review] Financial ACL API tests #7818

Merged
merged 29 commits into from
Mar 16, 2016

Conversation

Edzelopez
Copy link
Contributor

@@ -44,8 +44,28 @@
* api result array
*/
function civicrm_api3_line_item_create($params) {
$params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params, TRUE);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this go in the BAO? the api should just be a wrapper for the BAO

@Edzelopez Edzelopez changed the title CRM-16526 [DO NOT MERGE - PR submitted to facilitate testing] Financial ACL API tests CRM-16526 [needs-review] Financial ACL API tests Feb 18, 2016
@eileenmcnaughton
Copy link
Contributor

Great to see the test!

What is worrying me about all this extra logic going into the api layer is that apart from being against our general principle of trying to put all logic in the BAO layer you are also creating future-you or someone like you work because api v4 will drop all of the api layer create logic and you will either have to move it to the BAO at that point or negotiate some exception on api v4.

Of course moving it to the BAO is unit tested but it would require at least some UI click around checks too to check nothing wierd is happening.

@Edzelopez
Copy link
Contributor Author

I agree @eileenmcnaughton, but I checked and the lineitem get API does not rely on the BAO. It just does a basic DAO get (). So unless we change that, we can't really modify the way the line items are being retrieved. Of course if there's anot her way this can be done please let me know :)

@eileenmcnaughton
Copy link
Contributor

I was looking more at create than get (which does have a BAO function to add things to).

The issue with get leveraging ACLs has recently been looked at by @colemanw and he can hopefully advise as to whether that approach is mature enough to add here.

I'm also kind of aware that you used an ACL approach that is more drupal-like than CiviCRM-like but I didn't dig into that side of it - I suspect the difference won't have much impact thought

@Edzelopez
Copy link
Contributor Author

Thanks for the suggestion @eileenmcnaughton
I've added the check to perform at BAO level for create rather than API, although I have set financial_type_id to be a required field for creating/editing a lineitem.

@@ -67,6 +69,12 @@ public static function create(&$params) {
if ($id) {
unset($params['entity_id'], $params['entity_table']);
}
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op);
if (!in_array($params['financial_type_id'], array_keys($types))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to only do this if check_permissions = TRUE

@Edzelopez
Copy link
Contributor Author

Jenkins, retest this please

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
… for line item

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
…n if even one is non-permissioned

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
…sioned line items for contribution

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
…PI for create

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
Edzelopez and others added 6 commits February 22, 2016 23:41
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
… added only if ACL is enabled

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
… for lineitems

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
@Edzelopez
Copy link
Contributor Author

Jenkins, retest this please

…tead of logic in API

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
@pradpnayak
Copy link
Contributor

Hi @eileenmcnaughton ,

We are having an issue with getting Jenkins to pass.
When running all tests for api_v3_FinancialTypeACLTest via PHPUnit on our local machines, we get a successful assertion after the tests have finished completion. Unfortunately, this is not the same when we try to merge the PR to master and let Jenkins test the API test there. Such can be seen from here.

We were wondering if you have any idea what we are doing wrong here and would very much appreciate ideas as to how to make sure that there is consistency of our tests between our local machine and Jenkins.

@eileenmcnaughton
Copy link
Contributor

See if it works when running api_v3_AllTests - probably some other test is leaving something behind that is messing with your test so it fails when they all run but not with only some. If it does fail there is a clever way to run selectively but I just delete around half the test classes locally & re-run until I've homing in on the clashing class

----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526
@Edzelopez
Copy link
Contributor Author

@eileenmcnaughton you were right, there was a caching issue with one of the static variables that was failing when run with the other tests. I've fixed it now.

@JoeMurray
Copy link
Contributor

@eileenmcnaughton would you be able to merge this for us? It's been waiting for over a week.

eileenmcnaughton added a commit that referenced this pull request Mar 16, 2016
CRM-16526 [needs-review] Financial ACL API tests
@eileenmcnaughton eileenmcnaughton merged commit c067566 into civicrm:master Mar 16, 2016
@pradpnayak pradpnayak deleted the CRM-16526-1 branch April 27, 2016 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants