diff options
author | Christopher Smith <chris@jalakai.co.uk> | 2013-03-22 18:01:45 +0000 |
---|---|---|
committer | Christopher Smith <chris@jalakai.co.uk> | 2013-03-22 18:01:45 +0000 |
commit | fb0b3fbf03223c8c304608cdb32ee5c9d755eca1 (patch) | |
tree | 4a417efffa52bcb536dbc9846c9623c3e560ed54 /_test/core | |
parent | 9894e7afaae16cc0699afbe839681e023afee65a (diff) | |
download | rpg-fb0b3fbf03223c8c304608cdb32ee5c9d755eca1.tar.gz rpg-fb0b3fbf03223c8c304608cdb32ee5c9d755eca1.tar.bz2 |
update TestResponse class to return specific headers & status codes (with tests)
Diffstat (limited to '_test/core')
-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 |