summaryrefslogtreecommitdiff
path: root/_test/core/TestRequest.php
diff options
context:
space:
mode:
authorAnika Henke <anika@selfthinker.org>2012-06-29 17:51:09 +0100
committerAnika Henke <anika@selfthinker.org>2012-06-29 17:51:09 +0100
commit0c06a181819249c6a4a2a6c60e13f739df1f2253 (patch)
tree859377c572d0acbfc520b02304ef515bf3aebbe0 /_test/core/TestRequest.php
parentef7e36e4fd2a168977754f0aac1d855fb651f104 (diff)
parent5d0aaf958325f500ce69cfb79e69eb0d8f83fdeb (diff)
downloadrpg-0c06a181819249c6a4a2a6c60e13f739df1f2253.tar.gz
rpg-0c06a181819249c6a4a2a6c60e13f739df1f2253.tar.bz2
Merge branch 'master' of github.com:splitbrain/dokuwiki into frontend_improvements
Conflicts: lib/tpl/dokuwiki/css/basic.css
Diffstat (limited to '_test/core/TestRequest.php')
-rw-r--r--_test/core/TestRequest.php87
1 files changed, 87 insertions, 0 deletions
diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php
new file mode 100644
index 000000000..66760b1e0
--- /dev/null
+++ b/_test/core/TestRequest.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Simulates a full DokuWiki HTTP Request and allows
+ * 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 {
+
+ private $server = array();
+ private $session = array();
+ private $get = array();
+ private $post = array();
+
+ public function getServer($key) { return $this->server[$key]; }
+ public function getSession($key) { return $this->session[$key]; }
+ public function getGet($key) { return $this->get[$key]; }
+ public function getPost($key) { return $this->post[$key]; }
+
+ public function setServer($key, $value) { $this->server[$key] = $value; }
+ public function setSession($key, $value) { $this->session[$key] = $value; }
+ public function setGet($key, $value) { $this->get[$key] = $value; }
+ public function setPost($key, $value) { $this->post[$key] = $value; }
+
+ /**
+ * Executes the request
+ *
+ * @return TestResponse the resulting output of the request
+ */
+ public function execute() {
+ // save old environment
+ $server = $_SERVER;
+ $session = $_SESSION;
+ $get = $_GET;
+ $post = $_POST;
+ $request = $_REQUEST;
+
+ // import all defined globals into the function scope
+ foreach(array_keys($GLOBALS) as $glb){
+ global $$glb;
+ }
+
+ // 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 = '';
+
+ // now execute dokuwiki and grep the output
+ header_remove();
+ ob_start('ob_start_callback');
+ include(DOKU_INC.'doku.php');
+ ob_end_flush();
+
+ // create the response object
+ $response = new TestResponse(
+ $output_buffer,
+ headers_list()
+ );
+
+ // reset environment
+ $_SERVER = $server;
+ $_SESSION = $session;
+ $_GET = $get;
+ $_POST = $post;
+ $_REQUEST = $request;
+
+ return $response;
+ }
+}