OSDN Git Service

Abstract にあわせて,Cachemanager_Memcacheの実装に変更
[ethna/ethna.git] / test / Ethna_Util_Test.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_Util_Test.php
5  */
6
7 /**
8  *  Ethna_Utilクラスのテストケース
9  *
10  *  @access public
11  */
12 class Ethna_Util_Test extends Ethna_UnitTestBase
13 {
14     // {{{  testCheckMailAddress
15     function testCheckMailAddress()
16     {
17         $fail_words = array(
18             'hogehuga.net',
19             'untarakantara',
20             'example@example',
21             'example@.com',
22             'example@example@example.com',
23         );
24
25         foreach ($fail_words as $word) {
26             $this->assertFalse(Ethna_Util::checkMailAddress($word));
27         }
28         
29         $util = new Ethna_Util;
30         $result = $util->checkMailAddress('hogefuga.net');
31         $this->assertFalse($result);
32
33         $result = $util->checkMailAddress('hoge@fuga.net');
34         $this->assertTrue($result);
35     }
36     // }}}
37
38     // {{{  testIsAbsolute
39     function testIsAbsolute()
40     {
41         if (ETHNA_OS_WINDOWS) {
42             $absolute_paths = array(
43                 'D:\root',
44                 'C:\home\user\giza',
45             );
46         } else {
47             $absolute_paths = array(
48                 '/root',
49                 '/home/user/giza',
50             );
51         }
52
53         $invalid_params = array(
54             '',
55             false,
56             true,
57             '0x1',
58         );
59
60         foreach ($absolute_paths as $path) {
61             $this->assertTrue(Ethna_Util::isAbsolute($path));
62         }
63         
64         foreach ($invalid_params as $path) {
65             $this->assertFalse(Ethna_Util::isAbsolute($path));
66         }
67     }
68     // }}}
69
70     // {{{  testIsRootDir
71     function testIsRootDir()
72     {
73         $this->assertTrue(DIRECTORY_SEPARATOR);
74
75         $util = new Ethna_Util;
76         if (ETHNA_OS_WINDOWS) {
77             $this->assertTrue($util->isRootDir("C:\\"));
78             $this->assertFalse($util->isRootDir("C:\\Program Files\\hoge\\fuga.txt"));
79             $this->assertFalse($util->isRootDir("C:\\Program Files\\hoge"));
80             $this->assertFalse($util->isRootDir("C:\\hoge\\"));
81             $this->assertFalse($util->isRootDir("C:\\hoge.txt"));
82         } else {
83             $this->assertFalse($util->isRootDir("/home/ethna/test.txt"));
84             $this->assertFalse($util->isRootDir("/home/ethna/"));
85             $this->assertFalse($util->isRootDir("/home/ethna"));
86             $this->assertFalse($util->isRootDir("/test.txt"));
87         }
88     }
89     // }}}
90
91     // {{{  testGetRandom
92     function testGetRandom()
93     {
94         //    いかなる状態であっても
95         //    値が得られなければならない
96         $r = Ethna_Util::getRandom();
97         $this->assertNotNULL($r);
98         $this->assertEqual(64, strlen($r));
99     }
100     // }}}
101
102     // {{{ testGetEra
103     function testGetEra()
104     {
105         unset($GLOBALS['_Ethna_controller']);
106         $tmp_ctl =& new Ethna_Controller();
107         
108         //  昭和63年
109         $last_showa_t = mktime(0,0,0,12,31,1988);
110         $r = Ethna_Util::getEra($last_showa_t);
111         $this->assertEqual('昭和', $r[0]);
112         $this->assertEqual(63, $r[1]);
113
114         //  平成元年
115         $first_heisei_t = mktime(0,0,0,1,1,1989);
116         $r = Ethna_Util::getEra($first_heisei_t);
117         $this->assertEqual('平成', $r[0]);
118         $this->assertEqual(1, $r[1]);
119     }
120     // }}}
121 }
122
123 ?>