Changing the registry part of BSRegister to be a new inner class called BSVariableReg...
[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::Registry()->someKey = 'someValue';
80
81 $registry = BSRegister::Registry();
82 $this->assertEquals($registry->someKey, 'someValue');
83 }
84
85 public function testGetAll()
86 {
87 BSRegister::Registry()->test = 1;
88 $this->assertType('array', BSRegister::Registry()->allObjects());
89 $this->assertSame(sizeof(BSRegister::Registry()->allObjects()), 2);
90 }
91
92 public function testOverWriteRegister()
93 {
94 BSRegister::Registry()->valueToOverWrite = 1;
95 BSRegister::Registry()->valueToOverWrite = 2;
96 $this->assertEquals(2, BSRegister::Registry()->valueToOverWrite);
97 }
98
99 public function testGet()
100 {
101 BSRegister::Registry()->testGet = 123;
102 $this->assertEquals(123, BSRegister::Registry()->testGet);
103 }
104
105 public function testUnregister()
106 {
107 BSRegister::Registry()->testUnregister = 1;
108 unset(BSRegister::Registry()->testUnregister);
109 $this->assertObjectNotHasAttribute('testUnregister', BSRegister::Registry());
110 }
111
112 public function testGetNoExist()
113 {
114 try
115 {
116 BSRegister::Registry()->doesNotExist;
117 $this->fail('exception expected');
118 }
119 catch (Exception $e)
120 {}
121 }
122
123 public function testUnregisterNoExist()
124 {
125 try
126 {
127 unset(BSRegister::Registry()->keyThatWontExist);
128 $this->fail('exception expected');
129 }
130 catch (Exception $e)
131 {}
132 }
133
134 public function testGetType()
135 {
136 $input = BSRegister::LoadModule('Input');
137 BSRegister::Registry()->input = $input;
138 $this->assertSame($input, BSRegister::Registry()->getType('Input'));
139
140 $this->assertEquals(null, BSRegister::Registry()->getType('Date'));
141 }
142
143 public function testRequiredModules()
144 {
145 try
146 {
147 BSRegister::RequiredModules(array('Input'));
148 }
149 catch (Exception $e)
150 {
151 $this->fail('unexpcted exception');
152 }
153
154 try
155 {
156 BSRegister::RequiredModules(array('Input', 'Db'));
157 $this->fail('exception expected');
158 }
159 catch (Exception $e)
160 {}
161
162 try
163 {
164 BSRegister::RequiredModules(array('Date'));
165 $this->fail('exception expected');
166 }
167 catch (Exception $e)
168 {}
169 }
170 }
171
172 ?>