‪TYPO3CMS  9.5
RenderableVariantTest.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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪RenderableVariantTest extends UnitTestCase
26 {
30  protected ‪$resetSingletonInstances = true;
31 
35  public function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->resetSingletonInstances = true;
39  }
40 
44  public function ‪formVariantOverridesArrayValues(): void
45  {
46  $formElementIdentifier = 'form-element-identifier';
47  $variantIdentifier = 'variant-identifier';
48  $formElementProperties = [
49  'options' => [
50  1 => 'option 1',
51  2 => 'option 2',
52  3 => 'option 3',
53  ],
54  ];
55  $variantProperties = [
56  'options' => [
57  1 => 'option 1',
58  2 => 'option 2',
59  3 => '__UNSET',
60  ],
61  ];
62 
63  $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
64 
65  $mockFormElement->_set('type', 'SingleSelect');
66  $mockFormElement->_set('identifier', $formElementIdentifier);
67  $mockFormElement->_set('label', 'some label');
68  $mockFormElement->_set('properties', $formElementProperties);
69 
70  $options = [
71  'identifier' => $variantIdentifier,
72  'label' => 'some label',
73  'properties' => $variantProperties
74  ];
75  $mockVariant = $this->getAccessibleMock(RenderableVariant::class, ['getIdentifier'], [$variantIdentifier, $options, $mockFormElement], '', true);
76  $mockFormElement->addVariant($mockVariant);
77  $mockFormElement->applyVariant($mockVariant);
78 
79  $expected = [
80  'options' => [
81  1 => 'option 1',
82  2 => 'option 2',
83  ],
84  ];
85 
86  self::assertEquals($expected, $mockFormElement->_get('properties'));
87  }
88 }
‪TYPO3\CMS\Form\Domain\Model\FormElements\GenericFormElement
Definition: GenericFormElement.php:26
‪TYPO3\CMS\Form\Tests\Unit\Domain\Renderable\RenderableVariantTest
Definition: RenderableVariantTest.php:26
‪TYPO3\CMS\Form\Tests\Unit\Domain\Renderable\RenderableVariantTest\formVariantOverridesArrayValues
‪formVariantOverridesArrayValues()
Definition: RenderableVariantTest.php:43
‪TYPO3\CMS\Form\Tests\Unit\Domain\Renderable
Definition: AbstractRenderableTest.php:2
‪TYPO3\CMS\Form\Tests\Unit\Domain\Renderable\RenderableVariantTest\setUp
‪setUp()
Definition: RenderableVariantTest.php:34
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableVariant
Definition: RenderableVariant.php:27
‪TYPO3\CMS\Form\Tests\Unit\Domain\Renderable\RenderableVariantTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: RenderableVariantTest.php:29