Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

isCollection() method returning true for entities #19

Merged
merged 1 commit into from

1 participant

@weierophinney

As noted on the mailing list, the logic for determining whether to validate an incoming request as a collection or as an entity is currently broken.

The error appears to be on line 306; when the identifier is found in the route matches, we should be returning false.

@weierophinney weierophinney added this to the 1.0.4 milestone
@weierophinney weierophinney added the bug label
@weierophinney weierophinney [#19] Ensure entities are validated as entities, not collections
- When a route match is found for the identifier, then we have an
  entity, not a collection.
1261a05
@weierophinney weierophinney merged commit 1261a05 into from
@weierophinney weierophinney deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 18, 2014
  1. @weierophinney

    [#19] Ensure entities are validated as entities, not collections

    weierophinney authored
    - When a route match is found for the identifier, then we have an
      entity, not a collection.
This page is out of date. Refresh to see the latest.
View
2  src/ContentValidationListener.php
@@ -303,7 +303,7 @@ protected function isCollection($serviceName, $data, RouteMatch $matches, HttpRe
$identifierName = $this->restControllers[$serviceName];
if ($matches->getParam($identifierName)) {
- return true;
+ return false;
}
return (null === $request->getQuery($identifierName, null));
View
59 test/ContentValidationListenerTest.php
@@ -1042,4 +1042,63 @@ public function testIndicatesInvalidPostedEntityWhenCollectionIsPossibleForServi
$this->assertInstanceOf('ZF\ApiProblem\ApiProblemResponse', $response);
$this->assertEquals(422, $response->getApiProblem()->status);
}
+
+ /**
+ * @dataProvider listMethods
+ * @group 19
+ */
+ public function testDoesNotAttemptToValidateAnEntityAsACollection($method)
+ {
+ $services = new ServiceManager();
+ $factory = new InputFilterFactory();
+ $services->setService('FooValidator', $factory->createInputFilter(array(
+ 'foo' => array(
+ 'name' => 'foo',
+ 'validators' => array(
+ array('name' => 'Digits'),
+ ),
+ ),
+ 'bar' => array(
+ 'name' => 'bar',
+ 'validators' => array(
+ array(
+ 'name' => 'Regex',
+ 'options' => array('pattern' => '/^[a-z]+/i'),
+ ),
+ ),
+ ),
+ )));
+
+ // Create ContentValidationListener with rest controllers populated
+ $listener = new ContentValidationListener(array(
+ 'Foo' => array('input_filter' => 'FooValidator'),
+ ), $services, array(
+ 'Foo' => 'foo_id',
+ ));
+
+ $request = new HttpRequest();
+ $request->setMethod($method);
+
+ $matches = new RouteMatch(array(
+ 'controller' => 'Foo',
+ 'foo_id' => uniqid(),
+ ));
+
+ $dataParams = new ParameterDataContainer();
+
+ $params = array(
+ 'foo' => 123,
+ 'bar' => 'abc',
+ );
+
+ $dataParams->setBodyParams($params);
+
+ $event = new MvcEvent();
+ $event->setRequest($request);
+ $event->setRouteMatch($matches);
+ $event->setParam('ZFContentNegotiationParameterData', $dataParams);
+
+ $this->assertNull($listener->onRoute($event));
+ $this->assertNull($event->getResponse());
+ }
}
Something went wrong with that request. Please try again.