[BUGFIX] Add support for language -1 to TCA field type slug
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / Element / InputSlugElementTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Tests\Unit\Form\Element;
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
18 use TYPO3\CMS\Backend\Form\Element\InputSlugElement;
19 use TYPO3\CMS\Core\Site\Entity\Site;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 /**
23 * Tests for InputSlugElement Form
24 */
25 class InputSlugElementTest extends UnitTestCase
26 {
27 /**
28 * @test
29 */
30 public function getPrefixReturnsDefaultBaseUrlForAllDefinedLanguagesAndMinusOne(): void
31 {
32 $languages = [
33 [
34 'languageId' => 0,
35 'locale' => 'en_US.UTF-8',
36 'base' => '/en/'
37 ],
38 [
39 'languageId' => 1,
40 'locale' => 'de_DE.UTF-8',
41 'base' => '/de/'
42 ]
43 ];
44
45 $site = new Site('www.foo.de', 0, [
46 'languages' => $languages
47 ]);
48
49 $subject = $this->getAccessibleMock(
50 InputSlugElement::class,
51 ['dummy'],
52 [],
53 '',
54 false
55 );
56
57 static::assertSame('/en', $subject->_call('getPrefix', $site, -1));
58 static::assertSame('/en', $subject->_call('getPrefix', $site, 0));
59 static::assertSame('/de', $subject->_call('getPrefix', $site, 1));
60 }
61
62 /**
63 * @test
64 */
65 public function getPrefixThrowsInvalidArgumentExceptionForUndefinedLanguages(): void
66 {
67 $this->expectException(\InvalidArgumentException::class);
68 $this->expectExceptionCode(1522960188);
69
70 $site = new Site('www.foo.de', 0, []);
71
72 $subject = $this->getAccessibleMock(
73 InputSlugElement::class,
74 ['dummy'],
75 [],
76 '',
77 false
78 );
79
80 $subject->_call('getPrefix', $site, 99);
81 }
82 }