From 25390a33a98f91f4443545a733606c2acdbba974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Mart=C3=ADn?= Date: Thu, 9 Mar 2017 19:39:14 +0100 Subject: [PATCH] Enum titles under field schema, not liform subarray (#fix Limenius/liform-react#7) --- .../Liform/Transformer/ChoiceTransformer.php | 2 +- .../Transformer/ChoiceTransformerTest.php | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php diff --git a/src/Limenius/Liform/Transformer/ChoiceTransformer.php b/src/Limenius/Liform/Transformer/ChoiceTransformer.php index b1f3670..3cc707d 100644 --- a/src/Limenius/Liform/Transformer/ChoiceTransformer.php +++ b/src/Limenius/Liform/Transformer/ChoiceTransformer.php @@ -52,7 +52,7 @@ public function transform(FormInterface $form, $extensions = [], $widget = null) } else { $schema = [ 'enum' => $choices, - 'liform' => ['enum_titles' => $titles], + 'enum_titles' => $titles, 'type' => 'string', ]; } diff --git a/tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php b/tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php new file mode 100644 index 0000000..d0666a2 --- /dev/null +++ b/tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php @@ -0,0 +1,44 @@ +factory->create(FormType::class) + ->add( + 'firstName', + Type\ChoiceType::class, + [ + 'choices' => ['a' => 'A', 'b' => 'B'], + ] + ); + $resolver = new Resolver(); + $resolver->setTransformer('choice', new Transformer\ChoiceTransformer()); + $transformer = new CompoundTransformer($resolver); + $transformed = $transformer->transform($form); + $this->assertTrue(is_array($transformed)); + $this->assertArrayHasKey('enum_titles', $transformed['properties']['firstName']); + $this->assertEquals(['a', 'b'], $transformed['properties']['firstName']['enum_titles']); + $this->assertArrayHasKey('enum', $transformed['properties']['firstName']); + $this->assertEquals(['A', 'B'], $transformed['properties']['firstName']['enum']); + } +}