From f61380cb67f8216ae4c75922511ff5a07fd21ca0 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Mon, 28 Nov 2011 19:06:16 +0100 Subject: introduced first remote test cases --- _test/cases/inc/remote.test.php | 77 +++++++++++++++++++++++++++++++++++++++++ inc/remote.php | 2 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 _test/cases/inc/remote.test.php 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 @@ + 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'); } -- cgit v1.2.3