‪TYPO3CMS  11.5
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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
28 class ‪SectionTest extends UnitTestCase
29 {
30  protected static ‪$IDENTIFIER = 'an_id';
31  protected static ‪$TYPE = 'a_type';
32 
37  protected ‪$sectionInstance;
38 
42  public function ‪setUp(): void
43  {
44  parent::setUp();
45  $this->sectionInstance = new ‪Section(self::$IDENTIFIER, self::$TYPE);
46  }
47 
51  public function ‪newInstanceHasNoProperties(): void
52  {
53  self::assertNotNull($this->sectionInstance);
54  self::assertCount(0, $this->sectionInstance->getProperties());
55  }
56 
60  public function ‪setSimpleProperties(): void
61  {
62  $this->sectionInstance->setProperty('foo', 'bar');
63  $this->sectionInstance->setProperty('buz', 'qax');
64  $properties = $this->sectionInstance->getProperties();
65 
66  self::assertCount(2, $properties, json_encode($properties));
67  self::assertArrayHasKey('foo', $properties);
68  self::assertEquals('bar', $properties['foo']);
69  self::assertArrayHasKey('buz', $properties);
70  self::assertEquals('qax', $properties['buz']);
71  }
72 
76  public function ‪overrideProperties(): void
77  {
78  $this->sectionInstance->setProperty('foo', 'bar');
79  $this->sectionInstance->setProperty('foo', 'buz');
80 
81  $properties = $this->sectionInstance->getProperties();
82  self::assertCount(1, $properties);
83  self::assertTrue(array_key_exists('foo', $properties));
84  self::assertEquals('buz', $properties['foo']);
85  }
86 
90  public function ‪setArrayProperties(): void
91  {
92  $this->sectionInstance->setProperty('foo', ['bar' => 'baz', 'bla' => 'blubb']);
93  $properties = $this->sectionInstance->getProperties();
94 
95  self::assertCount(1, $properties);
96  self::assertTrue(array_key_exists('foo', $properties));
97 
98  //check arrays details
99  self::assertIsArray($properties['foo']);
100  self::assertCount(2, $properties['foo']);
101  self::assertTrue(array_key_exists('bar', $properties['foo']));
102  self::assertEquals('baz', $properties['foo']['bar']);
103  }
104 
108  public function ‪setPropertyUnsetIfValueIsNull(): void
109  {
110  $expected = ['foo-1' => ['bar-1' => 'foo-2']];
111  $this->sectionInstance->setProperty('foo-1', ['bar-1' => 'foo-2']);
112  $this->sectionInstance->setProperty('foo-2', ['bar-2' => 'foo-3']);
113  $this->sectionInstance->setProperty('foo-2', null);
114 
115  self::assertSame($expected, $this->sectionInstance->getProperties());
116  }
117 
122  {
123  $expected = [
124  'foo-1' => [
125  'bar-1' => 'foo-2',
126  ],
127  'foo-2' => [
128  'bar-2' => 'foo-3',
129  ],
130  ];
131  $this->sectionInstance->setProperty('foo-1', ['bar-1' => 'foo-2']);
132  $this->sectionInstance->setProperty('foo-2', ['bar-2' => 'foo-3', 'bar-3' => 'foo-4']);
133  $this->sectionInstance->setProperty('foo-2', ['bar-3' => null]);
134 
135  self::assertSame($expected, $this->sectionInstance->getProperties());
136  }
137 
142  {
143  $expected = ['foo' => 'bar'];
144  $this->sectionInstance->setRenderingOption('foo', 'bar');
145 
146  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
147  }
148 
153  {
154  $expected = ['foo-1' => ['bar' => 'foo-2']];
155  $this->sectionInstance->setRenderingOption('foo-1', ['bar' => 'foo-2']);
156 
157  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
158  }
159 
163  public function ‪setRenderingOptionUnsetIfValueIsNull(): void
164  {
165  $expected = ['foo-1' => ['bar-1' => 'foo-2']];
166  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
167  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3']);
168  $this->sectionInstance->setRenderingOption('foo-2', null);
169 
170  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
171  }
172 
177  {
178  $expected = [
179  'foo-1' => [
180  'bar-1' => 'foo-2',
181  ],
182  'foo-2' => [
183  'bar-2' => 'foo-3',
184  ],
185  ];
186  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
187  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3', 'bar-3' => 'foo-4']);
188  $this->sectionInstance->setRenderingOption('foo-2', ['bar-3' => null]);
189 
190  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
191  }
192 
196  public function ‪setRenderingOptionAddValueIfValueIsArray(): void
197  {
198  $expected = [
199  'foo-1' => [
200  'bar-1' => 'foo-2',
201  ],
202  'foo-2' => [
203  'bar-2' => 'foo-3',
204  'bar-3' => 'foo-4',
205  ],
206  ];
207  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
208  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3']);
209  $this->sectionInstance->setRenderingOption('foo-2', ['bar-3' => 'foo-4']);
210 
211  self::assertSame($expected, $this->sectionInstance->getRenderingOptions());
212  }
213 }
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\$IDENTIFIER
‪static $IDENTIFIER
Definition: SectionTest.php:30
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionSetArrayValueIfKeyDoesNotExists
‪setRenderingOptionSetArrayValueIfKeyDoesNotExists()
Definition: SectionTest.php:151
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setPropertyUnsetIfValueIsNull
‪setPropertyUnsetIfValueIsNull()
Definition: SectionTest.php:107
‪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:36
‪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:31
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionUnsetIfValueIsNull
‪setRenderingOptionUnsetIfValueIsNull()
Definition: SectionTest.php:162
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setPropertyUnsetIfValueIsArrayWithSomeNullVales
‪setPropertyUnsetIfValueIsArrayWithSomeNullVales()
Definition: SectionTest.php:120
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setSimpleProperties
‪setSimpleProperties()
Definition: SectionTest.php:59
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest
Definition: SectionTest.php:29
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionUnsetIfValueIsArrayWithSomeNullVales
‪setRenderingOptionUnsetIfValueIsArrayWithSomeNullVales()
Definition: SectionTest.php:175
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionSetStringValueIfKeyDoesNotExists
‪setRenderingOptionSetStringValueIfKeyDoesNotExists()
Definition: SectionTest.php:140
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setUp
‪setUp()
Definition: SectionTest.php:41
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setArrayProperties
‪setArrayProperties()
Definition: SectionTest.php:89
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\newInstanceHasNoProperties
‪newInstanceHasNoProperties()
Definition: SectionTest.php:50
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\overrideProperties
‪overrideProperties()
Definition: SectionTest.php:75
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionAddValueIfValueIsArray
‪setRenderingOptionAddValueIfValueIsArray()
Definition: SectionTest.php:195