‪TYPO3CMS  ‪main
MinValueTest.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;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
30 final class ‪MinValueTest extends FunctionalTestCase
31 {
32  protected array ‪$testExtensionsToLoad = [
33  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler',
34  ];
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  $this->importCSVDataSet(__DIR__ . '/DataSet/MinValuePages.csv');
40  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users.csv');
41  $backendUser = $this->setUpBackendUser(1);
42  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
43  }
44 
45  public static function ‪valuesLowerThanMinResetToEmptyStringDataProvider(): iterable
46  {
47  yield 'Too few characters result in empty string' => [
48  'value' => 'Too short',
49  'expected' => '',
50  ];
51 
52  yield 'More than "min" characters stay the same' => [
53  'value' => 'This has enough length',
54  'expected' => 'This has enough length',
55  ];
56 
57  yield 'With unicode exact chars stays the same' => [
58  'value' => "123456789\u{1F421}",
59  'expected' => "123456789\u{1F421}",
60  ];
61 
62  yield 'With unicode too few chars results in empty' => [
63  'value' => "12345678\u{1F421}",
64  'expected' => '',
65  ];
66  }
67 
68  #[DataProvider('valuesLowerThanMinResetToEmptyStringDataProvider')]
69  #[Test]
70  public function ‪valuesLowerThanMinResetToEmptyString(string $value, string $expected): void
71  {
72  // Should work for type=input and type=text (except RTE).
73  $actionService = new ActionService();
74  $map = $actionService->createNewRecord('tt_content', 1, [
75  'tx_testdatahandler_input_minvalue' => $value,
76  'tx_testdatahandler_text_minvalue' => $value,
77  ]);
78  $newRecordId = reset($map['tt_content']);
79  $newRecord = BackendUtility::getRecord('tt_content', $newRecordId);
80  self::assertEquals($expected, $newRecord['tx_testdatahandler_input_minvalue']);
81  self::assertEquals($expected, $newRecord['tx_testdatahandler_text_minvalue']);
82  }
83 
84  #[Test]
85  public function ‪minDoesNotWorkForRTE(): void
86  {
87  $actionService = new ActionService();
88  $map = $actionService->createNewRecord('tt_content', 1, [
89  'tx_testdatahandler_richttext_minvalue' => 'Not working',
90  ]);
91  $newRecordId = reset($map['tt_content']);
92  $newRecord = BackendUtility::getRecord('tt_content', $newRecordId);
93  self::assertEquals('Not working', $newRecord['tx_testdatahandler_richttext_minvalue']);
94  }
95 
96  #[Test]
97  public function ‪minValueZeroIsIgnored(): void
98  {
99  $actionService = new ActionService();
100  $map = $actionService->createNewRecord('tt_content', 1, [
101  'tx_testdatahandler_input_minvalue_zero' => 'test123',
102  ]);
103  $newRecordId = reset($map['tt_content']);
104  $newRecord = BackendUtility::getRecord('tt_content', $newRecordId);
105  self::assertEquals('test123', $newRecord['tx_testdatahandler_input_minvalue_zero']);
106  }
107 }
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MinValueTest
Definition: MinValueTest.php:31
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MinValueTest\minDoesNotWorkForRTE
‪minDoesNotWorkForRTE()
Definition: MinValueTest.php:85
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MinValueTest\minValueZeroIsIgnored
‪minValueZeroIsIgnored()
Definition: MinValueTest.php:97
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MinValueTest\valuesLowerThanMinResetToEmptyStringDataProvider
‪static valuesLowerThanMinResetToEmptyStringDataProvider()
Definition: MinValueTest.php:45
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MinValueTest\setUp
‪setUp()
Definition: MinValueTest.php:36
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MinValueTest\valuesLowerThanMinResetToEmptyString
‪valuesLowerThanMinResetToEmptyString(string $value, string $expected)
Definition: MinValueTest.php:70
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\MinValueTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: MinValueTest.php:32
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular
Definition: CheckValueTest.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25