--- /dev/null
+<?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']);
+ }
+
+}
--- /dev/null
+
+/* ------------ 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();
+ });
+});