diff options
Diffstat (limited to '_testing/core/TestRequest.php')
-rw-r--r-- | _testing/core/TestRequest.php | 67 |
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); + } +} |