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

Commit

Permalink
Merge branch 'hotfix/78'
Browse files Browse the repository at this point in the history
Close #78
  • Loading branch information
weierophinney committed Jul 26, 2016
2 parents 7f44bbe + 50d0841 commit 448a456
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.3.3 - TBD
## 1.3.3 - 2016-07-26

### Added

Expand All @@ -18,7 +18,12 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#78](https://github.com/zfcampus/zf-content-validation/pull/78) updates
`ContentValidationListener::isCollection()` to check strictly for absence of
an identifier when determining if a collection was requested. Previously, a
`0` identifier would be incorrectly flagged as a request for a collection,
which would pull the collection input filter instead of the entity input
filter.

## 1.3.2 - 2016-07-21

Expand Down
2 changes: 1 addition & 1 deletion src/ContentValidationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ protected function isCollection($serviceName, $data, $matches, HttpRequest $requ
}

$identifierName = $this->restControllers[$serviceName];
if ($matches->getParam($identifierName)) {
if ($matches->getParam($identifierName) !== null) {
return false;
}

Expand Down
100 changes: 100 additions & 0 deletions test/ContentValidationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerInterface;
use Zend\Http\Request as HttpRequest;
use Zend\InputFilter\CollectionInputFilter;
use Zend\InputFilter\Factory as InputFilterFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterInterface;
Expand Down Expand Up @@ -500,6 +501,105 @@ public function testAllowsValidationOfPartialSetsForPatchRequests()
$this->assertNull($listener->onRoute($event));
}

/**
* @dataProvider listMethods
*/
public function testPatchWithZeroRouteIdDoesNotEmitANoticeAndDoesNotHaveCollectionInputFilterWhenRequestHasABody(
$verb
) {
$services = new ServiceManager();
$factory = new InputFilterFactory();
$services->setService(
'FooValidator',
$factory->createInputFilter(
[
'foo' => [
'name' => 'foo',
'required' => false,
],
]
)
);
$listener = new ContentValidationListener(
[
'Foo' => ['input_filter' => 'FooValidator'],
],
$services,
[
'Foo' => 'foo_id',
]
);

$request = new HttpRequest();
$request->setMethod($verb);

$matches = $this->createRouteMatch(['controller' => 'Foo']);
$matches->setParam('foo_id', "0");

$dataParams = new ParameterDataContainer();
$dataParams->setBodyParams(
[
'foo' => 123,
]
);

$event = new MvcEvent();
$event->setRequest($request);
$event->setRouteMatch($matches);
$event->setParam('ZFContentNegotiationParameterData', $dataParams);

$this->assertNull($listener->onRoute($event));
$inputFilter = $event->getParam('ZF\ContentValidation\InputFilter');
// with notices on, this won't get hit with broken code
$this->assertNotInstanceOf(CollectionInputFilter::class, $inputFilter);
}

/**
* @dataProvider listMethods
*/
public function testPatchWithZeroRouteIdWithNoRequestBodyDoesNotHaveCollectionInputFilter($verb)
{
$services = new ServiceManager();
$factory = new InputFilterFactory();
$services->setService(
'FooValidator',
$factory->createInputFilter(
[
'foo' => [
'name' => 'foo',
'required' => false,
],
]
)
);
$listener = new ContentValidationListener(
[
'Foo' => ['input_filter' => 'FooValidator'],
],
$services,
[
'Foo' => 'foo_id',
]
);

$request = new HttpRequest();
$request->setMethod($verb);

$matches = $this->createRouteMatch(['controller' => 'Foo']);
$matches->setParam('foo_id', "0");

$dataParams = new ParameterDataContainer();
$dataParams->setBodyParams([]);

$event = new MvcEvent();
$event->setRequest($request);
$event->setRouteMatch($matches);
$event->setParam('ZFContentNegotiationParameterData', $dataParams);
$this->assertNull($listener->onRoute($event));
$inputFilter = $event->getParam('ZF\ContentValidation\InputFilter');
$this->assertNotInstanceOf(CollectionInputFilter::class, $inputFilter);
}

public function testFailsValidationOfPartialSetsForPatchRequestsThatIncludeUnknownInputs()
{
$services = new ServiceManager();
Expand Down

0 comments on commit 448a456

Please sign in to comment.