- Switch to using Exception in Xml.php, Register.php, and Input.php
[isso.git] / docs / UnitTest / RegisterTest.php
1 <?php
2
3 require_once 'PHPUnit/Framework.php';
4
5
6 /**
7 * Register Test Suite
8 *
9 * @author Blue Static
10 * @copyright Copyright ©2002 - [#]year[#], Blue Static
11 * @version $Revision$
12 * @package ISSO Tests
13 *
14 */
15 class RegisterTest extends PHPUnit_Framework_TestCase
16 {
17 public function setUp()
18 {
19 require_once 'ISSO/Register.php';
20 }
21
22 public function testLoadModule()
23 {
24 $this->assertTrue(BSRegister::LoadModule('Input') instanceof BSInput);
25 }
26
27 public function testLoadBadModule()
28 {
29 try
30 {
31 BSRegister::LoadModule('nonExistentModule');
32 $this->fail('exception expected');
33 }
34 catch (Exception $e)
35 {}
36 }
37
38 public function testSetGetAppPath()
39 {
40 BSRegister::SetAppPath(getcwd());
41 $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR, BSRegister::GetAppPath());
42 }
43
44 public function testSetGetAppVersion()
45 {
46 BSRegister::SetAppVersion('1.0-test');
47 $this->assertEquals('1.0-test', BSRegister::GetAppVersion());
48 }
49
50 public function testSetGetApplication()
51 {
52 BSRegister::SetApplication('ISSO Tests');
53 $this->assertEquals('ISSO Tests', BSRegister::GetApplication());
54 }
55
56 public function testSetGetWebPath()
57 {
58 $path = DIRECTORY_SEPARATOR . 'Server' . DIRECTORY_SEPARATOR . 'htdocs' . DIRECTORY_SEPARATOR . 'ISSO';
59 BSRegister::SetWebPath($path);
60 $this->assertEquals($path . DIRECTORY_SEPARATOR, BSRegister::GetWebPath());
61 }
62
63 public function testSetGetDebug()
64 {
65 BSRegister::SetDebug(true);
66 $this->assertSame(true, BSRegister::GetDebug());
67 }
68
69 public function testDebugList()
70 {
71 $this->assertEquals('<select><option>Debug Notices (0)</option></select>', BSRegister::GetDebugList());
72
73 BSRegister::Debug('dbg');
74 $this->assertEquals('<select><option>Debug Notices (1)</option><option>--- dbg</option></select>', BSRegister::GetDebugList());
75 }
76
77 public function testRegisterValue()
78 {
79 BSRegister::Register('someKey', 'someValue');
80
81 $registry = BSRegister::GetAll();
82 $this->assertEquals($registry['someKey'], 'someValue');
83 }
84
85 public function testGetAll()
86 {
87 BSRegister::Register('test', 1);
88 $this->assertType('array', BSRegister::GetAll());
89 $this->assertEquals(sizeof(BSRegister::GetAll()), 2);
90 }
91
92 public function testOverWriteRegister()
93 {
94 try
95 {
96 BSRegister::Register('valueToOverWrite', 1);
97 BSRegister::Register('valueToOverWrite', 2);
98 $this->fail('exception expected');
99 }
100 catch (Exception $e)
101 {
102 $this->assertEquals(1, BSRegister::Get('valueToOverWrite'));
103 }
104 }
105
106 public function testGet()
107 {
108 BSRegister::Register('testGet', 123);
109 $this->assertEquals(123, BSRegister::Get('testGet'));
110 }
111
112 public function testUnregister()
113 {
114 try
115 {
116 BSRegister::Register('testUnregister', 1);
117 BSRegister::Unregister('testUnregister');
118 BSRegister::Register('testUnregister', 2);
119 $this->fail('exception expected');
120 }
121 catch (Exception $e)
122 {
123 $this->assertEquals(2, BSRegister::Get('testUnregister'));
124 }
125 }
126
127 public function testGetNoExist()
128 {
129 try
130 {
131 BSRegister::Get('doesNotExist');
132 $this->fail('exception expected');
133 }
134 catch (Exception $e)
135 {}
136 }
137
138 public function testUnregisterNoExist()
139 {
140 try
141 {
142 BSRegister::Unregister('keyThatWontExist');
143 $this->fail('exception expected');
144 }
145 catch (Exception $e)
146 {}
147 }
148
149 public function testGetType()
150 {
151 $input = BSRegister::LoadModule('Input');
152 BSRegister::Register('input', $input);
153 $this->assertSame($input, BSRegister::GetType('Input'));
154
155 $this->assertEquals(null, BSRegister::GetType('Date'));
156 }
157
158 public function testRequiredModules()
159 {
160 try
161 {
162 BSRegister::RequiredModules(array('Input'));
163 }
164 catch (Exception $e)
165 {
166 $this->fail('unexpcted exception');
167 }
168
169 try
170 {
171 BSRegister::RequiredModules(array('Input', 'Db'));
172 $this->fail('exception expected');
173 }
174 catch (Exception $e)
175 {}
176
177 try
178 {
179 BSRegister::RequiredModules(array('Date'));
180 $this->fail('exception expected');
181 }
182 catch (Exception $e)
183 {}
184 }
185 }
186
187 ?>