From be83077c26cc5cfb732fd50dd6b256b3ac603a18 Mon Sep 17 00:00:00 2001 From: Konstantin Kudryashov Date: Thu, 1 Mar 2012 11:59:03 +0100 Subject: [PATCH] refactored send definitions --- Behat/CommonContexts/WebApiContext.php | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Behat/CommonContexts/WebApiContext.php b/Behat/CommonContexts/WebApiContext.php index 80007eb..6c8ec20 100644 --- a/Behat/CommonContexts/WebApiContext.php +++ b/Behat/CommonContexts/WebApiContext.php @@ -102,7 +102,7 @@ public function iSendARequestWithValues($method, $url, TableNode $post) } /** - * Sends HTTP request to specific URL with body from PyString. + * Sends HTTP request to specific URL with raw body from PyString. * * @param string $method request method * @param string $url relative url @@ -115,6 +115,33 @@ public function iSendARequestWithBody($method, $url, PyStringNode $string) $url = $this->baseUrl.'/'.ltrim($this->replacePlaceHolder($url), '/'); $string = $this->replacePlaceHolder(trim($string)); + switch ($method) { + case 'POST': + $this->browser->call($url, Request::METHOD_POST, array(), $string); + break; + case 'PUT': + $this->browser->call($url, Request::METHOD_PUT, array(), $string); + break; + case 'DELETE': + $this->browser->call($url, Request::METHOD_DELETE, array(), $string); + break; + } + } + + /** + * Sends HTTP request to specific URL with form data from PyString. + * + * @param string $method request method + * @param string $url relative url + * @param PyStringNode $string request body + * + * @When /^(?:I )?send a (POST|PUT|DELETE) request to "([^"]+)" with form data:$/ + */ + public function iSendARequestWithFormData($method, $url, PyStringNode $string) + { + $url = $this->baseUrl.'/'.ltrim($this->replacePlaceHolder($url), '/'); + $string = $this->replacePlaceHolder(trim($string)); + parse_str(implode('&', explode("\n", $string)), $fields); switch ($method) {