‪TYPO3CMS  9.5
StateTest.php
Go to the documentation of this file.
1 <?php
2 
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 
24 class ‪StateTest extends UnitTestCase
25 {
26  const ‪TABLE_NAME = 'tx_test_table';
27 
31  protected function ‪setUp()
32  {
33  ‪$GLOBALS['TCA'] = [];
34  }
35 
43  public function ‪stateObjectCanBeCreated(string $tableName, array $states)
44  {
45  $subject = new ‪State($tableName, $states);
46 
47  $this->assertInstanceOf(State::class, $subject);
48  }
49 
53  public function ‪stateObjectCanBeCreatedDataProvider(): array
54  {
55  return [
56  'without states' => [
57  static::TABLE_NAME,
58  [],
59  ],
60  'with states' => [
61  static::TABLE_NAME,
62  ['nonExistingField' => 'invalidState'],
63  ],
64  ];
65  }
66 
75  array $states,
76  array $expected
77  ) {
79  'first_field',
80  'second_field'
81  );
82 
83  $subject = new ‪State(static::TABLE_NAME, $states);
84 
85  $this->assertSame(
86  $expected,
87  $subject->toArray()
88  );
89  }
90 
95  {
96  return [
97  'empty' => [
98  [],
99  [
100  'first_field' => 'parent',
101  'second_field' => 'parent',
102  ],
103  ],
104  'invalid field only' => [
105  [
106  'invalid_field' => 'invalidState',
107  ],
108  [
109  'first_field' => 'parent',
110  'second_field' => 'parent',
111  ],
112  ],
113  'first_field only, valid state' => [
114  [
115  'first_field' => 'custom',
116  ],
117  [
118  'first_field' => 'custom',
119  'second_field' => 'parent',
120  ],
121  ],
122  'first_field only, invalid state' => [
123  [
124  'first_field' => 'invalidState',
125  ],
126  [
127  'first_field' => 'parent',
128  'second_field' => 'parent',
129  ],
130  ],
131  'all valid fields, valid states' => [
132  [
133  'first_field' => 'custom',
134  'second_field' => 'parent',
135  ],
136  [
137  'first_field' => 'custom',
138  'second_field' => 'parent',
139  ],
140  ],
141  'all valid fields, invalid states' => [
142  [
143  'first_field' => 'invalidState',
144  'second_field' => 'invalidState',
145  ],
146  [
147  'first_field' => 'parent',
148  'second_field' => 'parent',
149  ],
150  ],
151  'all valid fields, valid states and invalid field' => [
152  [
153  'invalid_field' => 'invalidState',
154  'first_field' => 'custom',
155  'second_field' => 'parent',
156  ],
157  [
158  'first_field' => 'custom',
159  'second_field' => 'parent',
160  ],
161  ],
162  'all valid fields, invalid states and invalid field' => [
163  [
164  'invalid_field' => 'invalidState',
165  'first_field' => 'invalidState',
166  'second_field' => 'invalidState',
167  ],
168  [
169  'first_field' => 'parent',
170  'second_field' => 'parent',
171  ],
172  ],
173  ];
174  }
175 
181  private function ‪provideTableConfiguration(string ...$fieldNames): array
182  {
183  $columnsConfiguration = [];
184  foreach ($fieldNames as $fieldName) {
185  $columnsConfiguration[$fieldName]['config']['behaviour']['allowLanguageSynchronization'] = true;
186  }
187  return [
188  static::TABLE_NAME => [
189  'columns' => $columnsConfiguration,
190  ],
191  ];
192  }
193 }
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\stateObjectCanBeCreatedDataProvider
‪array stateObjectCanBeCreatedDataProvider()
Definition: StateTest.php:53
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\stateObjectCanBeCreated
‪stateObjectCanBeCreated(string $tableName, array $states)
Definition: StateTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization
Definition: StateTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\provideTableConfiguration
‪array provideTableConfiguration(string ... $fieldNames)
Definition: StateTest.php:181
‪TYPO3\CMS\Core\DataHandling\Localization\State
Definition: State.php:23
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\statesAreEnrichedAndSanitizedOnObjectCreation
‪statesAreEnrichedAndSanitizedOnObjectCreation(array $states, array $expected)
Definition: StateTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\statesAreEnrichedAndSanitizedOnObjectCreationDataProvider
‪array statesAreEnrichedAndSanitizedOnObjectCreationDataProvider()
Definition: StateTest.php:94
‪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