Skip to content

Commit 8a9f467

Browse files
author
Sagrario Meneses
committed
[ALICE-1062] Added test for creating form with help messages.
1 parent dbf54f8 commit 8a9f467

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Tests/Form/FormFactoryTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
2323
* @var ObjectProphecy
2424
*/
2525
protected $formFactoryMock;
26+
2627
/**
2728
* @expectedException \Linio\DynamicFormBundle\Exception\NonExistentFormException
2829
*/
@@ -159,6 +160,51 @@ public function testIsCreatingFormWithTransformers()
159160
$this->assertEquals('foo_form', $actual);
160161
}
161162

163+
public function testIsCreatingFormWithHelpMessages()
164+
{
165+
$formConfiguration = [
166+
'foo' => [
167+
'field1' => [
168+
'enabled' => true,
169+
'type' => 'field1_type',
170+
'help_message_provider' => 'cache',
171+
'options' => [
172+
'help' => 'cms:message',
173+
],
174+
],
175+
],
176+
];
177+
178+
$helpMessageProviderMock = $this->prophesize('Linio\DynamicFormBundle\HelpMessageProvider');
179+
180+
$helpMessageProviderMock->getHelpMessage('cms:message')
181+
->shouldBeCalled()
182+
->willReturn('message');
183+
184+
$this->formFactoryMock->createNamedBuilder('foo', 'form', ['foo_form_data'], $formConfiguration)
185+
->shouldBeCalled()
186+
->willReturn($this->formBuilderMock->reveal());
187+
188+
$this->formBuilderMock->create('field1', 'field1_type', ['help' => 'message'])
189+
->shouldBeCalled()
190+
->willReturn('field1_instance');
191+
192+
$this->formBuilderMock->add('field1_instance')
193+
->shouldBeCalled();
194+
195+
$this->formBuilderMock->getForm()
196+
->shouldBeCalled()
197+
->willReturn('foo_form');
198+
199+
$this->formFactory->setFormFactory($this->formFactoryMock->reveal());
200+
$this->formFactory->setConfiguration($formConfiguration);
201+
$this->formFactory->addHelpMessageProvider('cache', $helpMessageProviderMock->reveal());
202+
203+
$actual = $this->formFactory->createForm('foo', ['foo_form_data'], $formConfiguration);
204+
205+
$this->assertEquals('foo_form', $actual);
206+
}
207+
162208
public function testIsGettingConfiguration()
163209
{
164210
$configuration = [
@@ -242,12 +288,15 @@ class MockTransformer implements DataTransformerInterface
242288
public function setUserFormat()
243289
{
244290
}
291+
245292
public function setInputFormat()
246293
{
247294
}
295+
248296
public function transform($value)
249297
{
250298
}
299+
251300
public function reverseTransform($value)
252301
{
253302
}

0 commit comments

Comments
 (0)