TYPO3 CMS  TYPO3_6-2
LengthValidatorTest.php
Go to the documentation of this file.
1 <?php
20 
24  protected $helper;
25 
29  protected $subject;
30 
34  public function setUp() {
35  $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
36  $charsetConverterMock = $this->getMock('TYPO3\\CMS\\Core\\Charset\\CharsetConverter', array(), array(), '', FALSE);
37  $charsetConverterMock->expects($this->any())->method('strlen')
38  ->will($this->returnCallback(function ($charset, $value) {
39  return mb_strlen($value, $charset);
40  }));
41  $this->subject = $this->getAccessibleMock('TYPO3\\CMS\\Form\\Validation\\LengthValidator', array('dummy'), array(), '', FALSE);
42  $this->subject->_set('charsetConverter', $charsetConverterMock);
43  }
44 
48  public function validLengthProvider() {
49  return array(
50  '4 ≤ length(myString) ≤ 8' => array(
51  array(4, 8, 'mäString')
52  ),
53  '8 ≤ length(myString) ≤ 8' => array(
54  array(8, 8, 'möString')
55  ),
56  '4 ≤ length(myString)' => array(
57  array(4, NULL, 'myString')
58  ),
59  '4 ≤ length(asdf) ≤ 4' => array(
60  array(4, 4, 'asdf')
61  ),
62  );
63  }
64 
69  public function isValidForValidInputReturnsTrue($input) {
70  $this->subject->setFieldName('myLength');
71  $this->subject->setMinimum($input[0]);
72  $this->subject->setMaximum($input[1]);
73  $requestHandlerMock = $this->helper->getRequestHandler(array(
74  'myLength' => $input[2]
75  ));
76  $this->subject->injectRequestHandler($requestHandlerMock);
77 
78  $this->assertTrue(
79  $this->subject->isValid()
80  );
81  }
82 
86  public function invalidLengthProvider() {
87  return array(
88  '4 ≤ length(my) ≤ 12' => array(
89  array(4, 12, 'my')
90  ),
91  '4 ≤ length(my long string) ≤ 12' => array(
92  array(4, 12, 'my long string')
93  ),
94  );
95  }
96 
101  public function isValidForInvalidInputReturnsFalse($input) {
102  $this->subject->setFieldName('myLength');
103  $this->subject->setMinimum($input[0]);
104  $this->subject->setMaximum($input[1]);
105  $requestHandlerMock = $this->helper->getRequestHandler(array(
106  'myLength' => $input[2]
107  ));
108  $this->subject->injectRequestHandler($requestHandlerMock);
109 
110  $this->assertFalse(
111  $this->subject->isValid()
112  );
113  }
114 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)