|
25 | 25 | use Laminas\InputFilter\InputFilter; |
26 | 26 | use Laminas\InputFilter\InputFilterInterface; |
27 | 27 | use Laminas\InputFilter\InputInterface; |
| 28 | +use Laminas\Stdlib\PriorityList; |
28 | 29 | use LaminasTest\Form\TestAsset\Entity\Category; |
29 | 30 | use PHPUnit\Framework\Attributes\DataProvider; |
30 | 31 | use PHPUnit\Framework\Attributes\Group; |
@@ -607,6 +608,54 @@ public function testFormWithCollectionAndValidationGroupBindValuesToModel(): voi |
607 | 608 | self::assertFalse(isset($model->foobar)); |
608 | 609 | } |
609 | 610 |
|
| 611 | + public function testFormWithNestedCustomCollectionAndValidationGroupBindValuesToModel(): void |
| 612 | + { |
| 613 | + $model = new stdClass(); |
| 614 | + $data = [ |
| 615 | + 'foo' => 'abcde', |
| 616 | + 'top_level' => [ |
| 617 | + 'categories' => [ |
| 618 | + [ |
| 619 | + 'name' => 'category', |
| 620 | + ], |
| 621 | + ], |
| 622 | + ], |
| 623 | + ]; |
| 624 | + $this->populateForm(); |
| 625 | + |
| 626 | + $collection = self::createStub(CollectionInterface::class); |
| 627 | + $collection->method('getName') |
| 628 | + ->willReturn('categories'); |
| 629 | + $collection->method('getIterator') |
| 630 | + ->willReturn(new PriorityList()); |
| 631 | + $collection->method('getTargetElement') |
| 632 | + ->willReturn(new TestAsset\CategoryFieldset()); |
| 633 | + |
| 634 | + $fieldset = new Fieldset('top_level'); |
| 635 | + $fieldset->add($collection); |
| 636 | + |
| 637 | + $this->form->add($fieldset); |
| 638 | + $this->form->setHydrator(new ObjectPropertyHydrator()); |
| 639 | + $this->form->bind($model); |
| 640 | + $this->form->setData($data); |
| 641 | + $this->form->setValidationGroup([ |
| 642 | + 'foo', |
| 643 | + 'top_level' => [ |
| 644 | + 'categories' => [ |
| 645 | + 'name', |
| 646 | + ], |
| 647 | + ], |
| 648 | + ]); |
| 649 | + $this->form->isValid(); |
| 650 | + |
| 651 | + self::assertTrue(isset($model->top_level)); |
| 652 | + self::assertIsArray($model->top_level); |
| 653 | + self::assertTrue(isset($model->top_level['categories'])); |
| 654 | + self::assertIsArray($model->top_level['categories']); |
| 655 | + self::assertIsArray($model->top_level['categories'][0]); |
| 656 | + self::assertEquals('category', $model->top_level['categories'][0]['name']); |
| 657 | + } |
| 658 | + |
610 | 659 | public function testSettingValidationGroupWithoutCollectionBindsOnlyThoseValuesToModel(): void |
611 | 660 | { |
612 | 661 | $model = new stdClass(); |
|
0 commit comments