Skip to content
Browse files

Merge branch 'hotfix/patch-collection-selection'

Close #19
  • Loading branch information...
2 parents 3270434 + 1261a05 commit ca88631605304d51551640e69f5454723b1913a2 @weierophinney weierophinney committed Jul 18, 2014
Showing with 60 additions and 1 deletion.
  1. +1 −1 src/ContentValidationListener.php
  2. +59 −0 test/ContentValidationListenerTest.php
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());
+ }
}

0 comments on commit ca88631

Please sign in to comment.
Something went wrong with that request. Please try again.