Skip to content

Commit

Permalink
Enum titles under field schema, not liform subarray (#fix Limenius/li…
Browse files Browse the repository at this point in the history
  • Loading branch information
nacmartin committed Mar 9, 2017
1 parent 425956a commit 25390a3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Transformer/ChoiceTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
Expand Down
44 changes: 44 additions & 0 deletions tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Limenius\Liform\Tests\Liform\Transformer;

use Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Limenius\Liform\Transformer\CompoundTransformer;
use Limenius\Liform\Transformer;
use Limenius\Liform\Resolver;
use Limenius\Liform\Tests\LiformTestCase;

/**
* Class: ChoiceTransformerTest
*
* @see TypeTestCase
*/
class ChoiceTransformerTest extends LiformTestCase
{

/**
* testPattern
*
*/
public function testPattern()
{
$form = $this->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']);
}
}

0 comments on commit 25390a3

Please sign in to comment.