diff options
author | Anika Henke <anika@selfthinker.org> | 2013-06-02 23:14:12 +0100 |
---|---|---|
committer | Anika Henke <anika@selfthinker.org> | 2013-06-02 23:14:12 +0100 |
commit | 20beef63b4694afdc3d6c434c3d27c982b6a986b (patch) | |
tree | 9800833361010fe16a2f25a2b2e75a1b569f39f8 /_test/core/TestResponse.php | |
parent | bc1e9ee1b1fffcb554afced8504270032c97341f (diff) | |
parent | 21c9604e66bcb42ab5267e9873738a6e22250103 (diff) | |
download | rpg-20beef63b4694afdc3d6c434c3d27c982b6a986b.tar.gz rpg-20beef63b4694afdc3d6c434c3d27c982b6a986b.tar.bz2 |
Merge remote-tracking branch 'origin/master' into loggedin-class
Diffstat (limited to '_test/core/TestResponse.php')
-rw-r--r-- | _test/core/TestResponse.php | 38 |
1 files changed, 38 insertions, 0 deletions
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 |