Skip to content
This repository

Hotfix/restful head identifier #3671

Merged
merged 2 commits into from over 1 year ago

2 participants

Matthew Weier O'Phinney Enrico Zimuel
Matthew Weier O'Phinney

Fixes an issue reported by andrer in zftalk.dev (IRC). Essentially, HEAD calls with an identifier were always resetting the identifier to null, which meant that head() was never being called with the identifier. This patch (a) fixes the test to properly show that the identifier should be passed, and (b) fixes the issue.

Matthew Weier O'Phinney weierophinney Do not reset $id if found
- Pointed out by andrer in #zftalk.dev
50f99fa
Matthew Weier O'Phinney weierophinney Write test for HEAD behavior with identifier
- Wrote test to prove that HEAD is being called with identifier when
  found; failed before change, and works afterwards
22046e2
Enrico Zimuel ezimuel merged commit 22046e2 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Feb 05, 2013
Matthew Weier O'Phinney weierophinney Do not reset $id if found
- Pointed out by andrer in #zftalk.dev
50f99fa
Matthew Weier O'Phinney weierophinney Write test for HEAD behavior with identifier
- Wrote test to prove that HEAD is being called with identifier when
  found; failed before change, and works afterwards
22046e2
This page is out of date. Refresh to see the latest.
2  library/Zend/Mvc/Controller/AbstractRestfulController.php
@@ -281,7 +281,7 @@ public function onDispatch(MvcEvent $e)
281 281 // HEAD
282 282 case 'head':
283 283 $id = $this->getIdentifier($routeMatch, $request);
284   - if ($id !== false) {
  284 + if ($id === false) {
285 285 $id = null;
286 286 }
287 287 $action = 'head';
5 tests/ZendTest/Mvc/Controller/RestfulControllerTest.php
@@ -193,6 +193,11 @@ public function testDispatchInvokesHeadMethodWhenNoActionPresentAndHeadInvokedWi
193 193 $content = $result->getContent();
194 194 $this->assertEquals('', $content);
195 195 $this->assertEquals('head', $this->routeMatch->getParam('action'));
  196 +
  197 + $headers = $this->controller->getResponse()->getHeaders();
  198 + $this->assertTrue($headers->has('X-ZF2-Id'));
  199 + $header = $headers->get('X-ZF2-Id');
  200 + $this->assertEquals(1, $header->getFieldValue());
196 201 }
197 202
198 203 public function testAllowsRegisteringCustomHttpMethodsWithHandlers()
3  tests/ZendTest/Mvc/Controller/TestAsset/RestfulTestController.php
@@ -81,6 +81,9 @@ public function getList()
81 81 */
82 82 public function head($id = null)
83 83 {
  84 + if ($id) {
  85 + $this->getResponse()->getHeaders()->addHeaderLine('X-ZF2-Id', $id);
  86 + }
84 87 }
85 88
86 89 /**

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.