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

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/CollectionInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getCount()
*/
public function setData($data)
{
$this->collectionData = array_values($data);
$this->collectionData = $data;
}

/**
Expand All @@ -162,13 +162,16 @@ public function isValid()
return $valid;
}

$inputCollection = array_fill(0, $this->getCount(), $this->validationGroup ?: array_keys($this->inputs));
if (count($this->collectionData) < $this->getCount()) {
$valid = false;
}

foreach ($inputCollection as $key => $inputs) {
$this->data = array();
if (isset($this->collectionData[$key])) {
$this->data = $this->collectionData[$key];
$inputs = $this->validationGroup ?: array_keys($this->inputs);
foreach ($this->collectionData as $key => $data) {
if (!is_array($data)) {
$data = array();
}
$this->data = $data;
$this->populate();

if ($this->validateInputs($inputs)) {
Expand Down
10 changes: 10 additions & 0 deletions test/CollectionInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ public function testCanValidateValidData()
$this->assertTrue($this->filter->isValid());
}

public function testCanValidateValidDataWithNonConsecutiveKeys()
{
$collectionData = $this->getValidCollectionData();
$collectionData[2] = $collectionData[0];
unset($collectionData[0]);
$this->filter->setInputFilter($this->getBaseInputFilter());
$this->filter->setData($collectionData);
$this->assertTrue($this->filter->isValid());
}

public function testInvalidDataReturnsFalse()
{
$invalidCollectionData = array(
Expand Down

0 comments on commit b3e6575

Please sign in to comment.