These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\FormBundle\Tests\Form; |
||
4 | |||
5 | use Kunstmaan\FormBundle\Entity\AbstractFormPage; |
||
6 | use Kunstmaan\FormBundle\Form\AbstractFormPageAdminType; |
||
7 | use Symfony\Component\Form\Test\TypeTestCase; |
||
8 | use Symfony\Component\OptionsResolver\OptionsResolver; |
||
9 | |||
10 | class NonAbstractFormPageAdminType extends AbstractFormPageAdminType |
||
11 | { |
||
12 | public function configureOptions(OptionsResolver $resolver) |
||
13 | { |
||
14 | parent::configureOptions($resolver); |
||
15 | $resolver->setDefaults(array( |
||
16 | 'data_class' => 'Kunstmaan\FormBundle\Tests\Form\FormPage', |
||
17 | )); |
||
18 | } |
||
19 | } |
||
20 | |||
21 | class FormPage extends AbstractFormPage |
||
0 ignored issues
–
show
|
|||
22 | { |
||
23 | public function getPossibleChildTypes() |
||
24 | { |
||
25 | return null; |
||
26 | } |
||
27 | |||
28 | public function getPagePartAdminConfigurations() |
||
29 | { |
||
30 | return [ |
||
31 | [ |
||
32 | 'name' => 'ContentPage', |
||
33 | 'class' => '{{ namespace }}\Entity\Pages\ContentPage', |
||
34 | ], |
||
35 | [ |
||
36 | 'name' => 'FormPage', |
||
37 | 'class' => '{{ namespace }}\Entity\Pages\FormPage', |
||
38 | ], |
||
39 | ]; |
||
40 | } |
||
41 | |||
42 | public function getDefaultView() |
||
43 | { |
||
44 | return 'some.twig'; |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Generated by PHPUnit_SkeletonGenerator on 2012-09-20 at 15:14:43. |
||
50 | */ |
||
51 | class AbstractFormPageAdminTypeTest extends TypeTestCase |
||
52 | { |
||
53 | public function testFormType() |
||
54 | { |
||
55 | $formData = [ |
||
56 | 'title' => 'Testing!', |
||
57 | 'thanks' => 'Cheers', |
||
58 | 'subject' => 'Thanks a lot', |
||
59 | 'from_email' => '[email protected]', |
||
60 | 'to_email' => '[email protected]', |
||
61 | ]; |
||
62 | $form = $this->factory->create(NonAbstractFormPageAdminType::class); |
||
63 | |||
64 | $formPage = new FormPage(); |
||
65 | $formPage->setTitle('Testing!'); |
||
66 | $formPage->setThanks('<p>Cheers</p>'); |
||
67 | $formPage->setSubject('Thanks a lot'); |
||
68 | $formPage->setFromEmail('[email protected]'); |
||
69 | $formPage->setToEmail('[email protected]'); |
||
70 | |||
71 | $form->submit($formData); |
||
72 | |||
73 | $this->assertTrue($form->isSynchronized()); |
||
74 | $this->assertTrue($form->isValid()); |
||
75 | $this->assertEquals($formPage, $form->getData()); |
||
76 | |||
77 | $view = $form->createView(); |
||
78 | $children = $view->children; |
||
79 | |||
80 | foreach (array_keys($formData) as $key) { |
||
81 | $this->assertArrayHasKey($key, $children); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.