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

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6472-always-clear-in…
Browse files Browse the repository at this point in the history
…puts-before-populating-inputfilter' into develop

Forward port zendframework/zendframework#6472
  • Loading branch information
Ocramius committed Aug 6, 2014
3 parents 7431896 + 04fac49 + 816c8d3 commit 2bffeca
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,15 @@ protected function populate()
foreach (array_keys($this->inputs) as $name) {
$input = $this->inputs[$name];

if ($input instanceof CollectionInputFilter) {
$input->clearValues();
$input->clearRawValues();
}

if (!isset($this->data[$name])) {
// No value; clear value in this input
if ($input instanceof InputFilterInterface) {
$input->setData(array());
if ($input instanceof CollectionInputFilter) {
$input->clearValues();
$input->clearRawValues();
}
continue;
}

Expand Down
65 changes: 65 additions & 0 deletions test/CollectionInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,69 @@ public function testNestedCollectionWithEmptyData()
$values = $inputFilter->getValues();
$this->assertEquals($data, $values);
}

/**
* @group 6472
*/
public function testNestedCollectionWhereChildDataIsNotOverwritten()
{
$items_inputfilter = new BaseInputFilter();
$items_inputfilter->add(new Input(), 'id')
->add(new Input(), 'type');
$items = new CollectionInputFilter();
$items->setInputFilter($items_inputfilter);

$groups_inputfilter = new BaseInputFilter();
$groups_inputfilter->add(new Input(), 'group_class')
->add($items, 'items');
$groups = new CollectionInputFilter();
$groups->setInputFilter($groups_inputfilter);

$inputFilter = new BaseInputFilter();
$inputFilter->add($groups, 'groups');

$data = array(
'groups' => array(
array(
'group_class' => 'bar',
'items' => array(
array(
'id' => 100,
'type' => 'item-100',
),
array(
'id' => 101,
'type' => 'item-101',
),
array(
'id' => 102,
'type' => 'item-102',
),
array(
'id' => 103,
'type' => 'item-103',
),
),
),
array(
'group_class' => 'foo',
'items' => array(
array(
'id' => 200,
'type' => 'item-200',
),
array(
'id' => 201,
'type' => 'item-201',
),
),
),
),
);

$inputFilter->setData($data);
$inputFilter->isValid();
$values = $inputFilter->getValues();
$this->assertEquals($data, $values);
}
}

0 comments on commit 2bffeca

Please sign in to comment.