‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪StateTest extends UnitTestCase
26 {
27  public const ‪TABLE_NAME = 'tx_test_table';
28 
29  protected function ‪setUp(): void
30  {
31  parent::setUp();
32  ‪$GLOBALS['TCA'] = [];
33  }
34 
35  #[DataProvider('stateObjectCanBeCreatedDataProvider')]
36  #[Test]
37  public function ‪stateObjectCanBeCreated(string $tableName, array $states): void
38  {
39  $subject = new ‪State($tableName, $states);
40 
41  self::assertInstanceOf(State::class, $subject);
42  }
43 
44  public static function ‪stateObjectCanBeCreatedDataProvider(): array
45  {
46  return [
47  'without states' => [
48  static::TABLE_NAME,
49  [],
50  ],
51  'with states' => [
52  static::TABLE_NAME,
53  ['nonExistingField' => 'invalidState'],
54  ],
55  ];
56  }
57 
58  #[DataProvider('statesAreEnrichedAndSanitizedOnObjectCreationDataProvider')]
59  #[Test]
61  array $states,
62  array $expected
63  ): void {
65  'first_field',
66  'second_field'
67  );
68 
69  $subject = new ‪State(static::TABLE_NAME, $states);
70 
71  self::assertSame(
72  $expected,
73  $subject->toArray()
74  );
75  }
76 
78  {
79  return [
80  'empty' => [
81  [],
82  [
83  'first_field' => 'parent',
84  'second_field' => 'parent',
85  ],
86  ],
87  'invalid field only' => [
88  [
89  'invalid_field' => 'invalidState',
90  ],
91  [
92  'first_field' => 'parent',
93  'second_field' => 'parent',
94  ],
95  ],
96  'first_field only, valid state' => [
97  [
98  'first_field' => 'custom',
99  ],
100  [
101  'first_field' => 'custom',
102  'second_field' => 'parent',
103  ],
104  ],
105  'first_field only, invalid state' => [
106  [
107  'first_field' => 'invalidState',
108  ],
109  [
110  'first_field' => 'parent',
111  'second_field' => 'parent',
112  ],
113  ],
114  'all valid fields, valid states' => [
115  [
116  'first_field' => 'custom',
117  'second_field' => 'parent',
118  ],
119  [
120  'first_field' => 'custom',
121  'second_field' => 'parent',
122  ],
123  ],
124  'all valid fields, invalid states' => [
125  [
126  'first_field' => 'invalidState',
127  'second_field' => 'invalidState',
128  ],
129  [
130  'first_field' => 'parent',
131  'second_field' => 'parent',
132  ],
133  ],
134  'all valid fields, valid states and invalid field' => [
135  [
136  'invalid_field' => 'invalidState',
137  'first_field' => 'custom',
138  'second_field' => 'parent',
139  ],
140  [
141  'first_field' => 'custom',
142  'second_field' => 'parent',
143  ],
144  ],
145  'all valid fields, invalid states and invalid field' => [
146  [
147  'invalid_field' => 'invalidState',
148  'first_field' => 'invalidState',
149  'second_field' => 'invalidState',
150  ],
151  [
152  'first_field' => 'parent',
153  'second_field' => 'parent',
154  ],
155  ],
156  ];
157  }
158 
162  private function ‪provideTableConfiguration(string ...$fieldNames): array
163  {
164  $columnsConfiguration = [];
165  foreach ($fieldNames as $fieldName) {
166  $columnsConfiguration[$fieldName]['config']['behaviour']['allowLanguageSynchronization'] = true;
167  }
168  return [
169  static::TABLE_NAME => [
170  'columns' => $columnsConfiguration,
171  ],
172  ];
173  }
174 }
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\stateObjectCanBeCreated
‪stateObjectCanBeCreated(string $tableName, array $states)
Definition: StateTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization
Definition: StateTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\statesAreEnrichedAndSanitizedOnObjectCreationDataProvider
‪static statesAreEnrichedAndSanitizedOnObjectCreationDataProvider()
Definition: StateTest.php:77
‪TYPO3\CMS\Core\DataHandling\Localization\State
Definition: State.php:26
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\statesAreEnrichedAndSanitizedOnObjectCreation
‪statesAreEnrichedAndSanitizedOnObjectCreation(array $states, array $expected)
Definition: StateTest.php:60
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\TABLE_NAME
‪const TABLE_NAME
Definition: StateTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\stateObjectCanBeCreatedDataProvider
‪static stateObjectCanBeCreatedDataProvider()
Definition: StateTest.php:44
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest
Definition: StateTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Localization\StateTest\provideTableConfiguration
‪provideTableConfiguration(string ... $fieldNames)
Definition: StateTest.php:162
‪$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:29