OSDN Git Service

$blocklist['official/dev']
[pukiwiki/pukiwiki_sandbox.git] / spam / SpamPickupTest.php
index 8f0d5ec..8c510f4 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: SpamPickupTest.php,v 1.5 2008/12/27 11:50:55 henoheno Exp $
+// $Id: SpamPickupTest.php,v 1.10 2009/01/02 10:37:47 henoheno Exp $
 // Copyright (C) 2007 heno
 //
 // Design test case for spam.php (called from runner.php)
@@ -259,9 +259,10 @@ class SpamPickupTest extends PHPUnit_TestCase
                        sftp://foobar.example.org:80/dfsdfs#ftp_bat_port80
                        ftp://cnn.example.com&story=breaking_news@10.0.0.1/top_story.htm
                        http://192.168.1.4:443#IPv4
+                       http://localhost/index.php?%2Fofficial&word=f
 EOF;
                $results = uri_pickup_normalize(uri_pickup($test_string));
-               $this->assertEquals(5, count($results));
+               $this->assertEquals(6, count($results));
 
                // ttp://wwW.Example.Org:80#TTP_and_www
                $this->assertEquals('http',           $results[0]['scheme']);
@@ -303,6 +304,26 @@ EOF;
                $this->assertEquals('',               $results[3]['query']);
                $this->assertEquals('',               $results[3]['fragment']);
 
+               // http://192.168.1.4:443#IPv4
+               $this->assertEquals('http',           $results[4]['scheme']);
+               $this->assertEquals('',               $results[4]['userinfo']);
+               $this->assertEquals('192.168.1.4',    $results[4]['host']);
+               $this->assertEquals('443',            $results[4]['port']);
+               $this->assertEquals('/',              $results[4]['path']);
+               $this->assertEquals('',               $results[4]['file']);
+               $this->assertEquals('',               $results[4]['query']);
+               $this->assertEquals('ipv4',           $results[4]['fragment']);
+
+               // http://localhost/index.php?%2Fofficial&word=f
+               $this->assertEquals('http',           $results[5]['scheme']);
+               $this->assertEquals('',               $results[5]['userinfo']);
+               $this->assertEquals('localhost',      $results[5]['host']);
+               $this->assertEquals('',               $results[5]['port']);
+               $this->assertEquals('/',              $results[5]['path']);
+               $this->assertEquals('',               $results[5]['file']);
+               $this->assertEquals('%2fofficial&word=f', $results[5]['query']);
+               $this->assertEquals('',               $results[5]['fragment']);
+
 
                // Specific tests ----
 
@@ -316,6 +337,19 @@ EOF;
                //$results = uri_pickup_normalize(uri_pickup($test_string));
                //$this->assertEquals('percent-encoded.org',  $results[0]['host']);
 
+               // Host: Without path
+               $test_string = ' http://nopathstring.com ';
+               $results = uri_pickup($test_string);
+               $this->assertEquals('', $results[0]['path']);
+               $this->assertEquals('', $results[0]['file']);
+               $results[0]['path'] = '/';
+               $this->assertEquals('', $results[0]['file'], '[Seems referense trouble]');
+               //
+               $results = uri_pickup($test_string);
+               $results = uri_pickup_normalize($results);
+               $this->assertEquals('/',$results[0]['path']);
+               $this->assertEquals('', $results[0]['file']);
+
                // Host: Underscore
                $test_string = ' http://under_score.org/fobar.html ';
                $results = uri_pickup_normalize(uri_pickup($test_string));
@@ -355,6 +389,15 @@ EOF;
                $results = uri_pickup_normalize(uri_pickup($test_string));
                $this->assertEquals('sss',            $results[0]['host']);
                $this->assertEquals('foo.html',       $results[0]['file']);
+
+               // uri_pickup_normalize_pathfile()
+               $test_string = ' http://example.com/path/to/directory-accidentally-not-ended-with-slash ';
+               $results = uri_pickup_normalize_pathfile(uri_pickup($test_string));
+               $this->assertEquals('/path/to/directory-accidentally-not-ended-with-slash', $results[0]['path']);
+               $this->assertEquals(TRUE,  isset($results[0]['path']));
+               $this->assertEquals(FALSE, isset($results[0]['file']));
+               $this->assertEquals('http://example.com/path/to/directory-accidentally-not-ended-with-slash',
+                       uri_pickup_implode($results[0]));
        }
 
        function testFunc_spam_uri_pickup()
@@ -377,6 +420,72 @@ EOF;
                $this->assertEquals('nasty2.example.org', $results[0]['host']);
                $this->assertEquals('search2.example.org',  $results[1]['host']);
        }
+
+       function testFunc_is_ip()
+       {
+               // 1st argument: Null
+               foreach($this->setup_string_null() as $key => $value){
+                       $this->assertEquals(FALSE, is_ip($value), $key);
+               }
+
+               // IPv4
+               foreach(array(
+                               '192.168.1.1',
+                       ) as $value){
+                       $this->assertEquals(4,  is_ip($value), $key, '[' . $value . ']');
+               }
+
+               // IPv6
+               foreach(array(
+                               '::',                           // 0:0:0:0:0:0:0:0
+                               '::192.168.1.1',        // IPv4 within IPv6 network
+                       ) as $value){
+                       $this->assertEquals(6,  is_ip($value), $key, '[' . $value . ']');
+               }
+
+               // Invalid
+               foreach(array(
+                               '',
+                               '.',
+                       ) as $value){
+                       $this->assertEquals(FALSE,      is_ip($value), $key, '[' . $value . ']');
+               }
+       }
+
+       function testFunc_whois_responsibility()
+       {
+               // 1st argument: Null
+               foreach($this->setup_string_null() as $key => $value){
+                       $this->assertEquals('',        whois_responsibility($value), $key);
+               }
+
+               // 'act.edu.au' is known as 3rd level domain
+               $this->AssertEquals('bar.act.edu.au', whois_responsibility('foo.bar.act.edu.au'));
+               $this->AssertEquals('bar.act.edu.au', whois_responsibility('bar.act.edu.au'));
+               $this->AssertEquals('act.edu.au',  whois_responsibility('act.edu.au'));
+               $this->AssertEquals('edu.au',      whois_responsibility('edu.au'));
+               $this->AssertEquals('au',          whois_responsibility('au'));
+
+               // 'co.uk' is known as 2nd level domain
+               $this->AssertEquals('bar.co.uk',   whois_responsibility('foo.bar.co.uk'));
+               $this->AssertEquals('bar.co.uk',   whois_responsibility('bar.co.uk'));
+               $this->AssertEquals('co.uk',       whois_responsibility('co.uk'));
+               $this->AssertEquals('uk',          whois_responsibility('uk'));
+
+               // 'bar.uk' is not 2nd level (implicit responsibility)
+               $this->AssertEquals('bar.uk',      whois_responsibility('foo.bar.uk'));
+               $this->AssertEquals('bar.uk',      whois_responsibility('bar.uk'));
+
+               // IPv4
+               $this->AssertEquals('192.168.0.1', whois_responsibility('192.168.0.1'));
+
+               // Invalid Top-Level Domain (With implicit)
+               $this->AssertEquals('bar.local',  whois_responsibility('foo.bar.local'));       // Implicit responsibility
+               $this->AssertEquals('bar.local',  whois_responsibility('bar.local'));
+               $this->AssertEquals('local',      whois_responsibility('local'));
+               $this->AssertEquals('localhost',  whois_responsibility('localhost'));
+               $this->AssertEquals('s',          whois_responsibility('s'));
+       }
 }
 
 ?>
\ No newline at end of file