OSDN Git Service

Merge branch 'release/2.6.0beta2'
[ethna/ethna.git] / test / Class_Test.php
1 <?php
2 /**
3  *  Class_Test.php
4  *
5  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
6  *  @version    $Id$
7  */
8
9 class Dummy_Ethna_Error extends Ethna_Error
10 {
11     //  nothing defined.
12 }
13
14 function dummy_error_callback_global(&$error)
15 {
16     $GLOBALS['_dummy_error_callback_global'] = $error->getMessage();
17 }
18
19 //{{{    Ethna_Test
20 /**
21  *  Test Case For Ethna class
22  *
23  *  @access public
24  */
25 class Ethna_Class_Test extends Ethna_UnitTestBase
26 {
27     var $dummy_error_value_class;
28
29     function setUp()
30     {
31         $GLOBALS['_dummy_error_callback_global'] = NULL;
32         $this->dummy_error_value_class = NULL;
33         Ethna::clearErrorCallback();
34     }
35
36     function dummy_error_callback_obj(&$error)
37     {
38         $this->dummy_error_value_class = $error->getMessage();
39     }
40
41     //{{{  isError test
42     function test_isError()
43     {
44         $error = new Ethna_Error();
45         $this->assertTrue(Ethna::isError($error));
46
47         $error = 'this is not object, but string.';
48         $this->assertFalse(Ethna::isError($error));
49
50         $error = new Dummy_Ethna_Error('Error Message', E_CACHE_GENERAL,
51                                  ETHNA_ERROR_DUMMY, E_USER_ERROR,
52                                  NULL, 'Ethna_Error'
53                  );
54         $this->assertFalse(Ethna::isError($error, E_FORM_REQUIRED));
55         $this->assertTrue(Ethna::isError($error, E_CACHE_GENERAL));
56
57         $error = new stdClass();
58         $this->assertFalse(Ethna::isError($error));
59
60         $error = NULL;
61         $this->assertFalse(Ethna::isError($error));
62
63         //   Ethna はPEARに依存しないので、
64         //   PEAR_Error を渡してもfalse が返らなければならない
65         $fp = @fopen('PEAR.php', 'r', true);
66         if ($fp !== false) {
67             require_once 'PEAR.php';
68             $error = new PEAR_Error();
69             $this->assertFalse(Ethna::isError($error));
70         }
71         fclose($fp);
72     }
73     // }}}
74
75     //{{{  raiseError test
76     function test_raiseError()
77     {
78         $error = Ethna::raiseError('Error!!!!!');
79         $this->assertEqual('Error!!!!!', $error->getMessage());
80         $this->assertEqual(E_USER_ERROR, $error->getLevel());
81         $this->assertEqual(E_GENERAL, $error->getCode());     
82
83         $error = Ethna::raiseError('Error', E_CACHE_GENERAL);
84         $this->assertEqual(E_CACHE_GENERAL, $error->getCode());     
85     }
86     // }}}
87
88     //{{{  raiseWarning test
89     function test_raiseWarning()
90     {
91         $error = Ethna::raiseWarning('Error!!!!!');
92         $this->assertEqual('Error!!!!!', $error->getMessage());
93         $this->assertEqual(E_USER_WARNING, $error->getLevel());
94         $this->assertEqual(E_GENERAL, $error->getCode());     
95
96         $error = Ethna::raiseWarning('Error!!!!!', E_CACHE_GENERAL);
97         $this->assertEqual(E_CACHE_GENERAL, $error->getCode());     
98     }
99     // }}}
100
101     //{{{  raiseNotice test
102     function test_raiseNotice()
103     {
104         $error = Ethna::raiseNotice('Error!!!!!');
105         $this->assertEqual('Error!!!!!', $error->getMessage());
106         $this->assertEqual(E_USER_NOTICE, $error->getLevel());
107         $this->assertEqual(E_GENERAL, $error->getCode());     
108
109         $error = Ethna::raiseNotice('Error!!!!!', E_CACHE_GENERAL);
110         $this->assertEqual(E_CACHE_GENERAL, $error->getCode());     
111     }
112     // }}}
113
114     //{{{  callback test
115     function test_error_callback_obj()
116     {
117         $this->assertNULL($GLOBALS['_dummy_error_callback_global']);
118         $this->assertNULL($this->dummy_error_value_class);
119
120         //   array の場合は クラス名|オブジェクト + method
121         Ethna::setErrorCallback(array(&$this, 'dummy_error_callback_obj'));
122         Ethna::raiseError('dummy_error_obj!!!');
123         $this->assertEqual('dummy_error_obj!!!', $this->dummy_error_value_class);
124         $this->assertNULL($GLOBALS['_dummy_error_callback_global']);
125     }
126
127     function test_error_callback_global()
128     {
129         $this->assertNULL($GLOBALS['_dummy_error_callback_global']);
130         $this->assertNULL($this->dummy_error_value_class);
131
132         //   string の場合はグローバル関数 
133         Ethna::setErrorCallback('dummy_error_callback_global');
134         Ethna::raiseError('dummy_error_global!!!');
135         $this->assertEqual('dummy_error_global!!!', $GLOBALS['_dummy_error_callback_global']);
136     }
137
138     function test_error_callback_mixed()
139     {
140         //   string の場合はグローバル関数 
141         Ethna::setErrorCallback('dummy_error_callback_global');
142         Ethna::setErrorCallback(array(&$this, 'dummy_error_callback_obj'));
143         Ethna::raiseError('dummy_error_global!!!');
144         $this->assertEqual('dummy_error_global!!!', $GLOBALS['_dummy_error_callback_global']);
145         $this->assertEqual('dummy_error_global!!!', $this->dummy_error_value_class);
146     }
147     // }}}
148 }
149 // }}}
150