TYPO3 CMS  TYPO3_6-2
IpValidatorTest.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\\IpValidator', array('dummy'), array(), '', FALSE);
34  }
35 
36  public function validIpv4Provider() {
37  return array(
38  '127.0.0.1' => array('127.0.0.1'),
39  '10.0.0.4' => array('10.0.0.4'),
40  '192.168.0.4' => array('192.168.0.4'),
41  '0.0.0.0' => array('0.0.0.0')
42  );
43  }
44 
45  public function invalidIpv4Provider() {
46  return array(
47  '127.0.0.256' => array('127.0.0.256'),
48  '256.0.0.2' => array('256.0.0.2')
49  );
50  }
51 
56  public function isValidForValidInputReturnsTrue($input) {
57  $this->subject->setFieldName('myIp');
58  $requestHandlerMock = $this->helper->getRequestHandler(array(
59  'myIp' => $input
60  ));
61  $this->subject->injectRequestHandler($requestHandlerMock);
62 
63  $this->assertTrue(
64  $this->subject->isValid()
65  );
66  }
67 
72  public function isValidForInvalidInputReturnsFalse($input) {
73  $this->subject->setFieldName('myIp');
74  $requestHandlerMock = $this->helper->getRequestHandler(array(
75  'myIp' => $input
76  ));
77  $this->subject->injectRequestHandler($requestHandlerMock);
78 
79  $this->assertFalse(
80  $this->subject->isValid()
81  );
82  }
83 }