Browse Source

#ZF-8253

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18909 44c647ce-9c0f-0410-b52a-842ac1e357ba
freak 16 years ago
parent
commit
1e0bb4b34a
1 changed files with 86 additions and 45 deletions
  1. 86 45
      tests/Zend/Validate/IpTest.php

+ 86 - 45
tests/Zend/Validate/IpTest.php

@@ -99,58 +99,99 @@ class Zend_Validate_IpTest extends PHPUnit_Framework_TestCase
 
     /**
      * @see ZF-2694
+     * @see ZF-8253
      */
     public function testIPv6addresses()
     {
-        if (!function_exists('inet_pton')) {
-            $this->markTestIncomplete('No IPv6 support within this PHP release');
-        }
+        $IPs = array(
+            '2001:0db8:0000:0000:0000:0000:1428:57ab'   => true,
+            '2001:0DB8:0000:0000:0000:0000:1428:57AB'   => true,
+            '2001:00db8:0000:0000:0000:0000:1428:57ab'  => false,
+            '2001:0db8:xxxx:0000:0000:0000:1428:57ab'   => false,
 
-        $this->assertTrue($this->_validator->isValid('::127.0.0.1'));
-    }
-    
-    /**
-     * @see ZF-8253
-     */
-    public function testMoreIPv6Addresses()
-    {
-        $ips = array(
-                     '2001:0db8:0000:0000:0000:0000:1428:57ab',
-                     '2001:0DB8:0000:0000:0000:0000:1428:57AB',
-                     'a:b:c::1.2.3.4',
-                     'a:b:c:d::1.2.3.4',
-                     'a:b:c:d:e:f:1.2.3.4',
-                     'a::c:d:e:f:0:1',
-                     'a::0:1',
-                     '::e:f',
-                     'a:b:c:d:e:f::0');
-        foreach($ips as $ip) {
-            $this->assertTrue($this->_validator->isValid($ip));
-        }
-    }
-    
-    /**
-     * @see ZF-8253
-     * @see http://bugs.php.net/bug.php?id=50117
-     */
-    public function testMoreIPv6AddressesPHPdidWrong()
-    {
-        $validIps = array('a:b:c:d:e::1.2.3.4',
-                          '::0:a:b:c:d:e:f',
-                          '0:a:b:c:d:e:f::');
-        $invalidIps = array('::01.02.03.04',
-                            '0:0:0:255.255.255.255');
-        
-        foreach($validIps as $ip) {
-            $this->assertTrue($this->_validator->isValid($ip));
-        }
-        
-        foreach($invalidIps as $ip) {
-            $this->assertFalse($this->_validator->isValid($ip));
+            '2001:db8::1428:57ab'   => true,
+            '2001:db8::1428::57ab'  => false,
+            '2001:dx0::1234'        => false,
+            '2001:db0::12345'       => false,
+
+            ''                      => false,
+            ':'                     => false,
+            '::'                    => true,
+            ':::'                   => false,
+            '::::'                  => false,
+            '::1'                   => true,
+            ':::1'                  => false,
+
+            '::1.2.3.4'             => true,
+            '::127.0.0.1'           => true,
+            '::256.0.0.1'           => false,
+            '::01.02.03.04'         => false,
+            'a:b:c::1.2.3.4'        => true,
+            'a:b:c:d::1.2.3.4'      => true,
+            'a:b:c:d:e::1.2.3.4'    => true,
+            'a:b:c:d:e:f:1.2.3.4'   => true,
+            'a:b:c:d:e:f:1.256.3.4' => false,
+            'a:b:c:d:e:f::1.2.3.4'  => false,
+
+            'a:b:c:d:e:f:0:1:2'     => false,
+            'a:b:c:d:e:f:0:1'       => true,
+            'a::b:c:d:e:f:0:1'      => false,
+            'a::c:d:e:f:0:1'        => true,
+            'a::d:e:f:0:1'          => true,
+            'a::e:f:0:1'            => true,
+            'a::f:0:1'              => true,
+            'a::0:1'                => true,
+            'a::1'                  => true,
+            'a::'                   => true,
+
+            '::0:1:a:b:c:d:e:f'     => false,
+//            '::0:a:b:c:d:e:f'       => false,  //
+            '::a:b:c:d:e:f'         => true,
+            '::b:c:d:e:f'           => true,
+            '::c:d:e:f'             => true,
+            '::d:e:f'               => true,
+            '::e:f'                 => true,
+            '::f'                   => true,
+
+            '0:1:a:b:c:d:e:f::'     => false,
+//            '0:a:b:c:d:e:f::'       => false,  //
+            'a:b:c:d:e:f::'         => true,
+            'b:c:d:e:f::'           => true,
+            'c:d:e:f::'             => true,
+            'd:e:f::'               => true,
+            'e:f::'                 => true,
+            'f::'                   => true,
+
+            'a:b:::e:f'             => false,
+            '::a:'                  => false,
+            '::a::'                 => false,
+            ':a::b'                 => false,
+            'a::b:'                 => false,
+            '::a:b::c'              => false,
+            'abcde::f'              => false,
+
+            ':10.0.0.1'             => false,
+            '0:0:0:255.255.255.255' => false,
+            '1fff::a88:85a3::172.31.128.1' => false,
+
+            'a:b:c:d:e:f:0::1'      => false,
+//            'a:b:c:d:e:f:0::'       => false,
+            'a:b:c:d:e:f::0'        => true,
+            'a:b:c:d:e:f::'         => true,
+
+            'total gibberish'       => false
+        );
+
+        foreach($IPs as $ip => $expectedOutcome) {
+            if($expectedOutcome) {
+                $this->assertTrue($this->_validator->isValid($ip));
+            } else {
+                $this->assertFalse($this->_validator->isValid($ip));
+            }
         }
+
     }
     
-
     /**
      * @ZF-4352
      */