diff --git a/phpunit.xml b/phpunit.xml index 1a577df0..65aa2180 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false"> + > ./tests/ diff --git a/src/Kris/LaravelFormBuilder/Fields/FormField.php b/src/Kris/LaravelFormBuilder/Fields/FormField.php index 685628a2..93df2824 100644 --- a/src/Kris/LaravelFormBuilder/Fields/FormField.php +++ b/src/Kris/LaravelFormBuilder/Fields/FormField.php @@ -145,7 +145,7 @@ protected function setupValue() if ($this instanceof EntityType) { $attributeName = $this->name; } else { - $attributeName = $this->getOption('property', $this->name); + $attributeName = $this->getOption('value_property', $this->name); } $this->setValue($this->getModelValueAttribute($this->parent->getModel(), $attributeName)); diff --git a/tests/Fields/CollectionTypeTest.php b/tests/Fields/CollectionTypeTest.php index e0da9599..dea8db55 100644 --- a/tests/Fields/CollectionTypeTest.php +++ b/tests/Fields/CollectionTypeTest.php @@ -139,6 +139,25 @@ public function it_creates_collection_with_child_form_with_correct_model() } } + /** @test */ + public function it_creates_collection_with_child_form_with_correct_model_properties() + { + $items = new \Illuminate\Support\Collection([ + (new DummyEloquentModel2())->forceFill(['id' => 1, 'foo' => 'bar']), + (new DummyEloquentModel2())->forceFill(['id' => 2, 'foo' => 'baz']), + ]); + + $model = (new DummyEloquentModel())->forceFill(['id' => 11]); + $model->setRelation('items', $items); + + $form = $this->formBuilder->create('\LaravelFormBuilderCollectionTypeTest\Forms\NamespacedDummyFormCollectionForm', [ + 'model' => $model, + ]); + + $collectionValue = $form->getField('items')->getOption('data'); + $this->assertEquals($items, $collectionValue); + } + /** * @test */ @@ -227,4 +246,25 @@ class DummyEloquentModel2 extends Model { class NamespacedDummyForm extends Form { } + + class NamespacedDummyFormCollectionChildForm extends Form + { + function buildForm() + { + $this->add('foo', 'text'); + } + } + + class NamespacedDummyFormCollectionForm extends Form + { + function buildForm() + { + $this->add('items', 'collection', [ + 'type' => 'form', + 'options' => [ + 'class' => NamespacedDummyFormCollectionChildForm::class, + ], + ]); + } + } } diff --git a/tests/FormTest.php b/tests/FormTest.php index b4be3132..710083b7 100644 --- a/tests/FormTest.php +++ b/tests/FormTest.php @@ -468,7 +468,7 @@ public function it_can_take_and_replace_existing_fields() $this->plainForm->only('remember', 'name'); $this->assertEquals(2, count($this->plainForm->getFields())); - + $this->assertTrue($this->plainForm->has('remember')); $this->assertTrue($this->plainForm->has('name')); $this->assertFalse($this->plainForm->has('description')); @@ -788,7 +788,7 @@ public function it_can_use_model_property_to_set_value() ]); $form->add('alias_accessor', 'choice', [ - 'property' => 'accessor', + 'value_property' => 'accessor', ]); $this->assertEquals($form->alias_accessor->getValue(), $this->model->accessor);