diff options
author | Andreas Gohr <andi@splitbrain.org> | 2012-06-30 01:24:19 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2012-06-30 01:24:19 +0200 |
commit | 9e777cee116bd29c51b62ccd1c4353cc00014522 (patch) | |
tree | fc2b512ab96aa9d48054fe92156b4a1e2e95701f /_test/core/TestRequest.php | |
parent | 5d0aaf958325f500ce69cfb79e69eb0d8f83fdeb (diff) | |
download | rpg-9e777cee116bd29c51b62ccd1c4353cc00014522.tar.gz rpg-9e777cee116bd29c51b62ccd1c4353cc00014522.tar.bz2 |
simplified using the TestRequest class
You now can call get() or post() on it and give it all the wanted
input variables
Diffstat (limited to '_test/core/TestRequest.php')
-rw-r--r-- | _test/core/TestRequest.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php index 66760b1e0..aeda4b892 100644 --- a/_test/core/TestRequest.php +++ b/_test/core/TestRequest.php @@ -84,4 +84,69 @@ class TestRequest { return $response; } + + /** + * Set the virtual URI the request works against + * + * This parses the given URI and sets any contained GET variables + * but will not overwrite any previously set ones (eg. set via setGet()). + * + * It initializes the $_SERVER['REQUEST_URI'] and $_SERVER['QUERY_STRING'] + * with all set GET variables. + * + * @param string $url end URL to simulate, needs to start with /doku.php currently + */ + public function setUri($uri){ + if(substr($uri,0,9) != '/doku.php'){ + throw new Exception("only '/doku.php' is supported currently"); + } + + $params = array(); + list($uri, $query) = explode('?',$uri,2); + if($query) parse_str($query, $params); + + $this->get = array_merge($params, $this->get); + if(count($this->get)){ + $query = '?'.http_build_query($this->get, '', '&'); + $query = str_replace( + array('%3A', '%5B', '%5D'), + array(':', '[', ']'), + $query + ); + $uri = $uri.$query; + } + + $this->setServer('QUERY_STRING', $query); + $this->setServer('REQUEST_URI', $uri); + } + + /** + * 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 return TestResponse + */ + public function post($post=array(), $uri='/doku.php') { + $this->setUri($uri); + $this->post = array_merge($this->post, $post); + $this->setServer('REQUEST_METHOD', 'POST'); + return $this->execute(); + } + + /** + * 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 return TestResponse + */ + public function get($get=array(), $uri='/doku.php') { + $this->get = array_merge($this->get, $get); + $this->setUri($uri); + $this->setServer('REQUEST_METHOD', 'GET'); + return $this->execute(); + } + + } |