‪TYPO3CMS  9.5
AbstractFinisherTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪AbstractFinisherTest extends UnitTestCase
31 {
36  {
37  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
38  AbstractFinisher::class,
39  [],
40  '',
41  false
42  );
43 
44  $this->assertNull($mockAbstractFinisher->_call('parseOption', 'translation'));
45  }
46 
51  {
52  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
53  AbstractFinisher::class,
54  [],
55  '',
56  false
57  );
58 
59  $mockAbstractFinisher->_set('options', []);
60 
61  $this->assertNull($mockAbstractFinisher->_call('parseOption', 'foo'));
62  }
63 
68  {
69  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
70  AbstractFinisher::class,
71  [],
72  '',
73  false
74  );
75 
76  $mockAbstractFinisher->_set('options', []);
77 
78  $this->assertNull($mockAbstractFinisher->_call('parseOption', 'foo'));
79  }
80 
85  {
86  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
87  AbstractFinisher::class,
88  [],
89  '',
90  false
91  );
92 
93  $mockAbstractFinisher->_set('options', [
94  'foo1' => false,
95  ]);
96 
97  $expected = false;
98 
99  $this->assertSame($expected, $mockAbstractFinisher->_call('parseOption', 'foo1'));
100  }
101 
106  {
107  $expected = 'defaultValue';
108 
109  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
110  AbstractFinisher::class,
111  [],
112  '',
113  false,
114  false,
115  true,
116  [
117  'translateFinisherOption'
118  ]
119  );
120 
121  $mockAbstractFinisher
122  ->expects($this->any())
123  ->method('translateFinisherOption')
124  ->willReturnArgument(0);
125 
126  $mockAbstractFinisher->_set('options', []);
127  $mockAbstractFinisher->_set('defaultOptions', [
128  'subject' => $expected
129  ]);
130 
131  $finisherContextProphecy = $this->prophesize(FinisherContext::class);
132 
133  $formRuntimeProphecy = $this->prophesize(FormRuntime::class);
134  $formRuntimeProphecy->offsetExists(Argument::cetera())->willReturn(true);
135  $formRuntimeProphecy->offsetGet(Argument::cetera())->willReturn(null);
136 
137  $finisherContextProphecy->getFormRuntime(Argument::cetera())
138  ->willReturn($formRuntimeProphecy->reveal());
139  $finisherContextProphecy->getFinisherVariableProvider(Argument::cetera())
140  ->willReturn(new ‪FinisherVariableProvider);
141 
142  $mockAbstractFinisher->_set('finisherContext', $finisherContextProphecy->reveal());
143 
144  $this->assertSame($expected, $mockAbstractFinisher->_call('parseOption', 'subject'));
145  }
146 
151  {
152  $elementIdentifier = 'element-identifier-1';
153  $expected = 'defaultValue';
154 
155  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
156  AbstractFinisher::class,
157  [],
158  '',
159  false,
160  false,
161  true,
162  [
163  'translateFinisherOption'
164  ]
165  );
166 
167  $mockAbstractFinisher
168  ->expects($this->any())
169  ->method('translateFinisherOption')
170  ->willReturnArgument(0);
171 
172  $mockAbstractFinisher->_set('options', [
173  'subject' => '{' . $elementIdentifier . '}'
174  ]);
175  $mockAbstractFinisher->_set('defaultOptions', [
176  'subject' => $expected
177  ]);
178 
179  $finisherContextProphecy = $this->prophesize(FinisherContext::class);
180 
181  $formRuntimeProphecy = $this->‪createFormRuntimeProphecy([
182  $elementIdentifier => ''
183  ]);
184 
185  $finisherContextProphecy->getFormRuntime(Argument::cetera())
186  ->willReturn($formRuntimeProphecy->reveal());
187 
188  $mockAbstractFinisher->_set('finisherContext', $finisherContextProphecy->reveal());
189 
190  $this->assertSame($expected, $mockAbstractFinisher->_call('parseOption', 'subject'));
191  }
192 
197  {
198  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
199  AbstractFinisher::class,
200  [],
201  '',
202  false,
203  false,
204  true,
205  [
206  'translateFinisherOption'
207  ]
208  );
209 
210  $elementIdentifier = 'element-identifier-1';
211  $elementValue = 'element-value-1';
212  $elementReferenceName = '{' . $elementIdentifier . '}';
213 
214  $translationValue = 'subject: ' . $elementReferenceName;
215  $expected = 'subject: ' . $elementValue;
216 
217  $mockAbstractFinisher
218  ->expects($this->any())
219  ->method('translateFinisherOption')
220  ->willReturn($translationValue);
221 
222  $mockAbstractFinisher->_set('options', [
223  'subject' => ''
224  ]);
225 
226  $finisherContextProphecy = $this->prophesize(FinisherContext::class);
227 
228  $formRuntimeProphecy = $this->‪createFormRuntimeProphecy([
229  $elementIdentifier => $elementValue
230  ]);
231 
232  $finisherContextProphecy->getFormRuntime(Argument::cetera())
233  ->willReturn($formRuntimeProphecy->reveal());
234 
235  $mockAbstractFinisher->_set('finisherContext', $finisherContextProphecy->reveal());
236 
237  $this->assertSame($expected, $mockAbstractFinisher->_call('parseOption', 'subject'));
238  }
239 
244  {
245  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
246  AbstractFinisher::class,
247  [],
248  '',
249  false
250  );
251 
252  $formRuntimeProphecy = $this->prophesize(FormRuntime::class);
253 
254  $input = ['bar', 'foobar', ['x', 'y']];
255  $expected = ['bar', 'foobar', ['x', 'y']];
256 
257  $this->assertSame($expected, $mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal()));
258  }
259 
264  {
265  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
266  AbstractFinisher::class,
267  [],
268  '',
269  false
270  );
271 
272  $formRuntimeProphecy = $this->prophesize(FormRuntime::class);
273 
274  $input = 'foobar';
275  $expected = 'foobar';
276 
277  $this->assertSame($expected, $mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal()));
278  }
279 
284  {
285  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
286  AbstractFinisher::class,
287  [],
288  '',
289  false
290  );
291 
292  $elementIdentifier = 'element-identifier-1';
293  $input = '{' . $elementIdentifier . '}';
294  $expected = 'element-value';
295 
296  $formRuntimeProphecy = $this->‪createFormRuntimeProphecy([
297  $elementIdentifier => $expected
298  ]);
299 
300  $this->assertSame($expected, $mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal()));
301  }
302 
307  {
308  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
309  AbstractFinisher::class,
310  [],
311  '',
312  false
313  );
314 
315  $elementIdentifier1 = 'element-identifier-1';
316  $elementValue1 = 'element-value-1';
317  $elementIdentifier2 = 'element-identifier-2';
318  $elementValue2 = 'element-value-2';
319 
320  $input = '{' . $elementIdentifier1 . '},{' . $elementIdentifier2 . '}';
321  $expected = $elementValue1 . ',' . $elementValue2;
322 
323  $formRuntimeProphecy = $this->‪createFormRuntimeProphecy([
324  $elementIdentifier1 => $elementValue1,
325  $elementIdentifier2 => $elementValue2
326  ]);
327 
328  $this->assertSame($expected, $mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal()));
329  }
330 
335  {
336  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
337  AbstractFinisher::class,
338  [],
339  '',
340  false
341  );
342 
343  $elementIdentifier = 'element-identifier-1';
344  $input = '{' . $elementIdentifier . '}';
345  $expected = ['bar', 'foobar'];
346 
347  $formRuntimeProphecy = $this->‪createFormRuntimeProphecy([
348  $elementIdentifier => $expected
349  ]);
350 
351  $this->assertSame($expected, $mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal()));
352  }
353 
358  {
359  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
360  AbstractFinisher::class,
361  [],
362  '',
363  false
364  );
365 
366  $elementIdentifier1 = 'element-identifier-1';
367  $elementValue1 = ['klaus', 'fritz'];
368  $elementIdentifier2 = 'element-identifier-2';
369  $elementValue2 = ['stan', 'steve'];
370 
371  $input = [
372  '{' . $elementIdentifier1 . '}',
373  'static value',
374  'norbert' => [
375  'lisa',
376  '{' . $elementIdentifier1 . '}',
377  '{' . $elementIdentifier2 . '}',
378  ],
379  ];
380  $expected = [
381  ['klaus', 'fritz'],
382  'static value',
383  'norbert' => [
384  'lisa',
385  ['klaus', 'fritz'],
386  ['stan', 'steve'],
387  ]
388  ];
389 
390  $formRuntimeProphecy = $this->‪createFormRuntimeProphecy([
391  $elementIdentifier1 => $elementValue1,
392  $elementIdentifier2 => $elementValue2
393  ]);
394 
395  $this->assertSame($expected, $mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal()));
396  }
397 
402  {
403  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
404  AbstractFinisher::class,
405  [],
406  '',
407  false
408  );
409 
410  $elementIdentifier = 'element-identifier-1';
411  $input = '{' . $elementIdentifier . '}';
412  $expected = '{' . $elementIdentifier . '}';
413 
414  $formRuntimeProphecy = $this->‪createFormRuntimeProphecy([
415  $elementIdentifier => $expected
416  ]);
417 
418  $finisherContextProphecy = $this->prophesize(FinisherContext::class);
419  $finisherContextProphecy->getFinisherVariableProvider(Argument::cetera())->willReturn(new ‪FinisherVariableProvider);
420  $mockAbstractFinisher->_set('finisherContext', $finisherContextProphecy->reveal());
421 
422  $this->assertSame($expected, $mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal()));
423  }
424 
429  {
430  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
431  AbstractFinisher::class,
432  [],
433  '',
434  false
435  );
436 
437  $input = '{__currentTimestamp}';
438  $expected = '#^([0-9]{10})$#';
439 
440  $formRuntimeProphecy = $this->prophesize(FormRuntime::class);
441 
442  $this->assertEquals(1, preg_match($expected, (string)$mockAbstractFinisher->_call('substituteRuntimeReferences', $input, $formRuntimeProphecy->reveal())));
443  }
444 
449  {
450  $mockAbstractFinisher = $this->getAccessibleMockForAbstractClass(
451  AbstractFinisher::class,
452  [],
453  '',
454  false
455  );
456 
457  $elementIdentifier = 'element-identifier-1';
458  $input = 'BEFORE {' . $elementIdentifier . '} AFTER';
459 
460  $formRuntimeProphecy = $this->‪createFormRuntimeProphecy([
461  $elementIdentifier => ['value-1', 'value-2']
462  ]);
463 
464  $finisherContextProphecy = $this->prophesize(FinisherContext::class);
465  $finisherContextProphecy->getFinisherVariableProvider(Argument::cetera())->willReturn(new ‪FinisherVariableProvider);
466  $mockAbstractFinisher->_set('finisherContext', $finisherContextProphecy->reveal());
467 
468  $this->expectException(FinisherException::class);
469  $this->expectExceptionCode(1519239265);
470 
471  $mockAbstractFinisher->_call(
472  'substituteRuntimeReferences',
473  $input,
474  $formRuntimeProphecy->reveal()
475  );
476  }
477 
482  protected function ‪createFormRuntimeProphecy(array $values)
483  {
485  $formRuntimeProphecy = $this->prophesize(FormRuntime::class);
486  foreach ($values as $key => $value) {
487  $formRuntimeProphecy->offsetExists(Argument::exact($key))->willReturn(true);
488  $formRuntimeProphecy->offsetGet(Argument::exact($key))->willReturn($value);
489  }
490  return $formRuntimeProphecy;
491  }
492 }
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormRuntime.php:97
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesReturnsValueFromFormRuntimeIfInputIsArrayAndSomeItemsReferenceAFormElementIdentifierWhoseValueIsAnArray
‪substituteRuntimeReferencesReturnsValueFromFormRuntimeIfInputIsArrayAndSomeItemsReferenceAFormElementIdentifierWhoseValueIsAnArray()
Definition: AbstractFinisherTest.php:357
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesReturnsStringIfInputIsString
‪substituteRuntimeReferencesReturnsStringIfInputIsString()
Definition: AbstractFinisherTest.php:263
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider
Definition: FinisherVariableProvider.php:29
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesReturnsValueFromFormRuntimeIfInputReferenceMultipleFormElementIdentifierWhoseValueIsAString
‪substituteRuntimeReferencesReturnsValueFromFormRuntimeIfInputReferenceMultipleFormElementIdentifierWhoseValueIsAString()
Definition: AbstractFinisherTest.php:306
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesReturnsNoReplacedValueIfInputReferenceANonExistingFormElement
‪substituteRuntimeReferencesReturnsNoReplacedValueIfInputReferenceANonExistingFormElement()
Definition: AbstractFinisherTest.php:401
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesReturnsValueFromFormRuntimeIfInputReferenceAFormElementIdentifierWhoseValueIsAString
‪substituteRuntimeReferencesReturnsValueFromFormRuntimeIfInputReferenceAFormElementIdentifierWhoseValueIsAString()
Definition: AbstractFinisherTest.php:283
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\createFormRuntimeProphecy
‪ObjectProphecy FormRuntime createFormRuntimeProphecy(array $values)
Definition: AbstractFinisherTest.php:482
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\parseOptionReturnsNullIfOptionNameNotExistsWithinDefaultOptions
‪parseOptionReturnsNullIfOptionNameNotExistsWithinDefaultOptions()
Definition: AbstractFinisherTest.php:67
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesThrowsExceptionOnMultipleVariablesResolvedAsArray
‪substituteRuntimeReferencesThrowsExceptionOnMultipleVariablesResolvedAsArray()
Definition: AbstractFinisherTest.php:448
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesReturnsArrayIfInputIsArray
‪substituteRuntimeReferencesReturnsArrayIfInputIsArray()
Definition: AbstractFinisherTest.php:243
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\parseOptionReturnsNullIfOptionNameNotExistsWithinOptions
‪parseOptionReturnsNullIfOptionNameNotExistsWithinOptions()
Definition: AbstractFinisherTest.php:50
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesReturnsValueFromFormRuntimeIfInputReferenceAFormElementIdentifierWhoseValueIsAnArray
‪substituteRuntimeReferencesReturnsValueFromFormRuntimeIfInputReferenceAFormElementIdentifierWhoseValueIsAnArray()
Definition: AbstractFinisherTest.php:334
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\parseOptionReturnsDefaultOptionValueIfOptionNameNotExistsWithinOptionsButWithinDefaultOptions
‪parseOptionReturnsDefaultOptionValueIfOptionNameNotExistsWithinOptionsButWithinDefaultOptions()
Definition: AbstractFinisherTest.php:105
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:35
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\parseOptionReturnsNullIfOptionNameIsTranslation
‪parseOptionReturnsNullIfOptionNameIsTranslation()
Definition: AbstractFinisherTest.php:35
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\parseOptionReturnsBoolOptionValuesAsBool
‪parseOptionReturnsBoolOptionValuesAsBool()
Definition: AbstractFinisherTest.php:84
‪TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException
Definition: FinisherException.php:24
‪TYPO3\CMS\Form\Domain\Finishers\FinisherContext
Definition: FinisherContext.php:34
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:3
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest
Definition: AbstractFinisherTest.php:31
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\parseOptionResolvesFormElementReferenceFromTranslation
‪parseOptionResolvesFormElementReferenceFromTranslation()
Definition: AbstractFinisherTest.php:196
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\parseOptionReturnsDefaultOptionValueIfOptionValueIsAFormElementReferenceAndTheFormElementValueIsEmpty
‪parseOptionReturnsDefaultOptionValueIfOptionValueIsAFormElementReferenceAndTheFormElementValueIsEmpty()
Definition: AbstractFinisherTest.php:150
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers
Definition: AbstractFinisherTest.php:3
‪TYPO3\CMS\Form\Tests\Unit\Domain\Finishers\AbstractFinisherTest\substituteRuntimeReferencesReturnsTimestampIfInputIsATimestampRequestTrigger
‪substituteRuntimeReferencesReturnsTimestampIfInputIsATimestampRequestTrigger()
Definition: AbstractFinisherTest.php:428