Skip to content
Snippets Groups Projects
Commit f9b8008a authored by Tobias Sarnowski's avatar Tobias Sarnowski
Browse files

BROKEN added enable/disable feature for plugins

parent e048653b
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,7 @@ the PHPUnit migration and are disabled by default:
* inc/parser/parser_formatting
* inc/parser/xhtml_htmlphp (runkit)
* inc/parser/xhtml_links
* testing/inttests_plugins (enabling/disabling of plugins is borked)
TODO for the test framework
......@@ -65,14 +66,10 @@ TODO for the test framework
* unit test [ok]
* integration test [ok]
* plugins
* unit test
* unit test [ok]
* integration test [untested]
* provide the possibility to enable/disable plugins
* cleanup dw globals like registered event hooks
* cross platform compatibility: especially test windows (hint: tmp dir location)
* update http://www.dokuwiki.org/devel:unittesting
* optional: add helper methods to TestRequest for easy form submission
* createForm(), ...
* optional: add helper methods to TestReponse for easy response parsing
* findElementById, findElementByXPath, ...
......@@ -6,6 +6,7 @@
if(!defined('DOKU_UNITTEST')) define('DOKU_UNITTEST',dirname(__FILE__).'/');
require_once DOKU_UNITTEST.'core/phpQuery-onefile.php';
require_once DOKU_UNITTEST.'core/DokuWikiTest.php';
require_once DOKU_UNITTEST.'core/TestResponse.php';
require_once DOKU_UNITTEST.'core/TestRequest.php';
require_once DOKU_UNITTEST.'core/TestUtils.php';
......@@ -27,16 +28,12 @@ define('DOKU_TMP_DATA', TMP_DIR.'/data/');
// default plugins
$default_plugins = array(
'acl',
'action',
'admin',
'config',
'info',
'plugin',
'popularity',
'remote',
'revert',
'safefnrecode',
'syntax',
'usermanager'
);
......@@ -75,7 +72,7 @@ mkdir(TMP_DIR);
// cleanup dir after exit
register_shutdown_function(function() {
TestUtils::rdelete(TMP_DIR);
//TestUtils::rdelete(TMP_DIR);
});
// populate default dirs
......@@ -85,40 +82,21 @@ TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/data');
// disable all non-default plugins by default
$dh = dir(DOKU_INC.'lib/plugins/');
while (false !== ($entry = $dh->read())) {
if ($entry == '.' || $entry == '..' || $entry == 'index.html') {
if ($entry == '.' || $entry == '..') {
continue;
}
if (substr($entry, strlen($entry) - 4) == '.php') {
$plugin = substr($entry, 0, strlen($entry) - 4);
} else {
$plugin = $entry;
if (!is_dir(DOKU_INC.'lib/plugins/'.$entry)) {
continue;
}
if (!in_array($plugin, $default_plugins)) {
if (!in_array($entry, $default_plugins)) {
// disable this plugin
TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$plugin'] = 0;\n");
TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$entry'] = 0;\n");
}
}
$dh->close();
// setup default global variables
$_GET = array('id' => '');
$_POST = array();
$_REQUEST = array('id' => '');
foreach ($default_server_vars as $key => $value) {
$_SERVER[$key] = $value;
}
// load dw
require_once(DOKU_INC.'inc/init.php');
// output buffering
$output_buffer = '';
function ob_start_callback($buffer) {
global $output_buffer;
$output_buffer .= $buffer;
}
<?php
/**
* This file configures the default states of available plugins. All settings in
* the plugins.*.php files will override those here.
*/
$plugins['testing'] = 0;
......@@ -42,6 +42,16 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase {
// reset loaded plugins
global $plugin_controller_class, $plugin_controller;
$plugin_controller = new $plugin_controller_class();
// disable all non-default plugins
global $default_plugins;
foreach ($plugin_controller->getList() as $plugin) {
if (!in_array($plugin, $default_plugins)) {
$plugin_controller->disable($plugin);
}
}
// reset event handler
global $EVENT_HANDLER;
$EVENT_HANDLER = new Doku_Event_Handler();
......
......@@ -4,10 +4,34 @@
* runtime inspection.
*/
// output buffering
$output_buffer = '';
function ob_start_callback($buffer) {
global $output_buffer;
$output_buffer .= $buffer;
}
/**
* Helper class to execute a fake request
*/
class TestRequest {
var $server = array();
var $session = array();
var $get = array();
var $post = array();
function getServer($key) { return $this->server[$key]; }
function getSession($key) { return $this->session[$key]; }
function getGet($key) { return $this->get[$key]; }
function getPost($key) { return $this->post[$key]; }
function setServer($key, $value) { $this->server[$key] = $value; }
function setSession($key, $value) { $this->session[$key] = $value; }
function setGet($key, $value) { $this->get[$key] = $value; }
function setPost($key, $value) { $this->post[$key] = $value; }
/**
* Executes the request
......@@ -15,6 +39,22 @@ class TestRequest {
* @return TestResponse response
*/
function execute() {
// save old environment
$server = $_SERVER;
$session = $_SESSION;
$get = $_GET;
$post = $_POST;
$request = $_REQUEST;
// fake environment
global $default_server_vars;
$_SERVER = array_merge($default_server_vars, $this->server);
$_SESSION = $this->session;
$_GET = $this->get;
$_POST = $this->post;
$_REQUEST = array_merge($_GET, $_POST);
// reset output buffer
global $output_buffer;
$output_buffer = '';
......@@ -24,44 +64,19 @@ class TestRequest {
include(DOKU_INC.'doku.php');
ob_end_flush();
// it's done, return the page result
return new TestResponse(
$output_buffer,
headers_list()
);
}
}
/**
* holds a copy of all produced outputs of a TestRequest
*/
class TestResponse {
protected $content;
protected $headers;
protected $pq = null;
function __construct($content, $headers) {
$this->content = $content;
$this->headers = $headers;
}
// create the response object
$response = new TestResponse(
$output_buffer,
headers_list()
);
function getContent() {
return $this->content;
}
// reset environment
$_SERVER = $server;
$_SESSION = $session;
$_GET = $get;
$_POST = $post;
$_REQUEST = $request;
function getHeaders() {
return $this->headers;
}
/**
* Query the response for a JQuery compatible CSS selector
*
* @link https://code.google.com/p/phpquery/wiki/Selectors
* @param string selector
* @returns object a PHPQuery object
*/
function queryHTML($selector){
if(is_null($pq)) $pq = phpQuery::newDocument($this->content);
return pq($selector);
return $response;
}
}
<?php
/**
* holds a copy of all produced outputs of a TestRequest
*/
class TestResponse {
protected $content;
protected $headers;
/**
* @var phpQueryObject
*/
protected $pq = null;
function __construct($content, $headers) {
$this->content = $content;
$this->headers = $headers;
}
function getContent() {
return $this->content;
}
function getHeaders() {
return $this->headers;
}
/**
* Query the response for a JQuery compatible CSS selector
*
* @link https://code.google.com/p/phpquery/wiki/Selectors
* @param string selector
* @returns object a PHPQuery object
*/
function queryHTML($selector){
if(is_null($this->pq)) $this->pq = phpQuery::newDocument($this->content);
return $this->pq->find($selector);
}
}
......@@ -4,19 +4,46 @@
* @group integration
*/
class InttestsGlobalsTest extends DokuWikiTest {
/**
* Global variables should be restored for every test case.
* every request should be with its own variables
*/
function testFirstRun() {
$this->assertEquals('87.142.120.6', $_SERVER['REMOTE_ADDR'], 'Global var not set as expected');
function testFirstRun() {
global $EVENT_HANDLER;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
}
$request = new TestRequest();
$request->setServer('testvar', true);
/**
* @depends testFirstRun
*/
function testSecondRun() {
$this->assertEquals('87.142.120.6', $_SERVER['REMOTE_ADDR'], 'Global var not set as expected');
$self = $this;
$EVENT_HANDLER->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', null,
function() use ($self) {
$self->assertTrue($_SERVER['testvar'], 'Server variable not set correctly: testvar');
$self->assertEquals('87.142.120.6', $_SERVER['REMOTE_ADDR'], 'Server variable not set correctly: REMOTE_ADDR');
$_SERVER['tmpvar'] = true;
}
);
$request->execute();
}
/**
* @depends testFirstRun
*/
function testSecondRun() {
global $EVENT_HANDLER;
$request = new TestRequest();
$request->setServer('testvar', false);
$self = $this;
$EVENT_HANDLER->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', null,
function() use ($self) {
$self->assertFalse($_SERVER['testvar'], 'Server variable not set correctly: testvar');
$self->assertEquals('87.142.120.6', $_SERVER['REMOTE_ADDR'], 'Server variable not set correctly: REMOTE_ADDR');
$self->assertFalse(isset($_SERVER['tmpvar']));
}
);
$request->execute();
}
}
<?php
/**
* @group integration
*/
class InttestsPluginsTest extends DokuWikiTest {
function testTestingPluginEnabled() {
global $EVENT_HANDLER, $plugin_controller;
$this->assertTrue(
$plugin_controller->enable('testing'),
'Could not enable testing plugin.'
);
$request = new TestRequest();
$hookTriggered = false;
$EVENT_HANDLER->register_hook('TESTING_PLUGIN_INSTALLED', 'AFTER', null,
function() use (&$hookTriggered) {
$hookTriggered = true;
}
);
$request->execute();
$this->assertTrue($hookTriggered, 'Testing plugin did not trigger!');
}
/**
* @depends testTestingPluginEnabled
*/
function testTestingPluginDisabledDefault() {
global $EVENT_HANDLER;
$request = new TestRequest();
$hookTriggered = false;
$EVENT_HANDLER->register_hook('TESTING_PLUGIN_INSTALLED', 'AFTER', null,
function() use (&$hookTriggered) {
$hookTriggered = true;
}
);
$request->execute();
$this->assertFalse($hookTriggered, 'Testing plugin did trigger!');
}
}
<?php
/**
* This file configures the default states of available plugins. All settings in
* the plugins.*.php files will override those here.
*/
$plugins['testing'] = 0;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment