‪TYPO3CMS  ‪main
SectionTest.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 
20 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
29 final class ‪SectionTest extends UnitTestCase
30 {
31  protected static ‪$IDENTIFIER = 'an_id';
32  protected static ‪$TYPE = 'a_type';
33 
38  protected ‪$sectionInstance;
39 
40  public function ‪setUp(): void
41  {
42  parent::setUp();
43  $this->sectionInstance = new ‪Section(self::$IDENTIFIER, self::$TYPE);
44  }
45 
46  #[Test]
47  public function ‪newInstanceHasNoProperties(): void
48  {
49  self::assertNotNull($this->sectionInstance);
50  self::assertCount(0, $this->sectionInstance->getProperties());
51  }
52 
53  #[Test]
54  public function ‪setSimpleProperties(): void
55  {
56  $this->sectionInstance->setProperty('foo', 'bar');
57  $this->sectionInstance->setProperty('buz', 'qax');
58  $properties = $this->sectionInstance->getProperties();
59 
60  self::assertCount(2, $properties, json_encode($properties));
61  self::assertArrayHasKey('foo', $properties);
62  self::assertEquals('bar', $properties['foo']);
63  self::assertArrayHasKey('buz', $properties);
64  self::assertEquals('qax', $properties['buz']);
65  }
66 
67  #[Test]
68  public function ‪overrideProperties(): void
69  {
70  $this->sectionInstance->setProperty('foo', 'bar');
71  $this->sectionInstance->setProperty('foo', 'buz');
72 
73  $properties = $this->sectionInstance->getProperties();
74  self::assertCount(1, $properties);
75  self::assertTrue(array_key_exists('foo', $properties));
76  self::assertEquals('buz', $properties['foo']);
77  }
78 
79  #[Test]
80  public function ‪setArrayProperties(): void
81  {
82  $this->sectionInstance->setProperty('foo', ['bar' => 'baz', 'bla' => 'blubb']);
83  $properties = $this->sectionInstance->getProperties();
84 
85  self::assertCount(1, $properties);
86  self::assertTrue(array_key_exists('foo', $properties));
87 
88  //check arrays details
89  self::assertIsArray($properties['foo']);
90  self::assertCount(2, $properties['foo']);
91  self::assertTrue(array_key_exists('bar', $properties['foo']));
92  self::assertEquals('baz', $properties['foo']['bar']);
93  }
94 
95  #[Test]
96  public function ‪setPropertyUnsetIfValueIsNull(): void
97  {
98  $expected = ['foo-1' => ['bar-1' => 'foo-2']];
99  $this->sectionInstance->setProperty('foo-1', ['bar-1' => 'foo-2']);
100  $this->sectionInstance->setProperty('foo-2', ['bar-2' => 'foo-3']);
101  $this->sectionInstance->setProperty('foo-2', null);
102 
103  self::assertSame($expected, $this->sectionInstance->getProperties());
104  }
105 
106  #[Test]
108  {
109  $expected = [
110  'foo-1' => [
111  'bar-1' => 'foo-2',
112  ],
113  'foo-2' => [
114  'bar-2' => 'foo-3',
115  ],
116  ];
117  $this->sectionInstance->setProperty('foo-1', ['bar-1' => 'foo-2']);
118  $this->sectionInstance->setProperty('foo-2', ['bar-2' => 'foo-3', 'bar-3' => 'foo-4']);
119  $this->sectionInstance->setProperty('foo-2', ['bar-3' => null]);
120 
121  self::assertSame($expected, $this->sectionInstance->getProperties());
122  }
123 
124  #[Test]
126  {
127  $expected = ['foo' => 'bar'];
128  $this->sectionInstance->setRenderingOption('foo', 'bar');
129 
130  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
131  }
132 
133  #[Test]
135  {
136  $expected = ['foo-1' => ['bar' => 'foo-2']];
137  $this->sectionInstance->setRenderingOption('foo-1', ['bar' => 'foo-2']);
138 
139  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
140  }
141 
142  #[Test]
143  public function ‪setRenderingOptionUnsetIfValueIsNull(): void
144  {
145  $expected = ['foo-1' => ['bar-1' => 'foo-2']];
146  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
147  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3']);
148  $this->sectionInstance->setRenderingOption('foo-2', null);
149 
150  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
151  }
152 
153  #[Test]
155  {
156  $expected = [
157  'foo-1' => [
158  'bar-1' => 'foo-2',
159  ],
160  'foo-2' => [
161  'bar-2' => 'foo-3',
162  ],
163  ];
164  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
165  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3', 'bar-3' => 'foo-4']);
166  $this->sectionInstance->setRenderingOption('foo-2', ['bar-3' => null]);
167 
168  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
169  }
170 
171  #[Test]
172  public function ‪setRenderingOptionAddValueIfValueIsArray(): void
173  {
174  $expected = [
175  'foo-1' => [
176  'bar-1' => 'foo-2',
177  ],
178  'foo-2' => [
179  'bar-2' => 'foo-3',
180  'bar-3' => 'foo-4',
181  ],
182  ];
183  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
184  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3']);
185  $this->sectionInstance->setRenderingOption('foo-2', ['bar-3' => 'foo-4']);
186 
187  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
188  }
189 }
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\$IDENTIFIER
‪static $IDENTIFIER
Definition: SectionTest.php:31
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionSetArrayValueIfKeyDoesNotExists
‪setRenderingOptionSetArrayValueIfKeyDoesNotExists()
Definition: SectionTest.php:133
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setPropertyUnsetIfValueIsNull
‪setPropertyUnsetIfValueIsNull()
Definition: SectionTest.php:95
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section
Definition: Section.php:39
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\$sectionInstance
‪Section $sectionInstance
Definition: SectionTest.php:37
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements
Definition: AbstractFormElementTest.php:18
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\$TYPE
‪static $TYPE
Definition: SectionTest.php:32
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionUnsetIfValueIsNull
‪setRenderingOptionUnsetIfValueIsNull()
Definition: SectionTest.php:142
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setPropertyUnsetIfValueIsArrayWithSomeNullVales
‪setPropertyUnsetIfValueIsArrayWithSomeNullVales()
Definition: SectionTest.php:106
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setSimpleProperties
‪setSimpleProperties()
Definition: SectionTest.php:53
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest
Definition: SectionTest.php:30
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionUnsetIfValueIsArrayWithSomeNullVales
‪setRenderingOptionUnsetIfValueIsArrayWithSomeNullVales()
Definition: SectionTest.php:153
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionSetStringValueIfKeyDoesNotExists
‪setRenderingOptionSetStringValueIfKeyDoesNotExists()
Definition: SectionTest.php:124
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setUp
‪setUp()
Definition: SectionTest.php:39
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setArrayProperties
‪setArrayProperties()
Definition: SectionTest.php:79
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\newInstanceHasNoProperties
‪newInstanceHasNoProperties()
Definition: SectionTest.php:46
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\overrideProperties
‪overrideProperties()
Definition: SectionTest.php:67
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionAddValueIfValueIsArray
‪setRenderingOptionAddValueIfValueIsArray()
Definition: SectionTest.php:171