‪TYPO3CMS  ‪main
IntegerValidatorTest.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;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪IntegerValidatorTest extends FunctionalTestCase
29 {
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
34  $request = (new ‪ServerRequest())->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
35  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
36  }
37 
41  public static function ‪validIntegers(): array
42  {
43  return [
44  [1029437],
45  ['12345'],
46  ['+12345'],
47  ['-12345'],
48  ];
49  }
50 
51  #[DataProvider('validIntegers')]
52  #[Test]
53  public function ‪integerValidatorReturnsNoErrorsForAValidInteger(int|string $integer): void
54  {
56  ‪$validator->setOptions([]);
57  self::assertFalse(‪$validator->validate($integer)->hasErrors());
58  }
59 
63  public static function ‪invalidIntegers(): array
64  {
65  return [
66  ['not a number'],
67  [3.1415],
68  ['12345.987'],
69  ];
70  }
71 
72  #[DataProvider('invalidIntegers')]
73  #[Test]
74  public function ‪integerValidatorReturnsErrorForAnInvalidInteger(float|string $invalidInteger): void
75  {
77  ‪$validator->setOptions([]);
78  self::assertTrue(‪$validator->validate($invalidInteger)->hasErrors());
79  }
80 
81  #[Test]
83  {
85  ‪$validator->setOptions([]);
86  self::assertCount(1, ‪$validator->validate('not a number')->getErrors());
87  }
88 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator
Definition: AlphanumericValidatorTest.php:18
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\IntegerValidatorTest
Definition: IntegerValidatorTest.php:29
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\IntegerValidatorTest\integerValidatorCreatesTheCorrectErrorForAnInvalidSubject
‪integerValidatorCreatesTheCorrectErrorForAnInvalidSubject()
Definition: IntegerValidatorTest.php:82
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\IntegerValidatorTest\invalidIntegers
‪static invalidIntegers()
Definition: IntegerValidatorTest.php:63
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\IntegerValidatorTest\integerValidatorReturnsNoErrorsForAValidInteger
‪integerValidatorReturnsNoErrorsForAValidInteger(int|string $integer)
Definition: IntegerValidatorTest.php:53
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:262
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\IntegerValidatorTest\integerValidatorReturnsErrorForAnInvalidInteger
‪integerValidatorReturnsErrorForAnInvalidInteger(float|string $invalidInteger)
Definition: IntegerValidatorTest.php:74
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\IntegerValidatorTest\validIntegers
‪static validIntegers()
Definition: IntegerValidatorTest.php:41
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\IntegerValidatorTest\setUp
‪setUp()
Definition: IntegerValidatorTest.php:30
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Validation\Validator\IntegerValidator
Definition: IntegerValidator.php:24