Skip to content

Commit

Permalink
added remote plugin calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-mel committed Dec 8, 2011
1 parent 4815d22 commit 647919c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
43 changes: 39 additions & 4 deletions _test/cases/inc/remote.test.php
Expand Up @@ -75,13 +75,24 @@ function _getMethods() {
'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); }
}


Expand Down Expand Up @@ -112,7 +123,11 @@ function tearDown() {

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() {
Expand Down Expand Up @@ -176,4 +191,24 @@ function test_generalCoreFunctionWithArguments() {
$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');
}
}
7 changes: 5 additions & 2 deletions inc/remote.php
Expand Up @@ -75,10 +75,12 @@ public function call($method, $args = array()) {
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])) {
Expand All @@ -99,7 +101,8 @@ private function getMethodName($methodMeta, $method) {
if (isset($methodMeta[$method]['name'])) {
return $methodMeta[$method]['name'];
}
return $method;
$method = explode('.', $method);
return $method[count($method)-1];
}

/**
Expand Down

0 comments on commit 647919c

Please sign in to comment.