‪TYPO3CMS  10.4
StateTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪StateTest extends UnitTestCase
25 {
26  const ‪TABLE_NAME = 'tx_test_table';
27 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  ‪$GLOBALS['TCA'] = [];
35  }
36 
44  public function ‪stateObjectCanBeCreated(string $tableName, array $states)
45  {
46  $subject = new ‪State($tableName, $states);
47 
48  self::assertInstanceOf(State::class, $subject);
49  }
50 
54  public function ‪stateObjectCanBeCreatedDataProvider(): array
55  {
56  return [
57  'without states' => [
58  static::TABLE_NAME,
59  [],
60  ],
61  'with states' => [
62  static::TABLE_NAME,
63  ['nonExistingField' => 'invalidState'],
64  ],
65  ];
66  }
67 
76  array $states,
77  array $expected
78  ) {
80  'first_field',
81  'second_field'
82  );
83 
84  $subject = new ‪State(static::TABLE_NAME, $states);
85 
86  self::assertSame(
87  $expected,
88  $subject->toArray()
89  );
90  }
91 
96  {
97  return [
98  'empty' => [
99  [],
100  [
101  'first_field' => 'parent',
102  'second_field' => 'parent',
103  ],
104  ],
105  'invalid field only' => [
106  [
107  'invalid_field' => 'invalidState',
108  ],
109  [
110  'first_field' => 'parent',
111  'second_field' => 'parent',
112  ],
113  ],
114  'first_field only, valid state' => [
115  [
116  'first_field' => 'custom',
117  ],
118  [
119  'first_field' => 'custom',
120  'second_field' => 'parent',
121  ],
122  ],
123  'first_field only, invalid state' => [
124  [
125  'first_field' => 'invalidState',
126  ],
127  [
128  'first_field' => 'parent',
129  'second_field' => 'parent',
130  ],
131  ],
132  'all valid fields, valid states' => [
133  [
134  'first_field' => 'custom',
135  'second_field' => 'parent',
136  ],
137  [
138  'first_field' => 'custom',
139  'second_field' => 'parent',
140  ],
141  ],
142  'all valid fields, invalid states' => [
143  [
144  'first_field' => 'invalidState',
145  'second_field' => 'invalidState',
146  ],
147  [
148  'first_field' => 'parent',
149  'second_field' => 'parent',
150  ],
151  ],
152  'all valid fields, valid states and invalid field' => [
153  [
154  'invalid_field' => 'invalidState',
155  'first_field' => 'custom',
156  'second_field' => 'parent',
157  ],
158  [
159  'first_field' => 'custom',
160  'second_field' => 'parent',
161  ],
162  ],
163  'all valid fields, invalid states and invalid field' => [
164  [
165  'invalid_field' => 'invalidState',
166  'first_field' => 'invalidState',
167  'second_field' => 'invalidState',
168  ],
169  [
170  'first_field' => 'parent',
171  'second_field' => 'parent',
172  ],
173  ],
174  ];
175  }
176 
182  private function ‪provideTableConfiguration(string ...$fieldNames): array
183  {
184  $columnsConfiguration = [];
185  foreach ($fieldNames as $fieldName) {
186  $columnsConfiguration[$fieldName]['config']['behaviour']['allowLanguageSynchronization'] = true;
187  }
188  return [
189  static::TABLE_NAME => [
190  'columns' => $columnsConfiguration,
191  ],
192  ];
193  }
194 }
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\stateObjectCanBeCreatedDataProvider
‪array stateObjectCanBeCreatedDataProvider()
Definition: StateTest.php:54
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\stateObjectCanBeCreated
‪stateObjectCanBeCreated(string $tableName, array $states)
Definition: StateTest.php:44
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization
Definition: StateTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\provideTableConfiguration
‪array provideTableConfiguration(string ... $fieldNames)
Definition: StateTest.php:182
‪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:75
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\statesAreEnrichedAndSanitizedOnObjectCreationDataProvider
‪array statesAreEnrichedAndSanitizedOnObjectCreationDataProvider()
Definition: StateTest.php:95
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\TABLE_NAME
‪const TABLE_NAME
Definition: StateTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest
Definition: StateTest.php:25
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\setUp
‪setUp()
Definition: StateTest.php:31