‪TYPO3CMS  10.4
TcaSlugTest.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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪TcaSlugTest extends UnitTestCase
28 {
32  protected ‪$subject;
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->subject = new ‪TcaSlug();
38  }
39 
45  public function ‪resultArrayDataProvider(): array
46  {
47  return [
48  'Language default [0]' => [
49  [
50  'tableName' => 'aTable',
51  'site' => new ‪Site('www.foo.de', 0, [
52  'languages' => [
53  [
54  'languageId' => 0,
55  'locale' => 'en_US.UTF-8',
56  'base' => '/en/'
57  ],
58  [
59  'languageId' => 1,
60  'locale' => 'de_DE.UTF-8',
61  'base' => '/de/'
62  ]
63  ]
64  ]),
65  'databaseRow' => [
66  'sys_language_uid' => [0]
67  ],
68  'processedTca' => [
69  'ctrl' => [
70  'languageField' => 'sys_language_uid'
71  ],
72  'columns' => [
73  'slugField' => [
74  'config' => [
75  'type' => 'slug'
76  ]
77  ]
78  ]
79  ]
80  ],
81  [
82  'tableName' => 'aTable',
83  'site' => new ‪Site('www.foo.de', 0, [
84  'languages' => [
85  [
86  'languageId' => 0,
87  'locale' => 'en_US.UTF-8',
88  'base' => '/en/'
89  ],
90  [
91  'languageId' => 1,
92  'locale' => 'de_DE.UTF-8',
93  'base' => '/de/'
94  ]
95  ]
96  ]),
97  'databaseRow' => [
98  'sys_language_uid' => [0]
99  ],
100  'processedTca' => [
101  'ctrl' => [
102  'languageField' => 'sys_language_uid'
103  ],
104  'columns' => [
105  'slugField' => [
106  'config' => [
107  'type' => 'slug',
108  'appearance' => [
109  'prefix' => '/en'
110  ]
111  ]
112  ]
113  ]
114  ],
115  'customData' => [
116  'slugField' => [
117  'slugPrefix' => '/en'
118  ]
119  ]
120  ]
121  ],
122  'Language 1' => [
123  [
124  'tableName' => 'aTable',
125  'site' => new ‪Site('www.foo.de', 0, [
126  'languages' => [
127  [
128  'languageId' => 0,
129  'locale' => 'en_US.UTF-8',
130  'base' => '/en/'
131  ],
132  [
133  'languageId' => 1,
134  'locale' => 'de_DE.UTF-8',
135  'base' => '/de/'
136  ]
137  ]
138  ]),
139  'databaseRow' => [
140  'sys_language_uid' => [1]
141  ],
142  'processedTca' => [
143  'ctrl' => [
144  'languageField' => 'sys_language_uid'
145  ],
146  'columns' => [
147  'slugField' => [
148  'config' => [
149  'type' => 'slug'
150  ]
151  ]
152  ]
153  ]
154  ],
155  [
156  'tableName' => 'aTable',
157  'site' => new ‪Site('www.foo.de', 0, [
158  'languages' => [
159  [
160  'languageId' => 0,
161  'locale' => 'en_US.UTF-8',
162  'base' => '/en/'
163  ],
164  [
165  'languageId' => 1,
166  'locale' => 'de_DE.UTF-8',
167  'base' => '/de/'
168  ]
169  ]
170  ]),
171  'databaseRow' => [
172  'sys_language_uid' => [1]
173  ],
174  'processedTca' => [
175  'ctrl' => [
176  'languageField' => 'sys_language_uid'
177  ],
178  'columns' => [
179  'slugField' => [
180  'config' => [
181  'type' => 'slug',
182  'appearance' => [
183  'prefix' => '/de'
184  ]
185  ]
186  ]
187  ]
188  ],
189  'customData' => [
190  'slugField' => [
191  'slugPrefix' => '/de'
192  ]
193  ]
194  ]
195  ],
196  'Language -1' => [
197  [
198  'tableName' => 'aTable',
199  'site' => new ‪Site('www.foo.de', 0, [
200  'languages' => [
201  [
202  'languageId' => 0,
203  'locale' => 'en_US.UTF-8',
204  'base' => '/en/'
205  ],
206  [
207  'languageId' => 1,
208  'locale' => 'de_DE.UTF-8',
209  'base' => '/de/'
210  ]
211  ]
212  ]),
213  'databaseRow' => [
214  'sys_language_uid' => [-1]
215  ],
216  'processedTca' => [
217  'ctrl' => [
218  'languageField' => 'sys_language_uid'
219  ],
220  'columns' => [
221  'slugField' => [
222  'config' => [
223  'type' => 'slug'
224  ]
225  ]
226  ]
227  ]
228  ],
229  [
230  'tableName' => 'aTable',
231  'site' => new ‪Site('www.foo.de', 0, [
232  'languages' => [
233  [
234  'languageId' => 0,
235  'locale' => 'en_US.UTF-8',
236  'base' => '/en/'
237  ],
238  [
239  'languageId' => 1,
240  'locale' => 'de_DE.UTF-8',
241  'base' => '/de/'
242  ]
243  ]
244  ]),
245  'databaseRow' => [
246  'sys_language_uid' => [-1]
247  ],
248  'processedTca' => [
249  'ctrl' => [
250  'languageField' => 'sys_language_uid'
251  ],
252  'columns' => [
253  'slugField' => [
254  'config' => [
255  'type' => 'slug',
256  'appearance' => [
257  'prefix' => '/en'
258  ]
259  ]
260  ]
261  ]
262  ],
263  'customData' => [
264  'slugField' => [
265  'slugPrefix' => '/en'
266  ]
267  ]
268  ]
269  ],
270  'UserFunc' => [
271  [
272  'tableName' => 'aTable',
273  'site' => new ‪Site('www.foo.de', 0, [
274  'languages' => [
275  [
276  'languageId' => 0,
277  'locale' => 'en_US.UTF-8',
278  'base' => '/en/'
279  ],
280  [
281  'languageId' => 1,
282  'locale' => 'de_DE.UTF-8',
283  'base' => '/de/'
284  ]
285  ]
286  ]),
287  'databaseRow' => [
288  'sys_language_uid' => [0]
289  ],
290  'processedTca' => [
291  'ctrl' => [
292  'languageField' => 'sys_language_uid'
293  ],
294  'columns' => [
295  'slugField' => [
296  'config' => [
297  'type' => 'slug',
298  'appearance' => [
299  'prefix' => function (array $parameters, ‪TcaSlug $reference): string {
300  return $parameters['site']->getIdentifier()
301  . '-'
302  . $parameters['languageId']
303  . '-'
304  . $parameters['table']
305  . '-'
306  . $parameters['row']['sys_language_uid'][0];
307  }
308  ]
309  ]
310  ]
311  ]
312  ]
313  ],
314  [
315  'tableName' => 'aTable',
316  'site' => new Site('www.foo.de', 0, [
317  'languages' => [
318  [
319  'languageId' => 0,
320  'locale' => 'en_US.UTF-8',
321  'base' => '/en/'
322  ],
323  [
324  'languageId' => 1,
325  'locale' => 'de_DE.UTF-8',
326  'base' => '/de/'
327  ]
328  ]
329  ]),
330  'databaseRow' => [
331  'sys_language_uid' => [0]
332  ],
333  'processedTca' => [
334  'ctrl' => [
335  'languageField' => 'sys_language_uid'
336  ],
337  'columns' => [
338  'slugField' => [
339  'config' => [
340  'type' => 'slug',
341  'appearance' => [
342  'prefix' => 'www.foo.de-0-aTable-0'
343  ]
344  ]
345  ]
346  ]
347  ],
348  'customData' => [
349  'slugField' => [
350  'slugPrefix' => 'www.foo.de-0-aTable-0'
351  ]
352  ]
353  ]
354  ]
355  ];
356  }
357 
365  public function ‪getSlugPrefixForDefinedLanguagesAndUserFunc(array $input, array $expected): void
366  {
367  self::assertEquals($expected, $this->subject->addData($input));
368  }
369 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaSlugTest
Definition: TcaSlugTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaSlugTest\setUp
‪setUp()
Definition: TcaSlugTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaSlugTest\getSlugPrefixForDefinedLanguagesAndUserFunc
‪getSlugPrefixForDefinedLanguagesAndUserFunc(array $input, array $expected)
Definition: TcaSlugTest.php:364
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:40
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaSlug
Definition: TcaSlug.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaSlugTest\resultArrayDataProvider
‪array resultArrayDataProvider()
Definition: TcaSlugTest.php:44
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaSlugTest\$subject
‪TcaSlug $subject
Definition: TcaSlugTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18