‪TYPO3CMS  10.4
RegularExpressionValidatorTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪RegularExpressionValidatorTest extends UnitTestCase
26 {
30  protected ‪$validatorClassName = RegularExpressionValidator::class;
31 
36  {
37  $options = ['regularExpression' => '/^simple[0-9]expression$/'];
38  ‪$validator = $this->getMockBuilder($this->validatorClassName)
39  ->setMethods(['translateErrorMessage'])
40  ->setConstructorArgs([$options])
41  ->getMock();
42  self::assertFalse(‪$validator->validate('simple1expression')->hasErrors());
43  self::assertTrue(‪$validator->validate('simple1expressions')->hasErrors());
44  }
45 
50  {
51  $options = ['regularExpression' => '/^simple[0-9]expression$/'];
52  ‪$validator = $this->getMockBuilder($this->validatorClassName)
53  ->setMethods(['translateErrorMessage'])
54  ->setConstructorArgs([$options])
55  ->getMock();
56  ‪$errors = ‪$validator->validate('some subject that will not match')->getErrors();
57  // we only test for the error code, after the translation Method for message is mocked anyway
58  self::assertEquals([new ‪Error('', 1221565130)], ‪$errors);
59  }
60 }
‪TYPO3\CMS\Extbase\Validation\Validator\RegularExpressionValidator
Definition: RegularExpressionValidator.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\RegularExpressionValidatorTest\$validatorClassName
‪string $validatorClassName
Definition: RegularExpressionValidatorTest.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\RegularExpressionValidatorTest\regularExpressionValidatorMatchesABasicExpressionCorrectly
‪regularExpressionValidatorMatchesABasicExpressionCorrectly()
Definition: RegularExpressionValidatorTest.php:34
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:25
‪TYPO3\CMS\Extbase\Validation\Error
Definition: Error.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\RegularExpressionValidatorTest\regularExpressionValidatorCreatesTheCorrectErrorIfTheExpressionDidNotMatch
‪regularExpressionValidatorCreatesTheCorrectErrorIfTheExpressionDidNotMatch()
Definition: RegularExpressionValidatorTest.php:48
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\RegularExpressionValidatorTest
Definition: RegularExpressionValidatorTest.php:26
‪$errors
‪$errors
Definition: annotationChecker.php:121
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
Definition: AbstractCompositeValidatorTest.php:16