|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Knp\RadBundle\Form; |
|
4
|
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
|
|
7
|
|
|
class DefaultFormCreatorSpec extends ObjectBehavior |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param Knp\RadBundle\Reflection\ClassMetadataFetcher $fetcher |
|
11
|
|
|
* @param Symfony\Component\Form\FormFactoryInterface $factory |
|
12
|
|
|
* @param Knp\RadBundle\Form\DataTypeGuesser $dataTypeGuesser |
|
13
|
|
|
*/ |
|
14
|
|
|
function let($fetcher, $factory, $dataTypeGuesser) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->beConstructedWith($fetcher, $factory, $dataTypeGuesser); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param stdClass $object |
|
21
|
|
|
* @param Symfony\Component\Form\FormFactoryInterface $factory |
|
22
|
|
|
* @param Knp\RadBundle\Reflection\ClassMetadataFetcher $fetcher |
|
23
|
|
|
* @param Symfony\Component\Form\FormBuilder $builder |
|
24
|
|
|
* @param Symfony\Component\Form\Form $form |
|
25
|
|
|
* @param Symfony\Component\Form\Form $subForm1 |
|
26
|
|
|
* @param Symfony\Component\Form\Form $subForm2 |
|
27
|
|
|
* @param Symfony\Component\Form\FormEvent $formEvent |
|
28
|
|
|
*/ |
|
29
|
|
|
function it_should_create_form_based_on_object_mutators($object, $factory, $fetcher, $builder, $form, $formEvent, $subForm1, $subForm2) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$fetcher->getProperties($object)->willReturn(array()); |
|
32
|
|
|
$fetcher->getMethods($object)->willReturn(array( |
|
33
|
|
|
'getName', 'setName', |
|
34
|
|
|
'isAdmin', 'setAdmin', |
|
35
|
|
|
'getId', 'foo', |
|
36
|
|
|
)); |
|
37
|
|
|
$fetcher->hasMethod($object, 'setName')->willReturn(true); |
|
38
|
|
|
$fetcher->hasMethod($object, 'setAdmin')->willReturn(true); |
|
39
|
|
|
$fetcher->hasMethod($object, 'setId')->willReturn(false); |
|
40
|
|
|
$factory->createBuilder('form', $object, array())->willReturn($builder)->shouldBeCalled(); |
|
41
|
|
|
|
|
42
|
|
|
$formEvent->getData()->willReturn($object); |
|
43
|
|
|
$formEvent->getForm()->willReturn($form); |
|
44
|
|
|
|
|
45
|
|
|
$factory->createForProperty(\Prophecy\Argument::any(), 'name', null, array('auto_initialize' => false))->shouldBeCalled()->willReturn($subForm1); |
|
46
|
|
|
$factory->createForProperty(\Prophecy\Argument::any(), 'admin', null, array('auto_initialize' => false))->shouldBeCalled()->willReturn($subForm2); |
|
47
|
|
|
$factory->createForProperty(\Prophecy\Argument::any(), 'id', null, array('auto_initialize' => false))->shouldNotBeCalled(); |
|
48
|
|
|
|
|
49
|
|
|
$form->add($subForm1)->shouldBeCalled(); |
|
50
|
|
|
$form->add($subForm2)->shouldBeCalled(); |
|
51
|
|
|
|
|
52
|
|
|
$this->preSetData($formEvent); |
|
53
|
|
|
|
|
54
|
|
|
$builder->addEventSubscriber($this)->shouldBeCalled(); |
|
55
|
|
|
$builder->getForm()->willReturn($form); |
|
56
|
|
|
|
|
57
|
|
|
$this->create($object)->shouldReturn($form); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param stdClass $object |
|
62
|
|
|
* @param Symfony\Component\Form\FormFactoryInterface $factory |
|
63
|
|
|
* @param Knp\RadBundle\Reflection\ClassMetadataFetcher $fetcher |
|
64
|
|
|
* @param Symfony\Component\Form\FormBuilder $builder |
|
65
|
|
|
* @param Symfony\Component\Form\Form $form |
|
66
|
|
|
* @param Symfony\Component\Form\Form $subForm1 |
|
67
|
|
|
* @param Symfony\Component\Form\Form $subForm2 |
|
68
|
|
|
* @param Symfony\Component\Form\FormEvent $formEvent |
|
69
|
|
|
*/ |
|
70
|
|
|
public function it_should_create_form_based_on_object_properties($object, $factory, $fetcher, $builder, $form, $formEvent, $subForm1, $subForm2) |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
$fetcher->getMethods($object)->willReturn(array()); |
|
73
|
|
|
$fetcher->getProperties($object)->willReturn(array( |
|
74
|
|
|
'termOfService', 'locked', |
|
75
|
|
|
)); |
|
76
|
|
|
$factory->createBuilder('form', $object, array())->willReturn($builder)->shouldBeCalled(); |
|
77
|
|
|
|
|
78
|
|
|
$formEvent->getData()->willReturn($object); |
|
79
|
|
|
$formEvent->getForm()->willReturn($form->getWrappedObject()); |
|
80
|
|
|
|
|
81
|
|
|
$factory->createForProperty(\Prophecy\Argument::any(), 'termOfService', null, array('auto_initialize' => false))->shouldBeCalled()->willReturn($subForm1); |
|
82
|
|
|
$factory->createForProperty(\Prophecy\Argument::any(), 'locked', null, array('auto_initialize' => false))->shouldBeCalled()->willReturn($subForm2); |
|
83
|
|
|
|
|
84
|
|
|
$form->add($subForm1)->shouldBeCalled(); |
|
85
|
|
|
$form->add($subForm2)->shouldBeCalled(); |
|
86
|
|
|
|
|
87
|
|
|
$this->preSetData($formEvent); |
|
88
|
|
|
|
|
89
|
|
|
$builder->getForm()->willReturn($form); |
|
90
|
|
|
$builder->addEventSubscriber($this)->shouldBeCalled(); |
|
91
|
|
|
|
|
92
|
|
|
$this->create($object)->shouldReturn($form); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|