summaryrefslogtreecommitdiff
path: root/_test/core
diff options
context:
space:
mode:
authorAnika Henke <anika@selfthinker.org>2013-06-02 23:14:12 +0100
committerAnika Henke <anika@selfthinker.org>2013-06-02 23:14:12 +0100
commit20beef63b4694afdc3d6c434c3d27c982b6a986b (patch)
tree9800833361010fe16a2f25a2b2e75a1b569f39f8 /_test/core
parentbc1e9ee1b1fffcb554afced8504270032c97341f (diff)
parent21c9604e66bcb42ab5267e9873738a6e22250103 (diff)
downloadrpg-20beef63b4694afdc3d6c434c3d27c982b6a986b.tar.gz
rpg-20beef63b4694afdc3d6c434c3d27c982b6a986b.tar.bz2
Merge remote-tracking branch 'origin/master' into loggedin-class
Diffstat (limited to '_test/core')
-rw-r--r--_test/core/TestRequest.php19
-rw-r--r--_test/core/TestResponse.php38
2 files changed, 50 insertions, 7 deletions
diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php
index 172821576..0a54910ed 100644
--- a/_test/core/TestRequest.php
+++ b/_test/core/TestRequest.php
@@ -18,6 +18,9 @@ function ob_start_callback($buffer) {
*/
class TestRequest {
+ private $valid_scripts = array('/doku.php', '/lib/exe/fetch.php', '/lib/exe/detail.php');
+ private $script;
+
private $server = array();
private $session = array();
private $get = array();
@@ -27,6 +30,7 @@ class TestRequest {
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 getScript() { return $this->script; }
public function setServer($key, $value) { $this->server[$key] = $value; }
public function setSession($key, $value) { $this->session[$key] = $value; }
@@ -70,13 +74,13 @@ class TestRequest {
// now execute dokuwiki and grep the output
header_remove();
ob_start('ob_start_callback');
- include(DOKU_INC.'doku.php');
+ include(DOKU_INC.$this->script);
ob_end_flush();
// create the response object
$response = new TestResponse(
$output_buffer,
- headers_list()
+ (function_exists('xdebug_get_headers') ? xdebug_get_headers() : headers_list()) // cli sapi doesn't do headers, prefer xdebug_get_headers() which works under cli
);
// reset environment
@@ -102,14 +106,15 @@ class TestRequest {
* @todo make this work with other end points
*/
protected function setUri($uri){
- if(substr($uri,0,9) != '/doku.php'){
- throw new Exception("only '/doku.php' is supported currently");
+ if(!preg_match('#^('.join('|',$this->valid_scripts).')#',$uri)){
+ throw new Exception("$uri \n--- only ".join(', ',$this->valid_scripts)." are supported currently");
}
$params = array();
list($uri, $query) = explode('?',$uri,2);
if($query) parse_str($query, $params);
+ $this->script = substr($uri,1);
$this->get = array_merge($params, $this->get);
if(count($this->get)){
$query = '?'.http_build_query($this->get, '', '&');
@@ -129,7 +134,7 @@ class TestRequest {
* Simulate a POST request with the given variables
*
* @param array $post all the POST parameters to use
- * @param string $url end URL to simulate, needs to start with /doku.php currently
+ * @param string $url end URL to simulate, needs to start with /doku.php, /lib/exe/fetch.php or /lib/exe/detail.php currently
* @param return TestResponse
*/
public function post($post=array(), $uri='/doku.php') {
@@ -141,8 +146,8 @@ class TestRequest {
/**
* Simulate a GET request with the given variables
*
- * @param array $GET all the POST parameters to use
- * @param string $url end URL to simulate, needs to start with /doku.php currently
+ * @param array $GET all the GET parameters to use
+ * @param string $url end URL to simulate, needs to start with /doku.php, /lib/exe/fetch.php or /lib/exe/detail.php currently
* @param return TestResponse
*/
public function get($get=array(), $uri='/doku.php') {
diff --git a/_test/core/TestResponse.php b/_test/core/TestResponse.php
index 6d20afb28..7cc50ee4f 100644
--- a/_test/core/TestResponse.php
+++ b/_test/core/TestResponse.php
@@ -42,6 +42,44 @@ class TestResponse {
}
/**
+ * @param $name string, the name of the header without the ':', e.g. 'Content-Type', 'Pragma'
+ * @return mixed if exactly one header, the header (string); otherwise an array of headers, empty when no headers
+ */
+ public function getHeader($name) {
+ $result = array();
+ foreach ($this->headers as $header) {
+ if (substr($header,0,strlen($name)+1) == $name.':') {
+ $result[] = $header;
+ }
+ }
+
+ return count($result) == 1 ? $result[0] : $result;
+ }
+
+ /**
+ * @return int http status code
+ *
+ * in the test environment, only status codes explicitly set by dokuwiki are likely to be returned
+ * this means succcessful status codes (e.g. 200 OK) will not be present, but error codes will be
+ */
+ public function getStatusCode() {
+ $headers = $this->getHeader('Status');
+ $code = null;
+
+ if ($headers) {
+ // if there is more than one status header, use the last one
+ $status = is_array($headers) ? array_pop($headers) : $headers;
+ $matches = array();
+ preg_match('/^Status: ?(\d+)/',$status,$matches);
+ if ($matches){
+ $code = $matches[1];
+ }
+ }
+
+ return $code;
+ }
+
+ /**
* Query the response for a JQuery compatible CSS selector
*
* @link https://code.google.com/p/phpquery/wiki/Selectors