‪TYPO3CMS  9.5
SectionTest.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 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
26 class ‪SectionTest extends UnitTestCase
27 {
28  protected static ‪$IDENTIFIER = 'an_id';
29  protected static ‪$TYPE = 'a_type';
30 
35  protected ‪$sectionInstance;
36 
40  public function ‪setUp()
41  {
42  parent::setUp();
43  $this->sectionInstance = new ‪Section(self::$IDENTIFIER, self::$TYPE);
44  }
45 
49  public function ‪newInstanceHasNoProperties(): void
50  {
51  $this->assertNotNull($this->sectionInstance);
52  $this->assertCount(0, $this->sectionInstance->getProperties());
53  }
54 
58  public function ‪setSimpleProperties(): void
59  {
60  $this->sectionInstance->setProperty('foo', 'bar');
61  $this->sectionInstance->setProperty('buz', 'qax');
62  $properties = $this->sectionInstance->getProperties();
63 
64  $this->assertCount(2, $properties, json_encode($properties));
65  $this->assertTrue(array_key_exists('foo', $properties));
66  $this->assertEquals('bar', $properties['foo']);
67  $this->assertTrue(array_key_exists('buz', $properties));
68  $this->assertEquals('qax', $properties['buz']);
69  }
70 
74  public function ‪overrideProperties(): void
75  {
76  $this->sectionInstance->setProperty('foo', 'bar');
77  $this->sectionInstance->setProperty('foo', 'buz');
78 
79  $properties = $this->sectionInstance->getProperties();
80  $this->assertEquals(1, \count($properties));
81  $this->assertTrue(array_key_exists('foo', $properties));
82  $this->assertEquals('buz', $properties['foo']);
83  }
84 
88  public function ‪setArrayProperties(): void
89  {
90  $this->sectionInstance->setProperty('foo', ['bar' => 'baz', 'bla' => 'blubb']);
91  $properties = $this->sectionInstance->getProperties();
92 
93  $this->assertCount(1, $properties);
94  $this->assertTrue(array_key_exists('foo', $properties));
95 
96  //check arrays details
97  $this->assertTrue(\is_array($properties['foo']));
98  $this->assertCount(2, $properties['foo']);
99  $this->assertTrue(array_key_exists('bar', $properties['foo']));
100  $this->assertEquals('baz', $properties['foo']['bar']);
101  }
102 
106  public function ‪setPropertyUnsetIfValueIsNull(): void
107  {
108  $expected = ['foo-1' => ['bar-1' => 'foo-2']];
109  $this->sectionInstance->setProperty('foo-1', ['bar-1' => 'foo-2']);
110  $this->sectionInstance->setProperty('foo-2', ['bar-2' => 'foo-3']);
111  $this->sectionInstance->setProperty('foo-2', null);
112 
113  $this->assertSame($expected, $this->sectionInstance->getProperties());
114  }
115 
120  {
121  $expected = [
122  'foo-1' => [
123  'bar-1' => 'foo-2'
124  ],
125  'foo-2' => [
126  'bar-2' => 'foo-3'
127  ]
128  ];
129  $this->sectionInstance->setProperty('foo-1', ['bar-1' => 'foo-2']);
130  $this->sectionInstance->setProperty('foo-2', ['bar-2' => 'foo-3', 'bar-3' => 'foo-4']);
131  $this->sectionInstance->setProperty('foo-2', ['bar-3' => null]);
132 
133  $this->assertSame($expected, $this->sectionInstance->getProperties());
134  }
135 
140  {
141  $expected = ['foo' => 'bar'];
142  $this->sectionInstance->setRenderingOption('foo', 'bar');
143 
144  $this->assertSame($expected, $this->sectionInstance->getRenderingOptions());
145  }
146 
151  {
152  $expected = ['foo-1' => ['bar' => 'foo-2']];
153  $this->sectionInstance->setRenderingOption('foo-1', ['bar' => 'foo-2']);
154 
155  $this->assertSame($expected, $this->sectionInstance->getRenderingOptions());
156  }
157 
161  public function ‪setRenderingOptionUnsetIfValueIsNull(): void
162  {
163  $expected = ['foo-1' => ['bar-1' => 'foo-2']];
164  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
165  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3']);
166  $this->sectionInstance->setRenderingOption('foo-2', null);
167 
168  $this->assertSame($expected, $this->sectionInstance->getRenderingOptions());
169  }
170 
175  {
176  $expected = [
177  'foo-1' => [
178  'bar-1' => 'foo-2'
179  ],
180  'foo-2' => [
181  'bar-2' => 'foo-3'
182  ]
183  ];
184  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
185  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3', 'bar-3' => 'foo-4']);
186  $this->sectionInstance->setRenderingOption('foo-2', ['bar-3' => null]);
187 
188  $this->assertSame($expected, $this->sectionInstance->getRenderingOptions());
189  }
190 
194  public function ‪setRenderingOptionAddValueIfValueIsArray(): void
195  {
196  $expected = [
197  'foo-1' => [
198  'bar-1' => 'foo-2'
199  ],
200  'foo-2' => [
201  'bar-2' => 'foo-3',
202  'bar-3' => 'foo-4'
203  ]
204  ];
205  $this->sectionInstance->setRenderingOption('foo-1', ['bar-1' => 'foo-2']);
206  $this->sectionInstance->setRenderingOption('foo-2', ['bar-2' => 'foo-3']);
207  $this->sectionInstance->setRenderingOption('foo-2', ['bar-3' => 'foo-4']);
208 
209  $this->assertSame($expected, $this->sectionInstance->getRenderingOptions());
210  }
211 }
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\$IDENTIFIER
‪static $IDENTIFIER
Definition: SectionTest.php:28
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionSetArrayValueIfKeyDoesNotExists
‪setRenderingOptionSetArrayValueIfKeyDoesNotExists()
Definition: SectionTest.php:149
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setPropertyUnsetIfValueIsNull
‪setPropertyUnsetIfValueIsNull()
Definition: SectionTest.php:105
‪TYPO3\CMS\Form\Domain\Model\FormElements\Section
Definition: Section.php:35
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\$sectionInstance
‪Section $sectionInstance
Definition: SectionTest.php:34
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements
Definition: AbstractFormElementTest.php:3
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\$TYPE
‪static $TYPE
Definition: SectionTest.php:29
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionUnsetIfValueIsNull
‪setRenderingOptionUnsetIfValueIsNull()
Definition: SectionTest.php:160
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setPropertyUnsetIfValueIsArrayWithSomeNullVales
‪setPropertyUnsetIfValueIsArrayWithSomeNullVales()
Definition: SectionTest.php:118
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setSimpleProperties
‪setSimpleProperties()
Definition: SectionTest.php:57
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest
Definition: SectionTest.php:27
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionUnsetIfValueIsArrayWithSomeNullVales
‪setRenderingOptionUnsetIfValueIsArrayWithSomeNullVales()
Definition: SectionTest.php:173
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionSetStringValueIfKeyDoesNotExists
‪setRenderingOptionSetStringValueIfKeyDoesNotExists()
Definition: SectionTest.php:138
‪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:87
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\newInstanceHasNoProperties
‪newInstanceHasNoProperties()
Definition: SectionTest.php:48
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\overrideProperties
‪overrideProperties()
Definition: SectionTest.php:73
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\SectionTest\setRenderingOptionAddValueIfValueIsArray
‪setRenderingOptionAddValueIfValueIsArray()
Definition: SectionTest.php:193