OSDN Git Service

Merge branch 'feature/rename-files' into feature/php5.3-compatible2
[ethna/ethna.git] / test / Util_Test.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  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         $result = Ethna_Util::checkMailAddress('hogefuga.net');
30         $this->assertFalse($result);
31
32         $result = Ethna_Util::checkMailAddress('hoge@fuga.net');
33         $this->assertTrue($result);
34     }
35     // }}}
36
37     // {{{  testIsAbsolute
38     function testIsAbsolute()
39     {
40         if (ETHNA_OS_WINDOWS) {
41             $absolute_paths = array(
42                 'D:\root',
43                 'C:\home\user\giza',
44             );
45         } else {
46             $absolute_paths = array(
47                 '/root',
48                 '/home/user/giza',
49             );
50         }
51
52         $invalid_params = array(
53             '',
54             false,
55             true,
56             '0x1',
57         );
58
59         foreach ($absolute_paths as $path) {
60             $this->assertTrue(Ethna_Util::isAbsolute($path));
61         }
62         
63         foreach ($invalid_params as $path) {
64             $this->assertFalse(Ethna_Util::isAbsolute($path));
65         }
66     }
67     // }}}
68
69     // {{{  testIsRootDir
70     function testIsRootDir()
71     {
72         $this->assertTrue(DIRECTORY_SEPARATOR);
73
74         if (ETHNA_OS_WINDOWS) {
75             $this->assertTrue (Ethna_Util::isRootDir("C:\\"));
76             $this->assertFalse(Ethna_Util::isRootDir("C:\\Program Files\\hoge\\fuga.txt"));
77             $this->assertFalse(Ethna_Util::isRootDir("C:\\Program Files\\hoge"));
78             $this->assertFalse(Ethna_Util::isRootDir("C:\\hoge\\"));
79             $this->assertFalse(Ethna_Util::isRootDir("C:\\hoge.txt"));
80         } else {
81             $this->assertFalse(Ethna_Util::isRootDir("/home/ethna/test.txt"));
82             $this->assertFalse(Ethna_Util::isRootDir("/home/ethna/"));
83             $this->assertFalse(Ethna_Util::isRootDir("/home/ethna"));
84             $this->assertFalse(Ethna_Util::isRootDir("/test.txt"));
85         }
86     }
87     // }}}
88
89     // {{{  testGetRandom
90     function testGetRandom()
91     {
92         //    いかなる状態であっても
93         //    値が得られなければならない
94         $r = Ethna_Util::getRandom();
95         $this->assertNotNULL($r);
96         $this->assertEqual(64, strlen($r));
97     }
98     // }}}
99
100     // {{{ testGetEra
101     function testGetEra()
102     {
103         unset($GLOBALS['_Ethna_controller']);
104         $tmp_ctl = new Ethna_Controller();
105         
106         //  昭和63年
107         $last_showa_t = mktime(0,0,0,12,31,1988);
108         $r = Ethna_Util::getEra($last_showa_t);
109         $this->assertEqual('昭和', $r[0]);
110         $this->assertEqual(63, $r[1]);
111
112         //  平成元年
113         $first_heisei_t = mktime(0,0,0,1,1,1989);
114         $r = Ethna_Util::getEra($first_heisei_t);
115         $this->assertEqual('平成', $r[0]);
116         $this->assertEqual(1, $r[1]);
117     }
118     // }}}
119 }
120