1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\FormBundle\Tests\Form; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\AdminBundle\Form\MediaTokenTransformer; |
6
|
|
|
use Kunstmaan\AdminBundle\Form\WysiwygType; |
7
|
|
|
use Kunstmaan\FormBundle\Entity\AbstractFormPage; |
8
|
|
|
use Kunstmaan\FormBundle\Form\AbstractFormPageAdminType; |
9
|
|
|
use Symfony\Component\Form\PreloadedExtension; |
10
|
|
|
use Symfony\Component\Form\Test\TypeTestCase; |
11
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
12
|
|
|
|
13
|
|
|
class NonAbstractFormPageAdminType extends AbstractFormPageAdminType |
14
|
|
|
{ |
15
|
|
|
public function configureOptions(OptionsResolver $resolver) |
16
|
|
|
{ |
17
|
|
|
parent::configureOptions($resolver); |
18
|
|
|
$resolver->setDefaults(array( |
19
|
|
|
'data_class' => 'Kunstmaan\FormBundle\Tests\Form\FormPage', |
20
|
|
|
)); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
class FormPage extends AbstractFormPage |
25
|
|
|
{ |
26
|
|
|
public function getPossibleChildTypes() |
27
|
|
|
{ |
28
|
|
|
return null; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getPagePartAdminConfigurations() |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
[ |
35
|
|
|
'name' => 'ContentPage', |
36
|
|
|
'class' => '{{ namespace }}\Entity\Pages\ContentPage', |
37
|
|
|
], |
38
|
|
|
[ |
39
|
|
|
'name' => 'FormPage', |
40
|
|
|
'class' => '{{ namespace }}\Entity\Pages\FormPage', |
41
|
|
|
], |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getDefaultView() |
46
|
|
|
{ |
47
|
|
|
return 'some.twig'; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2012-09-20 at 15:14:43. |
53
|
|
|
*/ |
54
|
|
|
class AbstractFormPageAdminTypeTest extends TypeTestCase |
55
|
|
|
{ |
56
|
|
|
public function testFormType() |
57
|
|
|
{ |
58
|
|
|
$formData = [ |
59
|
|
|
'title' => 'Testing!', |
60
|
|
|
'thanks' => 'Cheers', |
61
|
|
|
'subject' => 'Thanks a lot', |
62
|
|
|
'from_email' => '[email protected]', |
63
|
|
|
'to_email' => '[email protected]', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
$form = $this->factory->create(NonAbstractFormPageAdminType::class); |
67
|
|
|
|
68
|
|
|
$formPage = new FormPage(); |
69
|
|
|
$formPage->setTitle('Testing!'); |
70
|
|
|
$formPage->setThanks('<p>Cheers</p>'); |
71
|
|
|
$formPage->setSubject('Thanks a lot'); |
72
|
|
|
$formPage->setFromEmail('[email protected]'); |
73
|
|
|
$formPage->setToEmail('[email protected]'); |
74
|
|
|
|
75
|
|
|
$form->submit($formData); |
76
|
|
|
|
77
|
|
|
$this->assertTrue($form->isSynchronized()); |
78
|
|
|
$this->assertTrue($form->isValid()); |
79
|
|
|
$this->assertEquals($formPage, $form->getData()); |
80
|
|
|
|
81
|
|
|
$view = $form->createView(); |
82
|
|
|
$children = $view->children; |
83
|
|
|
|
84
|
|
|
foreach (array_keys($formData) as $key) { |
85
|
|
|
$this->assertArrayHasKey($key, $children); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function getExtensions() |
90
|
|
|
{ |
91
|
|
|
$mediaTokenTransformer = $this->createMock(MediaTokenTransformer::class); |
92
|
|
|
$mediaTokenTransformer->expects($this->once()) |
93
|
|
|
->method('reverseTransform') |
94
|
|
|
->willReturn('<p>Cheers</p>'); |
95
|
|
|
$wysiwygType = new WysiwygType($mediaTokenTransformer); |
|
|
|
|
96
|
|
|
|
97
|
|
|
return [ |
98
|
|
|
new PreloadedExtension([$wysiwygType], []), |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: