Skip to content
Snippets Groups Projects
Commit 0fe377f6 authored by colemanw's avatar colemanw
Browse files

CRM-14093 - add php & js unit tests for mutiple api call syntax

parent 3eb318ac
No related branches found
No related tags found
No related merge requests found
<?php
require_once 'CiviTest/CiviUnitTestCase.php';
class CRM_Utils_RestTest extends CiviUnitTestCase {
function get_info() {
return array(
'name' => 'Rest Test',
'description' => 'Test Rest Interface Utilities',
'group' => 'CiviCRM BAO Tests',
);
}
function setUp() {
parent::setUp();
}
function testProcessMultiple() {
$_SERVER['REQUEST_METHOD'] = 'POST';
$input = array(
'cow' => array(
'contact',
'create',
array(
'contact_type' => 'Individual',
'first_name' => 'Cow',
),
),
'sheep' => array(
'contact',
'create',
array(
'contact_type' => 'Individual',
'first_name' => 'Sheep',
),
),
);
$_REQUEST['json'] = json_encode($input);
$output = CRM_Utils_REST::processMultiple();
$this->assertGreaterThan(0, $output['cow']['id']);
$this->assertGreaterThan($output['cow']['id'], $output['sheep']['id']);
}
}
/* ------------ Test cases ------------ */
module('api single');
asyncTest("simple api call", function() {
CRM.api3('contact', 'get').done(function(result) {
equal(result.is_error, 0, 'contact get failed');
start();
});
});
module('api multiple');
asyncTest("array api calls", function() {
var params = [
['email', 'get', {email: '@'}],
['phone', 'get', {phone: '123'}]
];
CRM.api3(params).done(function(result) {
equal(result[0].is_error, 0, 'email get failed');
equal(result[1].is_error, 0, 'phone get failed');
start();
});
});
asyncTest("named api calls", function() {
var params = {
one: ['email', 'getoptions', {field: 'location_type_id'}],
two: ['phone', 'get', {field: 'phone_type_id'}]
};
CRM.api3(params).done(function(result) {
ok(result.one.count > 0, 'email getoptions failed');
ok(result.two.count > 0, 'phone getoptions failed');
start();
});
});
<?php
// CRM_Core_Resources::singleton()->addScriptFile(...);
// CRM_Core_Resources::singleton()->addStyleFile(...);
// CRM_Core_Resources::singleton()->addSetting(...);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment