TYPO3 CMS  TYPO3_6-2
DateValidatorTest.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\\DateValidator', array('dummy'), array(), '', FALSE);
34  }
35 
36  public function validDateProvider() {
37  return array(
38  '28-03-2012' => array(array('%e-%m-%Y', '28-03-2012')),
39  '8-03-2012' => array(array('%e-%m-%Y', '8-03-2012')),
40  '29-02-2012' => array(array('%d-%m-%Y', '29-02-2012'))
41  );
42  }
43 
44  public function invalidDateProvider() {
45  return array(
46  '32-03-2012' => array(array('%d-%m-%Y', '32-03-2012')),
47  '31-13-2012' => array(array('%d-%m-%Y', '31-13-2012')),
48  '29-02-2011' => array(array('%d-%m-%Y', '29-02-2011'))
49  );
50  }
51 
56  public function isValidForValidInputReturnsTrue($input) {
57  $this->subject->setFormat($input[0]);
58  $this->subject->setFieldName('myDate');
59  $requestHandlerMock = $this->helper->getRequestHandler(array(
60  'myDate' => $input[1]
61  ));
62  $this->subject->injectRequestHandler($requestHandlerMock);
63 
64  $this->assertTrue(
65  $this->subject->isValid()
66  );
67  }
68 
73  public function isValidForInvalidInputReturnsFalse($input) {
74  $this->subject->setFormat($input[0]);
75  $this->subject->setFieldName('myDate');
76  $requestHandlerMock = $this->helper->getRequestHandler(array(
77  'myDate' => $input[1]
78  ));
79  $this->subject->injectRequestHandler($requestHandlerMock);
80 
81  $this->assertFalse(
82  $this->subject->isValid()
83  );
84  }
85 }