[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / RegularExpressionValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
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 /**
18 * Test case
19 */
20 class RegularExpressionValidatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\RegularExpressionValidator';
23
24 /**
25 * @test
26 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
27 */
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());
33 }
34
35 /**
36 * @test
37 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
38 */
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);
45 }
46 }