TYPO3 CMS  TYPO3_6-2
InArrayValidatorTest.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\\InArrayValidator', array('dummy'), array(), '', FALSE);
34  }
35 
36  public function validArrayProvider() {
37  return array(
38  '12 in (12, 13)' => array(array(array(12, 13), 12))
39  );
40  }
41 
42  public function invalidArrayProvider() {
43  return array(
44  '12 in (11, 13)' => array(array(array(11, 13), 12)),
45  );
46  }
47 
52  public function isValidForValidInputReturnsTrue($input) {
53  $this->subject->setFieldName('myfield');
54  $this->subject->setArray($input[0]);
55  $requestHandlerMock = $this->helper->getRequestHandler(array(
56  'myfield' => $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('myfield');
71  $this->subject->setArray($input[0]);
72  $requestHandlerMock = $this->helper->getRequestHandler(array(
73  'myfield' => $input[1]
74  ));
75  $this->subject->injectRequestHandler($requestHandlerMock);
76 
77  $this->assertFalse(
78  $this->subject->isValid()
79  );
80  }
81 
87  $this->subject->setFieldName('myfield');
88  $this->subject->setArray($input[0]);
89  $this->subject->setStrict(TRUE);
90  $requestHandlerMock = $this->helper->getRequestHandler(array(
91  'myfield' => $input[1]
92  ));
93  $this->subject->injectRequestHandler($requestHandlerMock);
94 
95  $this->assertTrue(
96  $this->subject->isValid()
97  );
98  }
99 
105  $this->subject->setFieldName('myfield');
106  $this->subject->setArray($input[0]);
107  $this->subject->setStrict(TRUE);
108  $requestHandlerMock = $this->helper->getRequestHandler(array(
109  'myfield' => $input[1]
110  ));
111  $this->subject->injectRequestHandler($requestHandlerMock);
112 
113  $this->assertFalse(
114  $this->subject->isValid()
115  );
116  }
117 }