File tree Expand file tree Collapse file tree 4 files changed +44
-4
lines changed
src/Kris/LaravelFormBuilder/Fields Expand file tree Collapse file tree 4 files changed +44
-4
lines changed Original file line number Diff line number Diff line change 77 convertWarningsToExceptions =" true"
88 processIsolation =" false"
99 stopOnFailure =" false"
10- syntaxCheck = " false " >
10+ >
1111 <testsuites >
1212 <testsuite name =" Package Test Suite" >
1313 <directory suffix =" .php" >./tests/</directory >
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ protected function setupValue()
145145 if ($ this instanceof EntityType) {
146146 $ attributeName = $ this ->name ;
147147 } else {
148- $ attributeName = $ this ->getOption ('property ' , $ this ->name );
148+ $ attributeName = $ this ->getOption ('value_property ' , $ this ->name );
149149 }
150150
151151 $ this ->setValue ($ this ->getModelValueAttribute ($ this ->parent ->getModel (), $ attributeName ));
Original file line number Diff line number Diff line change @@ -139,6 +139,25 @@ public function it_creates_collection_with_child_form_with_correct_model()
139139 }
140140 }
141141
142+ /** @test */
143+ public function it_creates_collection_with_child_form_with_correct_model_properties ()
144+ {
145+ $ items = new \Illuminate \Support \Collection ([
146+ (new DummyEloquentModel2 ())->forceFill (['id ' => 1 , 'foo ' => 'bar ' ]),
147+ (new DummyEloquentModel2 ())->forceFill (['id ' => 2 , 'foo ' => 'baz ' ]),
148+ ]);
149+
150+ $ model = (new DummyEloquentModel ())->forceFill (['id ' => 11 ]);
151+ $ model ->setRelation ('items ' , $ items );
152+
153+ $ form = $ this ->formBuilder ->create ('\LaravelFormBuilderCollectionTypeTest\Forms\NamespacedDummyFormCollectionForm ' , [
154+ 'model ' => $ model ,
155+ ]);
156+
157+ $ collectionValue = $ form ->getField ('items ' )->getOption ('data ' );
158+ $ this ->assertEquals ($ items , $ collectionValue );
159+ }
160+
142161 /**
143162 * @test
144163 */
@@ -227,4 +246,25 @@ class DummyEloquentModel2 extends Model {
227246 class NamespacedDummyForm extends Form
228247 {
229248 }
249+
250+ class NamespacedDummyFormCollectionChildForm extends Form
251+ {
252+ function buildForm ()
253+ {
254+ $ this ->add ('foo ' , 'text ' );
255+ }
256+ }
257+
258+ class NamespacedDummyFormCollectionForm extends Form
259+ {
260+ function buildForm ()
261+ {
262+ $ this ->add ('items ' , 'collection ' , [
263+ 'type ' => 'form ' ,
264+ 'options ' => [
265+ 'class ' => NamespacedDummyFormCollectionChildForm::class,
266+ ],
267+ ]);
268+ }
269+ }
230270}
Original file line number Diff line number Diff line change @@ -468,7 +468,7 @@ public function it_can_take_and_replace_existing_fields()
468468 $ this ->plainForm ->only ('remember ' , 'name ' );
469469
470470 $ this ->assertEquals (2 , count ($ this ->plainForm ->getFields ()));
471-
471+
472472 $ this ->assertTrue ($ this ->plainForm ->has ('remember ' ));
473473 $ this ->assertTrue ($ this ->plainForm ->has ('name ' ));
474474 $ this ->assertFalse ($ this ->plainForm ->has ('description ' ));
@@ -788,7 +788,7 @@ public function it_can_use_model_property_to_set_value()
788788 ]);
789789
790790 $ form ->add ('alias_accessor ' , 'choice ' , [
791- 'property ' => 'accessor ' ,
791+ 'value_property ' => 'accessor ' ,
792792 ]);
793793
794794 $ this ->assertEquals ($ form ->alias_accessor ->getValue (), $ this ->model ->accessor );
You can’t perform that action at this time.
0 commit comments