From 0fe377f66242c0de1c394da63920f3545b374ae4 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 19 Jan 2014 20:31:53 -0800 Subject: [PATCH] CRM-14093 - add php & js unit tests for mutiple api call syntax --- tests/phpunit/CRM/Utils/RestTest.php | 42 ++++++++++++++++++++++++++++ tests/qunit/crm-api3/test.js | 36 ++++++++++++++++++++++++ tests/qunit/crm-api3/test.php | 4 +++ 3 files changed, 82 insertions(+) create mode 100644 tests/phpunit/CRM/Utils/RestTest.php create mode 100644 tests/qunit/crm-api3/test.js create mode 100644 tests/qunit/crm-api3/test.php diff --git a/tests/phpunit/CRM/Utils/RestTest.php b/tests/phpunit/CRM/Utils/RestTest.php new file mode 100644 index 0000000000..48aa05f9d8 --- /dev/null +++ b/tests/phpunit/CRM/Utils/RestTest.php @@ -0,0 +1,42 @@ + '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 0000000000..51b0154895 --- /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 0000000000..7fab71c485 --- /dev/null +++ b/tests/qunit/crm-api3/test.php @@ -0,0 +1,4 @@ +addScriptFile(...); +// CRM_Core_Resources::singleton()->addStyleFile(...); +// CRM_Core_Resources::singleton()->addSetting(...); -- 2.25.1