Skip to content

Commit

Permalink
introduced first remote test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-mel committed Nov 28, 2011
1 parent 2d2d9d0 commit f61380c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
77 changes: 77 additions & 0 deletions _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();
}
}
2 changes: 1 addition & 1 deletion inc/remote.php
Expand Up @@ -92,7 +92,7 @@ public function hasAccess() {
* @throws RemoteException On denied access.
* @return void
*/
private function forceAccess() {
public function forceAccess() {
if (!$this->hasAccess()) {
throw new RemoteException('Access denied');
}
Expand Down

0 comments on commit f61380c

Please sign in to comment.