diff --git a/tests/phpunit/CRM/Utils/RestTest.php b/tests/phpunit/CRM/Utils/RestTest.php new file mode 100644 index 0000000000000000000000000000000000000000..48aa05f9d8603df4efcacbcf50a67594792fd405 --- /dev/null +++ b/tests/phpunit/CRM/Utils/RestTest.php @@ -0,0 +1,42 @@ +<?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']); + } + +} diff --git a/tests/qunit/crm-api3/test.js b/tests/qunit/crm-api3/test.js new file mode 100644 index 0000000000000000000000000000000000000000..51b0154895b3641062f4d43a87ece84c34048ff9 --- /dev/null +++ b/tests/qunit/crm-api3/test.js @@ -0,0 +1,36 @@ + +/* ------------ 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(); + }); +}); diff --git a/tests/qunit/crm-api3/test.php b/tests/qunit/crm-api3/test.php new file mode 100644 index 0000000000000000000000000000000000000000..7fab71c48585652505f463072231ce3d616efd83 --- /dev/null +++ b/tests/qunit/crm-api3/test.php @@ -0,0 +1,4 @@ +<?php +// CRM_Core_Resources::singleton()->addScriptFile(...); +// CRM_Core_Resources::singleton()->addStyleFile(...); +// CRM_Core_Resources::singleton()->addSetting(...);