2010-10-18 06:26:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
|
|
|
class IpTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
|
2011-10-06 02:07:15 +02:00
|
|
|
protected $ipValidator;
|
2010-10-18 06:26:02 +02:00
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2011-10-06 02:07:15 +02:00
|
|
|
$this->ipValidator = new Ip;
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForIp
|
|
|
|
*
|
|
|
|
*/
|
2011-10-06 02:07:15 +02:00
|
|
|
public function test_valid_ips_should_return_True($input, $options=null)
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2011-10-06 02:07:15 +02:00
|
|
|
$this->ipValidator->ipOptions = $options;
|
|
|
|
$this->assertTrue($this->ipValidator->validate($input));
|
|
|
|
$this->assertTrue($this->ipValidator->assert($input));
|
|
|
|
$this->assertTrue($this->ipValidator->check($input));
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForNotIp
|
2010-12-07 20:17:43 +01:00
|
|
|
* @expectedException Respect\Validation\Exceptions\IpException
|
2010-10-18 06:26:02 +02:00
|
|
|
*/
|
2011-10-06 02:07:15 +02:00
|
|
|
public function test_invalid_ips_should_throw_IpException($input, $options=null)
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2011-10-06 02:07:15 +02:00
|
|
|
$this->ipValidator->ipOptions = $options;
|
|
|
|
$this->assertFalse($this->ipValidator->validate($input));
|
|
|
|
$this->assertFalse($this->ipValidator->assert($input));
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForIp()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('127.0.0.1'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForNotIp()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(null),
|
|
|
|
array('j'),
|
|
|
|
array(' '),
|
|
|
|
array('Foo'),
|
|
|
|
array(''),
|
|
|
|
array('192.168.0.1', FILTER_FLAG_NO_PRIV_RANGE),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-02-10 21:49:48 +01:00
|
|
|
}
|