-
-
Notifications
You must be signed in to change notification settings - Fork 814
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-18981 Add a 'validate' action to CiviCRM API #8624
Conversation
saurabhbatra96
commented
Jun 26, 2016
•
edited by civicrm-builder
Loading
edited by civicrm-builder
- CRM-18981: Add a 'validate' action to CiviCRM API
06e9af0
to
e055867
Compare
736c9b0
to
5ff2e62
Compare
5ff2e62
to
b7c239b
Compare
@eileenmcnaughton what do you imagine a test on this would look like? |
I think what we want is to test that we get multiple failure information so something like
It would be possible to do a syntax conformance test - but it may add little value over a couple of single entity tests. |
*/ | ||
function _civicrm_api3_validate($entity, $action, $params) { | ||
$errors = array(); | ||
$fields = civicrm_api($entity, 'getfields', array('version' => 3, 'action' => $action)); |
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.
is there a reason not to use civicrm_api3 here?
@eileenmcnaughton Going to add a test, but did some basic testing from the API explorer and this looks good! |
tests are showing a typo |
@@ -1538,6 +1538,87 @@ function _civicrm_api3_custom_data_get(&$returnArray, $checkPermission, $entity, | |||
} | |||
|
|||
/** | |||
* Used by the Validate API. |
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.
Super trivial - but the full whitespace standard would have a blank line here
This looks good. I still have an urge to have validate throw an exception (from which the errors can be extracted) rather than return success when it finds errors - but maybe I'm overly attached to exceptions @totten should probably talk me down from that. The second thing is that ideally one the validate api is all good we would alter the main api wrapper to call the validate api rather than having 2 paths & having the wrapper not have the benefit of a consolidated error. NB this does not have to be done as part of this PR - it's just where it would be good to take this |
3614a86
to
52265c3
Compare
Are the tests not written correctly? Can't seem to run them without running into "error in api call" while the API works just fine in the API explorer. Also, reminder to self: complete the comments before merging. |
These are coming out of the syntaxconformance tests - notably the getfields-title test goes through every entity-action combo to make sure the declared fields have titles |
* @param array $params | ||
*/ | ||
function _civicrm_api3_generic_validate_spec(&$params) { | ||
$params['action']['api.required'] = TRUE; |
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.
Add $params['action']['title'] = ts('blah blah');
for a huge test improvement
52265c3
to
51b8c5f
Compare
51b8c5f
to
6e4339c
Compare
'code' => "mandatory_missing", | ||
), | ||
); | ||
$this->assertEquals($validation['values'][0], $expectedOut); |
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.
$validation['values'][0]
- this nesting seems like a necessary evil. Cannot return the output in this dictionary format without using it:
{
"is_error": 0,
"version": 3,
"count": 1,
"id": 0,
"values": [
{
"contact_type": {
"message": "Mandatory key(s) missing from params array: contact_type",
"code": "mandatory_missing"
}
}
]
}
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.
hmm - should it be up one?
ie
$result['values']['contact_type'] => you would need to add field_name to the response array for when it's called with 'is_sequential'
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.
Up for a chat on mattermost?
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.
This is just how civicrm_api3_create_success
arranges the API output.
I could instead go for:
{
"is_error": 0,
"version": 3,
"count": 1,
"id": 0,
"values": [
{
"name": "total_amount",
"message": "Mandatory key(s) missing from params array: total_amount",
"code": "mandatory_missing"
},
{
"name": "contact_id",
"message": "Mandatory key(s) missing from params array: contact_id",
"code": "mandatory_missing"
}
]
}
Looks good to merge IMO. |