summaryrefslogtreecommitdiff
path: root/_testing/core/TestRequest.php
diff options
context:
space:
mode:
authorAndreas Gohr <gohr@cosmocode.de>2012-04-17 15:38:03 +0200
committerAndreas Gohr <gohr@cosmocode.de>2012-04-17 15:38:03 +0200
commite048653b52aad13b5964e1626192ffee2211870b (patch)
treed5aaa7168f1496aa8262920ad2320a5d3668b6a5 /_testing/core/TestRequest.php
parentc45ce44912e3e54ecdf0a19af2d7df1960aa2962 (diff)
downloadrpg-e048653b52aad13b5964e1626192ffee2211870b.tar.gz
rpg-e048653b52aad13b5964e1626192ffee2211870b.tar.bz2
moved functions and classes out of bootstrap
There's still more that I'd like to moved out. bootstrap should not contain any logic but only call the appropriate functions for setup the test environment.
Diffstat (limited to '_testing/core/TestRequest.php')
-rw-r--r--_testing/core/TestRequest.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/_testing/core/TestRequest.php b/_testing/core/TestRequest.php
new file mode 100644
index 000000000..f77c494c3
--- /dev/null
+++ b/_testing/core/TestRequest.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Simulates a full DokuWiki HTTP Request and allows
+ * runtime inspection.
+ */
+
+/**
+ * Helper class to execute a fake request
+ */
+class TestRequest {
+
+ /**
+ * Executes the request
+ *
+ * @return TestResponse response
+ */
+ function execute() {
+ 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();
+
+ // 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;
+ }
+
+ 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($pq)) $pq = phpQuery::newDocument($this->content);
+ return pq($selector);
+ }
+}