‪TYPO3CMS  ‪main
StringValidatorTest.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\Test;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪StringValidatorTest extends FunctionalTestCase
28 {
29  protected function ‪setUp(): void
30  {
31  parent::setUp();
32  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
33  $request = (new ‪ServerRequest())->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
34  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
35  }
36 
37  #[Test]
39  {
40  $subject = new ‪StringValidator();
41  $subject->setOptions([]);
42  self::assertFalse($subject->validate('Hello World')->hasErrors());
43  }
44 
45  #[Test]
47  {
48  $subject = new ‪StringValidator();
49  $subject->setOptions([]);
50  self::assertTrue($subject->validate(42)->hasErrors());
51  }
52 
53  #[Test]
55  {
56  $subject = new ‪StringValidator();
57  $subject->setOptions([]);
58  $object = new class () {
59  public function __toString(): string
60  {
61  return 'ASDF';
62  }
63  };
64  self::assertTrue($subject->validate($object)->hasErrors());
65  }
66 }
‪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\StringValidatorTest\stringValidatorShouldReturnErrorIfNumberIsGiven
‪stringValidatorShouldReturnErrorIfNumberIsGiven()
Definition: StringValidatorTest.php:46
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\StringValidatorTest
Definition: StringValidatorTest.php:28
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\StringValidatorTest\stringValidatorShouldValidateString
‪stringValidatorShouldValidateString()
Definition: StringValidatorTest.php:38
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\StringValidatorTest\stringValidatorShouldReturnErrorIfObjectWithToStringMethodStringIsGiven
‪stringValidatorShouldReturnErrorIfObjectWithToStringMethodStringIsGiven()
Definition: StringValidatorTest.php:54
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\StringValidatorTest\setUp
‪setUp()
Definition: StringValidatorTest.php:29
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Validation\Validator\StringValidator
Definition: StringValidator.php:24