summaryrefslogtreecommitdiff
path: root/_testing/core
diff options
context:
space:
mode:
Diffstat (limited to '_testing/core')
-rw-r--r--_testing/core/DokuWikiTest.php10
-rw-r--r--_testing/core/TestRequest.php89
-rw-r--r--_testing/core/TestResponse.php38
3 files changed, 100 insertions, 37 deletions
diff --git a/_testing/core/DokuWikiTest.php b/_testing/core/DokuWikiTest.php
index 8ae261a52..2517e25e3 100644
--- a/_testing/core/DokuWikiTest.php
+++ b/_testing/core/DokuWikiTest.php
@@ -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();
diff --git a/_testing/core/TestRequest.php b/_testing/core/TestRequest.php
index f77c494c3..c9fc06bf2 100644
--- a/_testing/core/TestRequest.php
+++ b/_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 @@ 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;
}
}
diff --git a/_testing/core/TestResponse.php b/_testing/core/TestResponse.php
new file mode 100644
index 000000000..ed112b42e
--- /dev/null
+++ b/_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);
+ }
+}