From 2f40e4e47ca183c13d667ec79a39963c6c7a7841 Mon Sep 17 00:00:00 2001 From: Francis Chuang Date: Sun, 19 May 2013 16:00:21 +1000 Subject: [PATCH] Added support for deleting all registered functions in a namespace. --- lib/triagens/ArangoDb/AqlUserFunction.php | 10 +++++-- tests/AqlUserFunctionTest.php | 34 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/triagens/ArangoDb/AqlUserFunction.php b/lib/triagens/ArangoDb/AqlUserFunction.php index 12fdb32b..0cb80435 100644 --- a/lib/triagens/ArangoDb/AqlUserFunction.php +++ b/lib/triagens/ArangoDb/AqlUserFunction.php @@ -145,19 +145,25 @@ public function register($name = null, $code = null) * * If $name is passed, it will override the object's property with the passed one * - * @param null $name + * @param string $name + * @param boolean $namespace * * @throws Exception throw exception if the request fails * * @return mixed true if successful without a return value or the return value if one was set in the action */ - public function unregister($name = null) + public function unregister($name = null, $namespace = false) { if (is_null($name)) { $name = $this->getName(); } + $url = UrlHelper::buildUrl(Urls::URL_AQL_USER_FUNCTION, $name); + if($namespace){ + $url = UrlHelper::appendParamsUrl($url, array('group' => true)); + } + $response = $this->_connection->delete($url); $responseArray = $response->getJson(); diff --git a/tests/AqlUserFunctionTest.php b/tests/AqlUserFunctionTest.php index d99edc8a..745c1e25 100644 --- a/tests/AqlUserFunctionTest.php +++ b/tests/AqlUserFunctionTest.php @@ -290,6 +290,40 @@ public function testGetAQLFunctionsWithNamespaceFilter() $userFunction->unregister($name2); } + /** + * Unregister all AQL functions on a namespace. + */ + public function testUnregisterAQLFunctionsOnNamespace() + { + + $name1 = 'myFunctions:myFunction1'; + $name2 = 'myFunctions:myFunction2'; + $code = 'function (celsius) { return celsius * 1.8 + 32; }'; + + //Setup + $userFunction = new AqlUserFunction($this->connection); + + $userFunction->name = $name1; + $userFunction->code = $code; + + $result = $userFunction->register(); + + $userFunction = new AqlUserFunction($this->connection); + + $userFunction->name = $name2; + $userFunction->code = $code; + + $result = $userFunction->register(); + + $functions = $userFunction->getRegisteredUserFunctions('myFunctions'); + $this->assertCount(2, $functions, "myFunctions namespace should only contain 2 functions."); + + $userFunction->unregister('myFunctions', true); + + $functions = $userFunction->getRegisteredUserFunctions('myFunctions'); + $this->assertEmpty($functions, "myFunctions namespace should only contain no functions."); + } + public function tearDown() {