Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3916 from blanchonvincent/hotfix/zend-test-and-pu…
Browse files Browse the repository at this point in the history
…t-method

Fix PUT HTTP method usage with params
  • Loading branch information
weierophinney committed Mar 11, 2013
2 parents b0bd47c + 67e46ca commit f720eb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,19 @@ public function url($url, $method = HttpRequest::METHOD_GET, $params = array())

if ($method == HttpRequest::METHOD_POST) {
$post = $params;
}

if ($method == HttpRequest::METHOD_GET) {
} elseif ($method == HttpRequest::METHOD_GET) {
$query = array_merge($query, $params);
} elseif ($method == HttpRequest::METHOD_PUT) {
array_walk($params,
function(&$item, $key) { $item = $key . '=' . $item; }
);
$content = implode('&', $params);
$request->setContent($content);
} elseif ($params) {
trigger_error(
'Additional params is only supported by GET, POST and PUT HTTP method',
E_USER_NOTICE
);
}

$request->setMethod($method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setUp()
);
parent::setUp();
}

public function testUseOfRouter()
{
$this->assertEquals(false, $this->useConsoleRequest);
Expand Down Expand Up @@ -453,7 +453,7 @@ public function testAssertQueryWithDynamicQueryParamsInUrlAnsPostInParams()
$this->assertQueryCount('div.post', 5);
$this->assertXpathQueryCount('//div[@class="post"]', 5);
}

public function testAssertQueryWithDynamicPostParams()
{
$this->getRequest()
Expand All @@ -469,12 +469,22 @@ public function testAssertQueryWithDynamicPostParams()
public function testAssertQueryWithDynamicPostParamsInDispatchMethod()
{
$this->dispatch('/tests', 'POST', array('num_post' => 5));
$request = $this->getRequest();
$this->assertEquals($request->getMethod(), 'POST');
$this->assertQueryCount('div.post', 5);
$this->assertXpathQueryCount('//div[@class="post"]', 5);
$this->assertQueryCount('div.get', 0);
$this->assertXpathQueryCount('//div[@class="get"]', 0);
}


public function testAssertQueryWithDynamicPutParamsInDispatchMethod()
{
$this->dispatch('/tests', 'PUT', array('num_post' => 5, 'foo' => 'bar'));
$request = $this->getRequest();
$this->assertEquals($request->getMethod(), 'PUT');
$this->assertEquals('num_post=5&foo=bar', $request->getContent());
}
/*
public function testAssertUriWithHostname()
{
$this->dispatch('http://my.domain.tld:443');
Expand Down Expand Up @@ -546,7 +556,7 @@ public function testAssertExceptionInAction()
$this->assertResponseStatusCode(500);
$this->assertApplicationException('RuntimeException');
}

/**
* Sample tests on MvcEvent
*/
Expand Down

0 comments on commit f720eb3

Please sign in to comment.