1 | <?php |
||
21 | class FilterTest extends TestCase |
||
22 | { |
||
23 | public function testFilter(): void |
||
60 | |||
61 | public function testGetFieldOption(): void |
||
72 | |||
73 | public function testSetFieldOption(): void |
||
85 | |||
86 | public function testInitialize(): void |
||
97 | |||
98 | public function testLabel(): void |
||
105 | |||
106 | public function testExceptionOnNonDefinedFilterName(): void |
||
107 | { |
||
108 | $filter = new FooFilter(); |
||
109 | $filter->getName(); |
||
110 | |||
111 | $this->expectException(\RuntimeException::class); |
||
112 | $this->expectExceptionMessage(sprintf( |
||
113 | 'Seems like you didn\'t call `initialize()` on the filter `%s`. Did you create it through `%s::create()`?', |
||
114 | FooFilter::class, |
||
115 | FilterFactory::class |
||
116 | )); |
||
117 | } |
||
118 | |||
119 | public function testExceptionOnNonDefinedFieldName(): void |
||
120 | { |
||
121 | $filter = new FooFilter(); |
||
122 | $filter->initialize('foo'); |
||
123 | |||
124 | $filter->getFieldName(); |
||
125 | |||
126 | $this->expectException(\RuntimeException::class); |
||
127 | $this->expectExceptionMessage('The option `field_name` must be set for field: `foo`'); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @dataProvider isActiveData |
||
132 | * |
||
133 | * @param $expected |
||
134 | * @param $value |
||
135 | */ |
||
136 | public function testIsActive(bool $expected, array $value): void |
||
137 | { |
||
138 | $filter = new FooFilter(); |
||
139 | $filter->setValue($value); |
||
140 | |||
141 | $this->assertSame($expected, $filter->isActive()); |
||
142 | } |
||
143 | |||
144 | public function isActiveData(): array |
||
145 | { |
||
146 | return [ |
||
147 | [false, []], |
||
148 | [false, ['value' => null]], |
||
149 | [false, ['value' => '']], |
||
150 | [false, ['value' => false]], |
||
151 | [true, ['value' => 'active']], |
||
152 | ]; |
||
153 | } |
||
154 | |||
155 | public function testGetTranslationDomain(): void |
||
156 | { |
||
157 | $filter = new FooFilter(); |
||
158 | $this->assertNull($filter->getTranslationDomain()); |
||
159 | $filter->setOption('translation_domain', 'baz'); |
||
160 | $this->assertSame('baz', $filter->getTranslationDomain()); |
||
161 | } |
||
162 | |||
163 | public function testGetFieldMappingException(): void |
||
164 | { |
||
165 | $filter = new FooFilter(); |
||
166 | $filter->initialize('foo'); |
||
167 | |||
168 | $filter->getFieldMapping(); |
||
169 | |||
170 | $this->expectException(\RuntimeException::class); |
||
171 | $this->expectExceptionMessage('The option `field_mapping` must be set for field: `foo`'); |
||
172 | } |
||
173 | |||
174 | public function testGetFieldMapping(): void |
||
175 | { |
||
176 | $fieldMapping = [ |
||
177 | 'fieldName' => 'username', |
||
178 | 'type' => 'string', |
||
179 | 'columnName' => 'username', |
||
180 | 'length' => 200, |
||
181 | 'unique' => true, |
||
182 | 'nullable' => false, |
||
183 | 'declared' => 'Foo\Bar\User', |
||
184 | ]; |
||
185 | |||
186 | $filter = new FooFilter(); |
||
187 | $filter->setOption('field_mapping', $fieldMapping); |
||
188 | $this->assertSame($fieldMapping, $filter->getFieldMapping()); |
||
189 | } |
||
190 | |||
191 | public function testGetParentAssociationMappings(): void |
||
192 | { |
||
193 | $parentAssociationMapping = [ |
||
194 | 0 => ['fieldName' => 'user', |
||
195 | 'targetEntity' => 'Foo\Bar\User', |
||
196 | 'joinColumns' => [ |
||
197 | 0 => [ |
||
198 | 'name' => 'user_id', |
||
199 | 'referencedColumnName' => 'user_id', |
||
200 | ], |
||
201 | ], |
||
202 | 'type' => 2, |
||
203 | 'mappedBy' => null, |
||
204 | ], |
||
205 | ]; |
||
206 | |||
207 | $filter = new FooFilter(); |
||
208 | $this->assertSame([], $filter->getParentAssociationMappings()); |
||
209 | $filter->setOption('parent_association_mappings', $parentAssociationMapping); |
||
210 | $this->assertSame($parentAssociationMapping, $filter->getParentAssociationMappings()); |
||
211 | } |
||
212 | |||
213 | public function testGetAssociationMappingException(): void |
||
214 | { |
||
215 | |||
216 | $filter = new FooFilter(); |
||
217 | $filter->initialize('foo'); |
||
218 | |||
219 | $filter->getAssociationMapping(); |
||
220 | |||
221 | $this->expectException(\RuntimeException::class); |
||
222 | $this->expectExceptionMessage('The option `association_mapping` must be set for field: `foo`'); |
||
223 | } |
||
224 | |||
225 | public function testGetAssociationMapping(): void |
||
244 | } |
||
245 |