diff options
author | Dominik Eckelmann <deckelmann@gmail.com> | 2011-11-28 19:06:16 +0100 |
---|---|---|
committer | Dominik Eckelmann <deckelmann@gmail.com> | 2011-11-28 19:11:07 +0100 |
commit | f61380cb67f8216ae4c75922511ff5a07fd21ca0 (patch) | |
tree | 6925835b4b8f4e8455ac6f4994ef4e00e215c67a | |
parent | 2d2d9d0f3a410b31d76a2be193fe16b3dbd79096 (diff) | |
download | rpg-f61380cb67f8216ae4c75922511ff5a07fd21ca0.tar.gz rpg-f61380cb67f8216ae4c75922511ff5a07fd21ca0.tar.bz2 |
introduced first remote test cases
-rw-r--r-- | _test/cases/inc/remote.test.php | 77 | ||||
-rw-r--r-- | inc/remote.php | 2 |
2 files changed, 78 insertions, 1 deletions
diff --git a/_test/cases/inc/remote.test.php b/_test/cases/inc/remote.test.php new file mode 100644 index 000000000..aa7a8cd1b --- /dev/null +++ b/_test/cases/inc/remote.test.php @@ -0,0 +1,77 @@ +<?php + +require_once DOKU_INC . 'inc/init.php'; + +Mock::generate('Doku_Plugin_Controller'); + +class remote_plugin_testplugin extends DokuWiki_Remote_Plugin { + function _getMethods() { + return array( + 'method1' => array( + 'args' => array(), + 'return' => 'void' + ), + 'method2' => array( + 'args' => array('string', 'int', 'bool'), + 'return' => array('string'), + ) + ); + } +} + + +class remote_test extends UnitTestCase { + + var $originalConf; + + var $remote; + + function setUp() { + global $plugin_controller; + global $conf; + parent::setUp(); + $pluginManager = new MockDoku_Plugin_Controller(); + $pluginManager->setReturnValue('getList', array('testplugin')); + $pluginManager->setReturnValue('load', new remote_plugin_testplugin()); + $plugin_controller = $pluginManager; + + $this->originalConf = $conf; + + $this->remote = new RemoteAPI(); + } + + function tearDown() { + global $conf; + $conf = $this->originalConf; + } + + function test_pluginMethods() { + $methods = $this->remote->getPluginMethods(); + $this->assertEqual(array_keys($methods), array('plugin.testplugin.method1', 'plugin.testplugin.method2')); + } + + function test_hasAccessSuccess() { + global $conf; + $conf['remote'] = 1; + $this->assertTrue($this->remote->hasAccess()); + } + + function test_hasAccessFail() { + global $conf; + $conf['remote'] = 0; + $this->assertFalse($this->remote->hasAccess()); + } + + function test_forceAccessSuccess() { + global $conf; + $conf['remote'] = 1; + $this->remote->forceAccess(); // no exception should occur + } + + function test_forceAccessFail() { + global $conf; + $conf['remote'] = 0; + $this->expectException('RemoteException'); + $this->remote->forceAccess(); + } +} diff --git a/inc/remote.php b/inc/remote.php index 13a38aa17..6f48d2015 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -92,7 +92,7 @@ class RemoteAPI { * @throws RemoteException On denied access. * @return void */ - private function forceAccess() { + public function forceAccess() { if (!$this->hasAccess()) { throw new RemoteException('Access denied'); } |