[TASK] Cleanup StringValidatorTest
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / StringValidatorTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
4
5 /* *
6 * This script belongs to the Extbase framework. *
7 * *
8 * It is free software; you can redistribute it and/or modify it under *
9 * the terms of the GNU Lesser General Public License as published by the *
10 * Free Software Foundation, either version 3 of the License, or (at your *
11 * option) any later version. *
12 * *
13 * This script is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
15 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
16 * General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with the script. *
20 * If not, see http://www.gnu.org/licenses/lgpl.html *
21 * *
22 * The TYPO3 project - inspiring people to share! *
23 * */
24
25 use TYPO3\CMS\Extbase\Validation\Validator\StringValidator;
26
27 /**
28 * Testcase for the string length validator
29 *
30 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
31 */
32 class StringValidatorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
33 {
34 /**
35 * @test
36 */
37 public function stringValidatorShouldValidateString()
38 {
39 $this->assertFalse((new StringValidator())->validate('Hello World')->hasErrors());
40 }
41
42 /**
43 * @test
44 */
45 public function stringValidatorShouldReturnErrorIfNumberIsGiven()
46 {
47 /** @var StringValidator $validator */
48 $validator = $this->getMockBuilder(StringValidator::class)
49 ->setMethods(['translateErrorMessage'])
50 ->getMock();
51
52 $this->assertTrue($validator->validate(42)->hasErrors());
53 }
54
55 /**
56 * @test
57 */
58 public function stringValidatorShouldReturnErrorIfObjectWithToStringMethodStringIsGiven()
59 {
60 /** @var StringValidator $validator */
61 $validator = $this->getMockBuilder(StringValidator::class)
62 ->setMethods(['translateErrorMessage'])
63 ->getMock();
64
65 $object = new class() {
66 /** @return string */
67 public function __toString()
68 {
69 return 'ASDF';
70 }
71 };
72
73 $this->assertTrue($validator->validate($object)->hasErrors());
74 }
75 }