Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BROKEN added enable/disable feature for plugins

  • Loading branch information...
commit f9b8008a4ccae56009894e4052dba80752d562bc 1 parent e048653
Tobias Sarnowski authored
View
7 _testing/README
@@ -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, ...
View
36 _testing/bootstrap.php
@@ -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 @@
// default plugins
$default_plugins = array(
'acl',
- 'action',
- 'admin',
'config',
'info',
'plugin',
'popularity',
- 'remote',
'revert',
'safefnrecode',
- 'syntax',
'usermanager'
);
@@ -75,7 +72,7 @@
// cleanup dir after exit
register_shutdown_function(function() {
- TestUtils::rdelete(TMP_DIR);
+ //TestUtils::rdelete(TMP_DIR);
});
// populate default dirs
@@ -85,40 +82,21 @@
// 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;
-}
-
-
View
6 _testing/conf/plugins.php
@@ -0,0 +1,6 @@
+<?php
+/**
+ * This file configures the default states of available plugins. All settings in
+ * the plugins.*.php files will override those here.
+ */
+$plugins['testing'] = 0;
View
10 _testing/core/DokuWikiTest.php
@@ -42,6 +42,16 @@ function setUp() {
// 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();
View
89 _testing/core/TestRequest.php
@@ -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 @@ function execute() {
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;
}
}
View
38 _testing/core/TestResponse.php
@@ -0,0 +1,38 @@
+<?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);
+ }
+}
View
47 _testing/tests/testing/inttests_globals.test.php
@@ -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();
+ }
}
View
49 _testing/tests/testing/inttests_plugins.test.php
@@ -0,0 +1,49 @@
+<?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!');
+ }
+}
View
6 conf/plugins.php
@@ -0,0 +1,6 @@
+<?php
+/**
+ * This file configures the default states of available plugins. All settings in
+ * the plugins.*.php files will override those here.
+ */
+$plugins['testing'] = 0;
@selfthinker Collaborator

Won't this get overwritten when upgrading DokuWiki? Shouldn't it go into plugins.required.php instead?
I'm not 100% sure as we all had some problems (i.e. were easily confused) figuring those things out while looking at the (new) extension manager...

I can just explain the intension as I'm not familiar with things like the extension manager, maybe @splitbrain should have a look.

To verify that the test suite works correctly, we have a "testing" plugin which adds nothing for normal users. The intension was to disable this plugin by default. There is no problem if someone overrides those in local/... whatever configuration for whatever reason. The whole point was to disable this for new, clean installations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

6 comments on commit f9b8008

@splitbrain
Owner

I thinks it's correct this way. Having it in plugins.required.php would make it impossible to change the state of this plugin through the plugin manager (which you might want to do for... well, I don't know ;-)).

@sarnowski

The manager must be able to change its state to activate it for the corresponding test cases. (see _test/tests/test/plugins.test.php)

@selfthinker
Collaborator

Yes, I know what it's supposed to do (and it works). I forgot which are the local files and which are the core files. I remember that we had plugins.php earlier and that we removed it again because it didn't make any sense. But unfortunately I don't remember much more. If that is a file a user would change, it mustn't be in the repository, because an update would overwrite what a user put in there. (So, the other way around, not a user overwriting the file, but us overwriting the user's configuration.) Do we have some documentation for those plugin config files?

Even if this is not a local file (which I'm still not sure about), I still think it's better suited in plugins.required.php. To "make it impossible to change the state of this plugin" is the whole point of disabling this plugin, right? Why else is there a big fat red warning whenever you have enabled it? I think this is a perfect case for something a normal user should never be allowed to change (therefore it should go into plugins.required.php), but only an admin should do it only if there is a good reason for it (like the rest of the required plugins).

@selfthinker
Collaborator

Here is the documention: http://www.dokuwiki.org/config#enabling_disabling_plugins which is missing the "default" file because @splitbrain added it just a short while ago here: 23725b9
I do remember we have decided to not have a default plugin config file. But as I said, unfortunately I don't remember the reason anymore. Maybe @HakanS, @michitux or @piyushmishra will remember?

@splitbrain
Owner

We did not have a default file because all plugins are enabled by default ad we had no idea why we would ship a plugin that would be disabled by default.

@sarnowski

until now :-p

Please sign in to comment.
Something went wrong with that request. Please try again.