1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoctrineORMModuleTest\Form; |
4
|
|
|
|
5
|
|
|
use DoctrineORMModule\Form\Annotation\AnnotationBuilder; |
6
|
|
|
use DoctrineORMModuleTest\Assets\Entity\FormEntity; |
7
|
|
|
use DoctrineORMModuleTest\Assets\Entity\Issue237; |
8
|
|
|
use DoctrineORMModuleTest\Framework\TestCase; |
9
|
|
|
use Laminas\Form\Annotation\AnnotationBuilder as LaminasAnnotationBuilder; |
10
|
|
|
|
11
|
|
|
class AnnotationBuilderTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var AnnotationBuilder |
15
|
|
|
*/ |
16
|
|
|
protected $builder; |
17
|
|
|
|
18
|
|
|
public function setUp() : void |
19
|
|
|
{ |
20
|
|
|
$this->builder = new AnnotationBuilder($this->getEntityManager()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @covers \DoctrineORMModule\Form\Annotation\AnnotationBuilder::getFormSpecification |
25
|
|
|
* @link https://github.com/doctrine/DoctrineORMModule/issues/237 |
26
|
|
|
*/ |
27
|
|
|
public function testIssue237() |
28
|
|
|
{ |
29
|
|
|
$entity = new Issue237(); |
30
|
|
|
$spec = $this->builder->getFormSpecification($entity); |
31
|
|
|
|
32
|
|
|
$this->assertCount(0, $spec['elements']); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @covers \DoctrineORMModule\Form\Annotation\AnnotationBuilder::getFormSpecification |
37
|
|
|
*/ |
38
|
|
|
public function testAnnotationBuilderSupportsClassNames() |
39
|
|
|
{ |
40
|
|
|
$spec = $this->builder->getFormSpecification(\DoctrineORMModuleTest\Assets\Entity\Issue237::class); |
41
|
|
|
|
42
|
|
|
$this->assertCount(0, $spec['elements'], 'Annotation builder allows also class names'); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* empty_option behavior - !isset can't evaluate null value |
47
|
|
|
* @link https://github.com/doctrine/DoctrineORMModule/pull/247 |
48
|
|
|
*/ |
49
|
|
|
public function testEmptyOptionNullDoesntGenerateValue() |
50
|
|
|
{ |
51
|
|
|
$showEmptyValue = true; |
52
|
|
|
$entity = new FormEntity(); |
53
|
|
|
$spec = $this->builder->getFormSpecification($entity); |
54
|
|
|
|
55
|
|
|
foreach ($spec['elements'] as $elementSpec) { |
56
|
|
|
if (isset($elementSpec['spec']['options'])) { |
57
|
|
|
if (array_key_exists('empty_option', $elementSpec['spec']['options']) && |
58
|
|
|
$elementSpec['spec']['options']['empty_option'] === null |
59
|
|
|
) { |
60
|
|
|
$showEmptyValue = false; |
61
|
|
|
break; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
$this->assertFalse($showEmptyValue); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Ensure user defined \Type or type attribute overrides the listener one |
70
|
|
|
*/ |
71
|
|
|
public function testEnsureCustomTypeOrAttributeTypeIsUsedInAnnotations() |
72
|
|
|
{ |
73
|
|
|
$userDefinedTypeOverridesListenerType = true; |
74
|
|
|
$entity = new FormEntity(); |
75
|
|
|
|
76
|
|
|
$laminasAnnotationBuilder = new LaminasAnnotationBuilder(); |
77
|
|
|
$laminasForm = $laminasAnnotationBuilder->createForm($entity); |
78
|
|
|
|
79
|
|
|
$spec = $this->builder->getFormSpecification($entity); |
80
|
|
|
$annotationForm = $this->builder->createForm($entity); |
81
|
|
|
|
82
|
|
|
$attributesToTest = ['specificType', 'specificMultiType', 'specificAttributeType']; |
83
|
|
|
|
84
|
|
|
foreach ($spec['elements'] as $element) { |
85
|
|
|
$elementName = $element['spec']['name']; |
86
|
|
|
if (in_array($elementName, $attributesToTest)) { |
87
|
|
|
$annotationFormElement = $annotationForm->get($elementName); |
88
|
|
|
$laminasFormElement = $laminasForm->get($elementName); |
89
|
|
|
|
90
|
|
|
$annotationElementAttribute = $annotationFormElement->getAttribute('type'); |
91
|
|
|
$laminasElementAttribute = $laminasFormElement->getAttribute('type'); |
92
|
|
|
|
93
|
|
|
if ((get_class($laminasFormElement) !== get_class($annotationFormElement)) || |
94
|
|
|
($annotationElementAttribute !== $laminasElementAttribute) |
95
|
|
|
) { |
96
|
|
|
$userDefinedTypeOverridesListenerType = false; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
$this->assertTrue($userDefinedTypeOverridesListenerType); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @link https://github.com/zendframework/zf2/issues/7096 |
105
|
|
|
*/ |
106
|
|
|
public function testFileTypeDoesntGrabStringLengthValidator() |
107
|
|
|
{ |
108
|
|
|
$validators = $this |
109
|
|
|
->builder |
110
|
|
|
->createForm(new FormEntity()) |
111
|
|
|
->getInputFilter() |
112
|
|
|
->get('image') |
113
|
|
|
->getValidatorChain() |
114
|
|
|
->getValidators(); |
115
|
|
|
|
116
|
|
|
$this->assertCount(0, $validators); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Ensure prefer_form_input_filter is set to true for the generated form |
121
|
|
|
*/ |
122
|
|
|
public function testPreferFormInputFilterIsTrue() |
123
|
|
|
{ |
124
|
|
|
$entity = new FormEntity(); |
125
|
|
|
$form = $this->builder->createForm($entity); |
126
|
|
|
$this->assertTrue($form->getPreferFormInputFilter()); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.