aboutsummaryrefslogtreecommitdiff
path: root/engine/tests/services
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-19 11:59:44 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-19 11:59:44 +0000
commit985fad83ae06027c9ba92915b6f253815e7537cc (patch)
treeed32fd8354b73c3484b4ab77cb1ebe8103631c0a /engine/tests/services
parent6ed8a8dd29c699c1ff345f9827f5f685c15e85e6 (diff)
downloadelgg-985fad83ae06027c9ba92915b6f253815e7537cc.tar.gz
elgg-985fad83ae06027c9ba92915b6f253815e7537cc.tar.bz2
first version of new REST api
git-svn-id: http://code.elgg.org/elgg/trunk@3562 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/tests/services')
-rw-r--r--engine/tests/services/api.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/engine/tests/services/api.php b/engine/tests/services/api.php
new file mode 100644
index 000000000..cf8a16bf5
--- /dev/null
+++ b/engine/tests/services/api.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * Elgg Test Services - General API and REST
+ *
+ * @package Elgg
+ * @subpackage Test
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+class ElggCoreServicesApiTest extends ElggCoreUnitTest {
+
+ /**
+ * Called after each test method.
+ */
+ public function tearDown() {
+ global $API_METHODS;
+ $this->swallowErrors();
+ $API_METHODS = array();
+ }
+
+ public function testExposeFunctionNoMethod() {
+ $this->expectException('InvalidParameterException');
+ expose_function();
+ }
+
+ public function testExposeFunctionNoFunction() {
+ $this->expectException('InvalidParameterException');
+ expose_function('test');
+ }
+
+ public function testExposeFunctionBadParameters() {
+ $this->expectException('InvalidParameterException');
+ expose_function('test', 'test', 'BAD');
+ }
+
+ public function testExposeFunctionBadHttpMethod() {
+ $this->expectException('InvalidParameterException');
+ expose_function('test', 'test', null, '', 'BAD');
+ }
+
+ public function testExposeFunctionSuccess() {
+ global $API_METHODS;
+ $parameters = array('param1' => array('type' => 'int', 'required' => true));
+ $method['function'] = 'foo';
+ $method['parameters'] = $parameters;
+ $method['call_method'] = 'GET';
+ $method['description'] = '';
+ $method['require_api_auth'] = false;
+ $method['require_user_auth'] = false;
+
+ $this->assertTrue(expose_function('test', 'foo', $parameters));
+ $this->assertIdentical($method, $API_METHODS['test']);
+ }
+
+ public function testApiMethodNotImplemented() {
+ global $CONFIG;
+
+ $results = send_api_get_call($CONFIG->wwwroot . 'pg/api/rest/json/', array('method' => 'bad.method'));
+ $obj = json_decode($results);
+ $this->assertIdentical(sprintf(elgg_echo('APIException:MethodCallNotImplemented'), 'bad.method'), $obj->api[0]->message);
+ }
+
+ public function testVerifyParameters() {
+ $this->registerFunction();
+
+ $parameters = array('param1' => 0);
+ $this->assertTrue(verify_parameters('test', $parameters));
+
+ $parameters = array('param2' => true);
+ $this->expectException('APIException');
+ $this->assertTrue(verify_parameters('test', $parameters));
+ }
+
+ public function testserialise_parameters() {
+
+ }
+
+ protected function registerFunction($api_auth = false, $user_auth = false) {
+ $parameters = array('param1' => array('type' => 'int', 'required' => true),
+ 'param2' => array('type' => 'bool', 'required' => false), );
+ $method['function'] = 'foo';
+ $method['parameters'] = $parameters;
+ $method['call_method'] = 'GET';
+ $method['description'] = '';
+ $method['require_api_auth'] = $api_auth;
+ $method['require_user_auth'] = $user_auth;
+
+ expose_function('test', 'foo', $parameters);
+ }
+
+}