‪TYPO3CMS  11.5
StateTest.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 
26 class ‪StateTest extends UnitTestCase
27 {
28  public const ‪TABLE_NAME = 'tx_test_table';
29 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  ‪$GLOBALS['TCA'] = [];
37  }
38 
46  public function ‪stateObjectCanBeCreated(string $tableName, array $states): void
47  {
48  $subject = new ‪State($tableName, $states);
49 
50  self::assertInstanceOf(State::class, $subject);
51  }
52 
56  public function ‪stateObjectCanBeCreatedDataProvider(): array
57  {
58  return [
59  'without states' => [
60  static::TABLE_NAME,
61  [],
62  ],
63  'with states' => [
64  static::TABLE_NAME,
65  ['nonExistingField' => 'invalidState'],
66  ],
67  ];
68  }
69 
78  array $states,
79  array $expected
80  ): void {
82  'first_field',
83  'second_field'
84  );
85 
86  $subject = new ‪State(static::TABLE_NAME, $states);
87 
88  self::assertSame(
89  $expected,
90  $subject->toArray()
91  );
92  }
93 
98  {
99  return [
100  'empty' => [
101  [],
102  [
103  'first_field' => 'parent',
104  'second_field' => 'parent',
105  ],
106  ],
107  'invalid field only' => [
108  [
109  'invalid_field' => 'invalidState',
110  ],
111  [
112  'first_field' => 'parent',
113  'second_field' => 'parent',
114  ],
115  ],
116  'first_field only, valid state' => [
117  [
118  'first_field' => 'custom',
119  ],
120  [
121  'first_field' => 'custom',
122  'second_field' => 'parent',
123  ],
124  ],
125  'first_field only, invalid state' => [
126  [
127  'first_field' => 'invalidState',
128  ],
129  [
130  'first_field' => 'parent',
131  'second_field' => 'parent',
132  ],
133  ],
134  'all valid fields, valid states' => [
135  [
136  'first_field' => 'custom',
137  'second_field' => 'parent',
138  ],
139  [
140  'first_field' => 'custom',
141  'second_field' => 'parent',
142  ],
143  ],
144  'all valid fields, invalid states' => [
145  [
146  'first_field' => 'invalidState',
147  'second_field' => 'invalidState',
148  ],
149  [
150  'first_field' => 'parent',
151  'second_field' => 'parent',
152  ],
153  ],
154  'all valid fields, valid states and invalid field' => [
155  [
156  'invalid_field' => 'invalidState',
157  'first_field' => 'custom',
158  'second_field' => 'parent',
159  ],
160  [
161  'first_field' => 'custom',
162  'second_field' => 'parent',
163  ],
164  ],
165  'all valid fields, invalid states and invalid field' => [
166  [
167  'invalid_field' => 'invalidState',
168  'first_field' => 'invalidState',
169  'second_field' => 'invalidState',
170  ],
171  [
172  'first_field' => 'parent',
173  'second_field' => 'parent',
174  ],
175  ],
176  ];
177  }
178 
184  private function ‪provideTableConfiguration(string ...$fieldNames): array
185  {
186  $columnsConfiguration = [];
187  foreach ($fieldNames as $fieldName) {
188  $columnsConfiguration[$fieldName]['config']['behaviour']['allowLanguageSynchronization'] = true;
189  }
190  return [
191  static::TABLE_NAME => [
192  'columns' => $columnsConfiguration,
193  ],
194  ];
195  }
196 }
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\stateObjectCanBeCreatedDataProvider
‪array stateObjectCanBeCreatedDataProvider()
Definition: StateTest.php:56
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\stateObjectCanBeCreated
‪stateObjectCanBeCreated(string $tableName, array $states)
Definition: StateTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization
Definition: StateTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\provideTableConfiguration
‪array provideTableConfiguration(string ... $fieldNames)
Definition: StateTest.php:184
‪TYPO3\CMS\Core\DataHandling\Localization\State
Definition: State.php:24
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\statesAreEnrichedAndSanitizedOnObjectCreation
‪statesAreEnrichedAndSanitizedOnObjectCreation(array $states, array $expected)
Definition: StateTest.php:77
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\statesAreEnrichedAndSanitizedOnObjectCreationDataProvider
‪array statesAreEnrichedAndSanitizedOnObjectCreationDataProvider()
Definition: StateTest.php:97
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\TABLE_NAME
‪const TABLE_NAME
Definition: StateTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest
Definition: StateTest.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\setUp
‪setUp()
Definition: StateTest.php:33