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