2 // $Id: SpamTest.php,v 1.27 2009/01/04 08:56:07 henoheno Exp $
3 // Copyright (C) 2007-2009 heno
5 // Design test case for spam.php (called from runner.php)
7 if (! defined('SPAM_INI_FILE')) define('SPAM_INI_FILE', 'spam.ini.php');
9 require_once('spam.php');
10 require_once('PHPUnit/PHPUnit.php');
12 class SpamTest extends PHPUnit_TestCase
15 function setup_string_null()
21 '[array(foobar)]' => array('foobar'),
28 function testFunc_generate_glob_regex()
31 foreach($this->setup_string_null() as $key => $value){
32 $this->assertEquals('', generate_glob_regex($value), $key);
35 $this->assertEquals('.*\.txt', generate_glob_regex('*.txt'));
36 $this->assertEquals('A.A', generate_glob_regex('A?A'));
39 function testFunc_generate_host_regex()
42 foreach($this->setup_string_null() as $key => $value){
43 $this->assertEquals('', generate_host_regex($value), $key);
46 $this->assertEquals('localhost', generate_host_regex('localhost'));
47 $this->assertEquals('example\.org', generate_host_regex('example.org'));
48 $this->assertEquals('(?:.*\.)?example\.org', generate_host_regex('.example.org'));
49 $this->assertEquals('.*\.example\.org', generate_host_regex('*.example.org'));
50 $this->assertEquals('.*\..*\.example\.org', generate_host_regex('*.*.example.org'));
51 $this->assertEquals('10\.20\.30\.40', generate_host_regex('10.20.30.40'));
53 // Should match with 192.168.0.0/16
54 //$this->assertEquals('192\.168\.', generate_host_regex('192.168.'));
57 function testFunc_get_blocklist()
59 if (! defined('SPAM_INI_FILE') || ! file_exists(SPAM_INI_FILE)) {
60 $this->fail('SPAM_INI_FILE not defined or not found');
64 // get_blocklist_add()
67 get_blocklist_add($array, 'foo', 'bar');
68 $this->assertEquals(1, count($array));
69 $this->assertEquals('bar', $array['foo']);
71 get_blocklist_add($array, 'hoge', 'fuga');
72 $this->assertEquals(2, count($array));
73 $this->assertEquals('bar', $array['foo']);
74 $this->assertEquals('fuga', $array['hoge']);
76 get_blocklist_add($array, -1, '*.txt');
77 $this->assertEquals(3, count($array));
78 $this->assertEquals('bar', $array['foo']);
79 $this->assertEquals('fuga', $array['hoge']);
80 $this->assertEquals('#^.*\.txt$#i', $array['*.txt']);
84 $array = get_blocklist();
85 $this->assertTrue(isset($array['C']));
86 $this->assertTrue(isset($array['goodhost']));
88 $array = get_blocklist('B-1');
89 $this->assertTrue(isset($array['Google.com']));
91 $array = get_blocklist('goodhost');
92 $this->assertTrue(isset($array['IANA-examples']));