]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
fixed line endings on services api unit tests
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 14 Dec 2009 12:39:53 +0000 (12:39 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 14 Dec 2009 12:39:53 +0000 (12:39 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@3754 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/tests/services/api.php

index b9dfda8f555c378346f880f0beb8b3f67b30a538..216c888ab59d953a1b08ca0238ba3ef0a475208a 100644 (file)
-<?php\r
-/**\r
- * Elgg Test Services - General API and REST\r
- *\r
- * @package Elgg\r
- * @subpackage Test\r
- * @author Curverider Ltd\r
- * @link http://elgg.org/\r
- */\r
-class ElggCoreServicesApiTest extends ElggCoreUnitTest {\r
-\r
-       /**\r
-        * Called after each test method.\r
-        */\r
-       public function tearDown() {\r
-               global $API_METHODS;\r
-               $this->swallowErrors();\r
-               $API_METHODS = array();\r
-       }\r
-       \r
-// expose_function\r
-       public function testExposeFunctionNoMethod() {\r
-               try {\r
-                       expose_function();\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'InvalidParameterException');\r
-                       $this->assertIdentical($e->getMessage(), elgg_echo('InvalidParameterException:APIMethodOrFunctionNotSet'));\r
-               }\r
-       }\r
-       \r
-       public function testExposeFunctionNoFunction() {\r
-               try {\r
-                       expose_function('test');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'InvalidParameterException');\r
-                       $this->assertIdentical($e->getMessage(), elgg_echo('InvalidParameterException:APIMethodOrFunctionNotSet'));\r
-               }\r
-       }\r
-       \r
-       public function testExposeFunctionBadParameters() {\r
-               try {\r
-                       expose_function('test', 'test', 'BAD');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'InvalidParameterException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('InvalidParameterException:APIParametersArrayStructure'), 'test'));\r
-               }\r
-       }\r
-       \r
-       public function testExposeFunctionParametersBadArray() {\r
-               try {\r
-                       expose_function('test', 'test', array('param1' => 'string'));\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'InvalidParameterException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('InvalidParameterException:APIParametersArrayStructure'), 'test'));\r
-               }\r
-       }\r
-       \r
-       public function testExposeFunctionBadHttpMethod() {\r
-               try {\r
-                       expose_function('test', 'test', null, '', 'BAD');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'InvalidParameterException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('InvalidParameterException:UnrecognisedHttpMethod'), 'BAD', 'test'));\r
-               }\r
-       }\r
-       \r
-       public function testExposeFunctionSuccess() {\r
-               global $API_METHODS;\r
-               // this is a general test but also tests specifically for setting 'required' correctly\r
-               $parameters = array('param1' => array('type' => 'int', 'required' => true), \r
-                                                       'param2' => array('type' => 'bool'),\r
-                                                       'param3' => array('type' => 'string', 'required' => false), );\r
-               \r
-               $this->assertTrue(expose_function('test', 'foo', $parameters));\r
-               \r
-               $parameters = array('param1' => array('type' => 'int', 'required' => true), \r
-                                                       'param2' => array('type' => 'bool', 'required' => true),\r
-                                                       'param3' => array('type' => 'string', 'required' => false), );\r
-               $method['description'] = '';\r
-               $method['function'] = 'foo';\r
-               $method['parameters'] = $parameters;\r
-               $method['call_method'] = 'GET'; \r
-               $method['require_api_auth'] = false;\r
-               $method['require_user_auth'] = false;\r
-\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 testAuthenticateMethodNotImplemented() {\r
-               try {\r
-                       authenticate_method('BAD');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:MethodCallNotImplemented'), 'BAD'));\r
-               }                               \r
-       }\r
-       \r
-       public function testAuthenticateMethodApiAuth() {\r
-               $this->registerFunction(true);\r
-               try {\r
-                       authenticate_method('test');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), elgg_echo('APIException:APIAuthenticationFailed'));\r
-               }                               \r
-       }\r
-       \r
-       public function testAuthenticateMethodUserAuth() {\r
-               $this->registerFunction(false, true);\r
-               try {\r
-                       authenticate_method('test');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), elgg_echo('APIException:UserAuthenticationFailed'));\r
-               }                               \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
-// execute_method\r
-       public function testExecuteMethodNotImplemented() {\r
-               try {\r
-                       execute_method('BAD');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:MethodCallNotImplemented'), 'BAD'));\r
-               }                               \r
-       }\r
-\r
-       public function testExecuteMethodNonCallable() {\r
-               expose_function('test', 'foo');\r
-               \r
-               try {\r
-                       execute_method('test');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:FunctionDoesNotExist'), 'test'));\r
-               }                               \r
-       }\r
-\r
-       public function testExecuteMethodWrongMethod() {\r
-               $this->registerFunction();\r
-               \r
-               try {\r
-                       // GET when it should be a POST\r
-                       execute_method('test');\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'CallException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('CallException:InvalidCallMethod'), 'test', 'POST'));\r
-               }                                               \r
-       }\r
-\r
-// verify parameters\r
-       public function testVerifyParametersTypeNotSet() {\r
-               $params = array('param1' => array('required' => true));\r
-               expose_function('test', 'elgg_echo', $params);\r
-               \r
-               try {\r
-                       verify_parameters('test', array());\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:InvalidParameter'), 'param1', 'test'));\r
-               }                                               \r
-       }\r
-       \r
-       public function testVerifyParametersMissing() {\r
-               $params = array('param1' => array('type' => 'int', 'required' => true));\r
-               expose_function('test', 'elgg_echo', $params);\r
-               \r
-               try {\r
-                       verify_parameters('test', array());\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:MissingParameterInMethod'), 'param1', 'test'));\r
-               }                                               \r
-       }\r
-       \r
-       public function testVerifyParameters() {\r
-               $this->registerFunction();\r
-               \r
-               $parameters = array('param1' => 0);\r
-               $this->assertTrue(verify_parameters('test', $parameters));\r
-       }\r
-       \r
-       public function testSerialiseParameters() {\r
-               \r
-               // int and bool\r
-               $this->registerFunction();\r
-               $parameters = array('param1' => 1, 'param2' => 0);\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ',1,false');\r
-               \r
-               // string\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));\r
-               $parameters = array('param1' => 'testing');\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ",'testing'");\r
-\r
-               // test string with " in it\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));\r
-               $parameters = array('param1' => 'test"ing');\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ',\'test"ing\'');\r
-               \r
-               // test string with ' in it\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));\r
-               $parameters = array('param1' => 'test\'ing');\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ",'test\'ing'");\r
-               \r
-               // test string with \ in it\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));\r
-               $parameters = array('param1' => 'test\ing');\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ",'test\\ing'"); \r
-               \r
-               // test string with \' in it\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));\r
-               $parameters = array('param1' => "test\'ing");\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ",'test\\\\'ing'"); // test\\'ing\r
-               \r
-               // test string reported by twall in #1364\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));\r
-               $parameters = array('param1' => '{"html":"<div><img src=\\"http://foo.com\\"/>Blah Blah</div>"}');\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ",'{\"html\":\"<div><img src=\\\"http://foo.com\\\"/>Blah Blah</div>\"}'");\r
-               \r
-               // float\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'float')));\r
-               $parameters = array('param1' => 2.5);\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ',2.5');\r
-\r
-               // indexed array of strings\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'array')));\r
-               $parameters = array('param1' => array('one', 'two'));\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ",array('0'=>'one','1'=>'two')");\r
-\r
-               // associative array of strings\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'array')));\r
-               $parameters = array('param1' => array('first' => 'one', 'second' => 'two'));\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ",array('first'=>'one','second'=>'two')");\r
-\r
-               // indexed array of strings\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'array')));\r
-               $parameters = array('param1' => array(1, 2));\r
-               $s = serialise_parameters('test', $parameters);\r
-               $this->assertIdentical($s, ",array('0'=>'1','1'=>'2')");\r
-\r
-               // test unknown type\r
-               $this->registerFunction(false, false, array('param1' => array('type' => 'bad')));\r
-               $parameters = array('param1' => 'test');\r
-               $this->expectException('APIException');\r
-               $s = serialise_parameters('test', $parameters);\r
-       }\r
-       \r
-// api key methods\r
-       public function testApiAuthenticate() {\r
-               $this->assertFalse(pam_authenticate(null, "api"));\r
-       }\r
-       \r
-       public function testApiAuthKeyNoKey() {\r
-               try {\r
-                       api_auth_key();\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), elgg_echo('APIException:MissingAPIKey'));\r
-               }\r
-       }\r
-\r
-       public function testApiAuthKeyBadKey() {\r
-               global $CONFIG;\r
-               \r
-               $CONFIG->input['api_key'] = 'BAD';\r
-               try {\r
-                       api_auth_key();\r
-                       $this->assertTrue(FALSE);\r
-               } catch (Exception $e) {\r
-                       $this->assertIsA($e, 'APIException');\r
-                       $this->assertIdentical($e->getMessage(), elgg_echo('APIException:BadAPIKey'));\r
-               }\r
-       }\r
-       \r
-       protected function registerFunction($api_auth = false, $user_auth = false, $params = null) {\r
-               $parameters = array('param1' => array('type' => 'int', 'required' => true),\r
-                                                       'param2' => array('type' => 'bool', 'required' => false), );\r
-               \r
-               if ($params == null) {\r
-                       $params = $parameters;\r
-               }\r
-\r
-               expose_function('test', 'elgg_echo', $params, '', 'POST', $api_auth, $user_auth);\r
-       }\r
-       \r
-}\r
+<?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();
+       }
+       
+// expose_function
+       public function testExposeFunctionNoMethod() {
+               try {
+                       expose_function();
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'InvalidParameterException');
+                       $this->assertIdentical($e->getMessage(), elgg_echo('InvalidParameterException:APIMethodOrFunctionNotSet'));
+               }
+       }
+       
+       public function testExposeFunctionNoFunction() {
+               try {
+                       expose_function('test');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'InvalidParameterException');
+                       $this->assertIdentical($e->getMessage(), elgg_echo('InvalidParameterException:APIMethodOrFunctionNotSet'));
+               }
+       }
+       
+       public function testExposeFunctionBadParameters() {
+               try {
+                       expose_function('test', 'test', 'BAD');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'InvalidParameterException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('InvalidParameterException:APIParametersArrayStructure'), 'test'));
+               }
+       }
+       
+       public function testExposeFunctionParametersBadArray() {
+               try {
+                       expose_function('test', 'test', array('param1' => 'string'));
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'InvalidParameterException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('InvalidParameterException:APIParametersArrayStructure'), 'test'));
+               }
+       }
+       
+       public function testExposeFunctionBadHttpMethod() {
+               try {
+                       expose_function('test', 'test', null, '', 'BAD');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'InvalidParameterException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('InvalidParameterException:UnrecognisedHttpMethod'), 'BAD', 'test'));
+               }
+       }
+       
+       public function testExposeFunctionSuccess() {
+               global $API_METHODS;
+               // this is a general test but also tests specifically for setting 'required' correctly
+               $parameters = array('param1' => array('type' => 'int', 'required' => true), 
+                                                       'param2' => array('type' => 'bool'),
+                                                       'param3' => array('type' => 'string', 'required' => false), );
+               
+               $this->assertTrue(expose_function('test', 'foo', $parameters));
+               
+               $parameters = array('param1' => array('type' => 'int', 'required' => true), 
+                                                       'param2' => array('type' => 'bool', 'required' => true),
+                                                       'param3' => array('type' => 'string', 'required' => false), );
+               $method['description'] = '';
+               $method['function'] = 'foo';
+               $method['parameters'] = $parameters;
+               $method['call_method'] = 'GET'; 
+               $method['require_api_auth'] = false;
+               $method['require_user_auth'] = false;
+
+               $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 testAuthenticateMethodNotImplemented() {
+               try {
+                       authenticate_method('BAD');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:MethodCallNotImplemented'), 'BAD'));
+               }                               
+       }
+       
+       public function testAuthenticateMethodApiAuth() {
+               $this->registerFunction(true);
+               try {
+                       authenticate_method('test');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), elgg_echo('APIException:APIAuthenticationFailed'));
+               }                               
+       }
+       
+       public function testAuthenticateMethodUserAuth() {
+               $this->registerFunction(false, true);
+               try {
+                       authenticate_method('test');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), elgg_echo('APIException:UserAuthenticationFailed'));
+               }                               
+       }
+       
+       public function testAuthenticateMethod() {
+               $this->registerFunction(false, false);
+               // anonymous with no user authentication
+               $this->assertTrue(authenticate_method('test'));
+       }
+       
+// execute_method
+       public function testExecuteMethodNotImplemented() {
+               try {
+                       execute_method('BAD');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:MethodCallNotImplemented'), 'BAD'));
+               }                               
+       }
+
+       public function testExecuteMethodNonCallable() {
+               expose_function('test', 'foo');
+               
+               try {
+                       execute_method('test');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:FunctionDoesNotExist'), 'test'));
+               }                               
+       }
+
+       public function testExecuteMethodWrongMethod() {
+               $this->registerFunction();
+               
+               try {
+                       // GET when it should be a POST
+                       execute_method('test');
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'CallException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('CallException:InvalidCallMethod'), 'test', 'POST'));
+               }                                               
+       }
+
+// verify parameters
+       public function testVerifyParametersTypeNotSet() {
+               $params = array('param1' => array('required' => true));
+               expose_function('test', 'elgg_echo', $params);
+               
+               try {
+                       verify_parameters('test', array());
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:InvalidParameter'), 'param1', 'test'));
+               }                                               
+       }
+       
+       public function testVerifyParametersMissing() {
+               $params = array('param1' => array('type' => 'int', 'required' => true));
+               expose_function('test', 'elgg_echo', $params);
+               
+               try {
+                       verify_parameters('test', array());
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), sprintf(elgg_echo('APIException:MissingParameterInMethod'), 'param1', 'test'));
+               }                                               
+       }
+       
+       public function testVerifyParameters() {
+               $this->registerFunction();
+               
+               $parameters = array('param1' => 0);
+               $this->assertTrue(verify_parameters('test', $parameters));
+       }
+       
+       public function testSerialiseParameters() {
+               
+               // int and bool
+               $this->registerFunction();
+               $parameters = array('param1' => 1, 'param2' => 0);
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ',1,false');
+               
+               // string
+               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));
+               $parameters = array('param1' => 'testing');
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ",'testing'");
+
+               // test string with " in it
+               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));
+               $parameters = array('param1' => 'test"ing');
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ',\'test"ing\'');
+               
+               // test string with ' in it
+               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));
+               $parameters = array('param1' => 'test\'ing');
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ",'test\'ing'");
+               
+               // test string with \ in it
+               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));
+               $parameters = array('param1' => 'test\ing');
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ",'test\\ing'"); 
+               
+               // test string with \' in it
+               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));
+               $parameters = array('param1' => "test\'ing");
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ",'test\\\\'ing'"); // test\\'ing
+               
+               // test string reported by twall in #1364
+               $this->registerFunction(false, false, array('param1' => array('type' => 'string')));
+               $parameters = array('param1' => '{"html":"<div><img src=\\"http://foo.com\\"/>Blah Blah</div>"}');
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ",'{\"html\":\"<div><img src=\\\"http://foo.com\\\"/>Blah Blah</div>\"}'");
+               
+               // float
+               $this->registerFunction(false, false, array('param1' => array('type' => 'float')));
+               $parameters = array('param1' => 2.5);
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ',2.5');
+
+               // indexed array of strings
+               $this->registerFunction(false, false, array('param1' => array('type' => 'array')));
+               $parameters = array('param1' => array('one', 'two'));
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ",array('0'=>'one','1'=>'two')");
+
+               // associative array of strings
+               $this->registerFunction(false, false, array('param1' => array('type' => 'array')));
+               $parameters = array('param1' => array('first' => 'one', 'second' => 'two'));
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ",array('first'=>'one','second'=>'two')");
+
+               // indexed array of strings
+               $this->registerFunction(false, false, array('param1' => array('type' => 'array')));
+               $parameters = array('param1' => array(1, 2));
+               $s = serialise_parameters('test', $parameters);
+               $this->assertIdentical($s, ",array('0'=>'1','1'=>'2')");
+
+               // test unknown type
+               $this->registerFunction(false, false, array('param1' => array('type' => 'bad')));
+               $parameters = array('param1' => 'test');
+               $this->expectException('APIException');
+               $s = serialise_parameters('test', $parameters);
+       }
+       
+// api key methods
+       public function testApiAuthenticate() {
+               $this->assertFalse(pam_authenticate(null, "api"));
+       }
+       
+       public function testApiAuthKeyNoKey() {
+               try {
+                       api_auth_key();
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), elgg_echo('APIException:MissingAPIKey'));
+               }
+       }
+
+       public function testApiAuthKeyBadKey() {
+               global $CONFIG;
+               
+               $CONFIG->input['api_key'] = 'BAD';
+               try {
+                       api_auth_key();
+                       $this->assertTrue(FALSE);
+               } catch (Exception $e) {
+                       $this->assertIsA($e, 'APIException');
+                       $this->assertIdentical($e->getMessage(), elgg_echo('APIException:BadAPIKey'));
+               }
+       }
+       
+       protected function registerFunction($api_auth = false, $user_auth = false, $params = null) {
+               $parameters = array('param1' => array('type' => 'int', 'required' => true),
+                                                       'param2' => array('type' => 'bool', 'required' => false), );
+               
+               if ($params == null) {
+                       $params = $parameters;
+               }
+
+               expose_function('test', 'elgg_echo', $params, '', 'POST', $api_auth, $user_auth);
+       }
+       
+}