CRM-14093 - add php & js unit tests for mutiple api call syntax
authorColeman Watts <coleman@civicrm.org>
Mon, 20 Jan 2014 04:31:53 +0000 (20:31 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 20 Jan 2014 05:17:33 +0000 (21:17 -0800)
tests/phpunit/CRM/Utils/RestTest.php [new file with mode: 0644]
tests/qunit/crm-api3/test.js [new file with mode: 0644]
tests/qunit/crm-api3/test.php [new file with mode: 0644]

diff --git a/tests/phpunit/CRM/Utils/RestTest.php b/tests/phpunit/CRM/Utils/RestTest.php
new file mode 100644 (file)
index 0000000..48aa05f
--- /dev/null
@@ -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 (file)
index 0000000..51b0154
--- /dev/null
@@ -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 (file)
index 0000000..7fab71c
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+// CRM_Core_Resources::singleton()->addScriptFile(...);
+// CRM_Core_Resources::singleton()->addStyleFile(...);
+// CRM_Core_Resources::singleton()->addSetting(...);