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