$API_METHODS = array();\r
}\r
\r
+// expose_function\r
public function testExposeFunctionNoMethod() {\r
$this->expectException('InvalidParameterException');\r
expose_function();\r
$this->assertTrue(expose_function('test', 'foo', $parameters));\r
$this->assertIdentical($method, $API_METHODS['test']);\r
}\r
+\r
+// unexpose_function\r
+ public function testUnexposeFunction() {\r
+ global $API_METHODS;\r
+ \r
+ $this->registerFunction();\r
\r
+ unexpose_function('test');\r
+ $this->assertIdentical(array(), $API_METHODS);\r
+ } \r
+\r
+// authenticate_method\r
public function testApiMethodNotImplemented() {\r
global $CONFIG;\r
\r
$this->assertIdentical(sprintf(elgg_echo('APIException:MethodCallNotImplemented'), 'bad.method'), $obj->api[0]->message);\r
}\r
\r
+ public function testAuthenticateForApi() {\r
+ $this->registerFunction(true, false);\r
+ \r
+ $this->expectException('APIException');\r
+ authenticate_method('test');\r
+ }\r
+\r
+ public function testAuthenticateForUser() {\r
+ $this->registerFunction(false, true);\r
+ \r
+ $this->expectException('APIException');\r
+ authenticate_method('test');\r
+ }\r
+ \r
+ public function testAuthenticateMethod() {\r
+ $this->registerFunction(false, false);\r
+ // anonymous with no user authentication\r
+ $this->assertTrue(authenticate_method('test'));\r
+ }\r
+ \r
+// api_authenticate\r
+ public function testApiAuthenticate() {\r
+ $this->registerFunction(true, false);\r
+ \r
+ $this->assertFalse(api_authenticate());\r
+ }\r
+ \r
+// execute_method\r
+ public function testExecuteMethodNonCallable() {\r
+ $this->registerFunction();\r
+ \r
+ $this->expectException('APIException');\r
+ execute_method('test');\r
+ }\r
+ \r
public function testVerifyParameters() {\r
$this->registerFunction();\r
\r
protected function registerFunction($api_auth = false, $user_auth = false) {\r
$parameters = array('param1' => array('type' => 'int', 'required' => true),\r
'param2' => array('type' => 'bool', 'required' => false), );\r
- $method['function'] = 'foo';\r
- $method['parameters'] = $parameters;\r
- $method['call_method'] = 'GET'; \r
- $method['description'] = '';\r
- $method['require_api_auth'] = $api_auth;\r
- $method['require_user_auth'] = $user_auth;\r
\r
- expose_function('test', 'foo', $parameters);\r
+ expose_function('test', 'foo', $parameters, '', 'GET', $api_auth, $user_auth);\r
}\r
\r
}\r
'SecurityException:AuthTokenExpired' => "Authentication token either missing, invalid or expired.",
'CallException:InvalidCallMethod' => "%s must be called using '%s'",
'APIException:MethodCallNotImplemented' => "Method call '%s' has not been implemented.",
+ 'APIException:FunctionDoesNotExist' => "Function for method '%s' is not callable",
'APIException:AlgorithmNotSupported' => "Algorithm '%s' is not supported or has been disabled.",
'ConfigurationException:CacheDirNotSet' => "Cache directory 'cache_path' not set.",
'APIException:NotGetOrPost' => "Request method must be GET or POST",