2 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
20 class RegularExpressionValidatorTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
22 protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\RegularExpressionValidator';
26 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
28 public function regularExpressionValidatorMatchesABasicExpressionCorrectly() {
29 $options = array('regularExpression' => '/^simple[0-9]expression$/');
30 $validator = $this->getMock($this->validatorClassName
, array('translateErrorMessage'), array($options));
31 $this->assertFalse($validator->validate('simple1expression')->hasErrors());
32 $this->assertTrue($validator->validate('simple1expressions')->hasErrors());
37 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
39 public function regularExpressionValidatorCreatesTheCorrectErrorIfTheExpressionDidNotMatch() {
40 $options = array('regularExpression' => '/^simple[0-9]expression$/');
41 $validator = $this->getMock($this->validatorClassName
, array('translateErrorMessage'), array($options));
42 $errors = $validator->validate('some subject that will not match')->getErrors();
43 // we only test for the error code, after the translation Method for message is mocked anyway
44 $this->assertEquals(array(new \TYPO3\CMS\Extbase\Validation\
Error(NULL
, 1221565130)), $errors);