TYPO3 CMS  TYPO3_6-2
RegExpValidatorTest.php
Go to the documentation of this file.
1 <?php
20 
24  protected $helper;
25 
29  protected $subject;
30 
31  public function setUp() {
32  $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
33  $this->subject = $this->getMock('TYPO3\\CMS\\Form\\Validation\\RegExpValidator', array('dummy'), array(), '', FALSE);
34  }
35 
36  public function validDataProvider() {
37  return array(
38  '/^a/ matches a' => array(array('/^a/', 'a')),
39  );
40  }
41 
42  public function invalidDataProvider() {
43  return array(
44  '/[^\d]/ matches 8' => array(array('/[^\d]/', 8)),
45  );
46  }
47 
52  public function isValidForValidInputReturnsTrue($input) {
53  $this->subject->setFieldName('myRegexp');
54  $this->subject->setRegularExpression($input[0]);
55  $requestHandlerMock = $this->helper->getRequestHandler(array(
56  'myRegexp' => $input[1]
57  ));
58  $this->subject->injectRequestHandler($requestHandlerMock);
59 
60  $this->assertTrue(
61  $this->subject->isValid()
62  );
63  }
64 
69  public function isValidForInvalidInputReturnsFalse($input) {
70  $this->subject->setFieldName('myRegexp');
71  $this->subject->setRegularExpression($input[0]);
72  $requestHandlerMock = $this->helper->getRequestHandler(array(
73  'myRegexp' => $input[1]
74  ));
75  $this->subject->injectRequestHandler($requestHandlerMock);
76 
77  $this->assertFalse(
78  $this->subject->isValid()
79  );
80  }
81 }