summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/cases/inc/remote.test.php43
-rw-r--r--inc/remote.php7
2 files changed, 44 insertions, 6 deletions
diff --git a/_test/cases/inc/remote.test.php b/_test/cases/inc/remote.test.php
index b33d8039f..f0e7b3d27 100644
--- a/_test/cases/inc/remote.test.php
+++ b/_test/cases/inc/remote.test.php
@@ -75,13 +75,24 @@ class remote_plugin_testplugin extends DokuWiki_Remote_Plugin {
'method1' => array(
'args' => array(),
'return' => 'void'
- ),
- 'method2' => array(
+ ), 'methodString' => array(
+ 'args' => array(),
+ 'return' => 'string'
+ ), 'method2' => array(
+ 'args' => array('string', 'int'),
+ 'return' => 'array',
+ 'name' => 'method2',
+ ), 'method2ext' => array(
'args' => array('string', 'int', 'bool'),
- 'return' => array('string'),
+ 'return' => 'array',
+ 'name' => 'method2',
)
);
}
+
+ function method1() { return null; }
+ function methodString() { return 'success'; }
+ function method2($str, $int, $bool = false) { return array($str, $int, $bool); }
}
@@ -112,7 +123,11 @@ class remote_test extends UnitTestCase {
function test_pluginMethods() {
$methods = $this->remote->getPluginMethods();
- $this->assertEqual(array_keys($methods), array('plugin.testplugin.method1', 'plugin.testplugin.method2'));
+ $actual = array_keys($methods);
+ sort($actual);
+ $expect = array('plugin.testplugin.method1', 'plugin.testplugin.method2', 'plugin.testplugin.methodString', 'plugin.testplugin.method2ext');
+ sort($expect);
+ $this->assertEqual($expect,$actual);
}
function test_hasAccessSuccess() {
@@ -176,4 +191,24 @@ class remote_test extends UnitTestCase {
$this->assertEqual($remoteApi->call('wiki.twoArgWithDefaultArg', array('string')), array('string', 'default'));
$this->assertEqual($remoteApi->call('wiki.twoArgWithDefaultArg', array('string', 'another')), array('string', 'another'));
}
+
+ function test_pluginCallMethods() {
+ global $conf;
+ $conf['remote'] = 1;
+
+ $remoteApi = new RemoteApi();
+ $this->assertEqual($remoteApi->call('plugin.testplugin.method1'), null);
+ $this->assertEqual($remoteApi->call('plugin.testplugin.method2', array('string', 7)), array('string', 7, false));
+ $this->assertEqual($remoteApi->call('plugin.testplugin.method2ext', array('string', 7, true)), array('string', 7, true));
+ $this->assertEqual($remoteApi->call('plugin.testplugin.methodString'), 'success');
+ }
+
+ function test_notExistingCall() {
+ global $conf;
+ $conf['remote'] = 1;
+
+ $remoteApi = new RemoteApi();
+ $this->expectException('RemoteException');
+ $remoteApi->call('dose not exist');
+ }
}
diff --git a/inc/remote.php b/inc/remote.php
index 5f136a43d..bc35d525e 100644
--- a/inc/remote.php
+++ b/inc/remote.php
@@ -75,10 +75,12 @@ class RemoteAPI {
list($type, $pluginName, $call) = explode('.', $method, 3);
if ($type === 'plugin') {
$plugin = plugin_load('remote', $pluginName);
+ $methods = $this->getPluginMethods();
if (!$plugin) {
throw new RemoteException('Method dose not exists');
}
- return call_user_func_array(array($plugin, $call), $args);
+ $name = $this->getMethodName($methods, $method);
+ return call_user_func_array(array($plugin, $name), $args);
} else {
$coreMethods = $this->getCoreMethods();
if (!isset($coreMethods[$method])) {
@@ -99,7 +101,8 @@ class RemoteAPI {
if (isset($methodMeta[$method]['name'])) {
return $methodMeta[$method]['name'];
}
- return $method;
+ $method = explode('.', $method);
+ return $method[count($method)-1];
}
/**