aboutsummaryrefslogtreecommitdiff
path: root/engine/tests/services
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-20 11:39:20 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-20 11:39:20 +0000
commit2a577a42b48312f68c86c5fd7f80a7128605a599 (patch)
treeab5a27c102c900bc704a716bbc7e94aa894f582f /engine/tests/services
parent4fa9ce868793d07dc820b4515f0cdd0e6c88519b (diff)
downloadelgg-2a577a42b48312f68c86c5fd7f80a7128605a599.tar.gz
elgg-2a577a42b48312f68c86c5fd7f80a7128605a599.tar.bz2
more unit tests for REST api
git-svn-id: http://code.elgg.org/elgg/trunk@3566 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/tests/services')
-rw-r--r--engine/tests/services/api.php55
1 files changed, 48 insertions, 7 deletions
diff --git a/engine/tests/services/api.php b/engine/tests/services/api.php
index cf8a16bf5..4c3019538 100644
--- a/engine/tests/services/api.php
+++ b/engine/tests/services/api.php
@@ -18,6 +18,7 @@ class ElggCoreServicesApiTest extends ElggCoreUnitTest {
$API_METHODS = array();
}
+// expose_function
public function testExposeFunctionNoMethod() {
$this->expectException('InvalidParameterException');
expose_function();
@@ -51,7 +52,18 @@ class ElggCoreServicesApiTest extends ElggCoreUnitTest {
$this->assertTrue(expose_function('test', 'foo', $parameters));
$this->assertIdentical($method, $API_METHODS['test']);
}
+
+// unexpose_function
+ public function testUnexposeFunction() {
+ global $API_METHODS;
+
+ $this->registerFunction();
+ unexpose_function('test');
+ $this->assertIdentical(array(), $API_METHODS);
+ }
+
+// authenticate_method
public function testApiMethodNotImplemented() {
global $CONFIG;
@@ -60,6 +72,41 @@ class ElggCoreServicesApiTest extends ElggCoreUnitTest {
$this->assertIdentical(sprintf(elgg_echo('APIException:MethodCallNotImplemented'), 'bad.method'), $obj->api[0]->message);
}
+ public function testAuthenticateForApi() {
+ $this->registerFunction(true, false);
+
+ $this->expectException('APIException');
+ authenticate_method('test');
+ }
+
+ public function testAuthenticateForUser() {
+ $this->registerFunction(false, true);
+
+ $this->expectException('APIException');
+ authenticate_method('test');
+ }
+
+ public function testAuthenticateMethod() {
+ $this->registerFunction(false, false);
+ // anonymous with no user authentication
+ $this->assertTrue(authenticate_method('test'));
+ }
+
+// api_authenticate
+ public function testApiAuthenticate() {
+ $this->registerFunction(true, false);
+
+ $this->assertFalse(api_authenticate());
+ }
+
+// execute_method
+ public function testExecuteMethodNonCallable() {
+ $this->registerFunction();
+
+ $this->expectException('APIException');
+ execute_method('test');
+ }
+
public function testVerifyParameters() {
$this->registerFunction();
@@ -78,14 +125,8 @@ class ElggCoreServicesApiTest extends ElggCoreUnitTest {
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);
+ expose_function('test', 'foo', $parameters, '', 'GET', $api_auth, $user_auth);
}
}