Skip to content

Commit

Permalink
Merge pull request #147 from zf-fr/pass-context
Browse files Browse the repository at this point in the history
Allow to pass resource as context to input filter
  • Loading branch information
bakura10 committed Apr 19, 2014
2 parents a025c25 + 0e9e74d commit 335a424
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function validateData(ResourceInterface $resource, array $data, AbstractR
$inputFilter = $controller->getInputFilter($this->inputFilterPluginManager, $inputFilterName);
$inputFilter->setData($data);

if (!$inputFilter->isValid()) {
$validationContext = $resource->getData();

if (!$inputFilter->isValid($validationContext)) {
throw new UnprocessableEntityException(
'Validation error',
$this->formatErrorMessages($inputFilter->getMessages())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public function testCanValidateData()
{
$resource = $this->getMock('ZfrRest\Resource\ResourceInterface');
$metadata = $this->getMock('ZfrRest\Resource\Metadata\ResourceMetadataInterface');
$context = new \stdClass;

$resource->expects($this->once())->method('getData')->will($this->returnValue($context));
$resource->expects($this->once())->method('getMetadata')->will($this->returnValue($metadata));
$metadata->expects($this->once())->method('getInputFilterName')->will($this->returnValue('inputFilter'));

Expand All @@ -76,6 +78,7 @@ public function testCanValidateData()
$inputFilter->expects($this->once())->method('setData')->with($data);
$inputFilter->expects($this->once())
->method('isValid')
->with($context)
->will($this->returnValue(true));

$inputFilter->expects($this->once())
Expand Down

0 comments on commit 335a424

Please sign in to comment.