Our test suite is now done with PHPUnit, although it's rather broken
[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 BSRegister::LoadModule('nonExistentModule');
30 // TODO - use exceptions
31 // $this->assertError();
32 }
33
34 public function testSetGetAppPath()
35 {
36 BSRegister::SetAppPath(getcwd());
37 $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR, BSRegister::GetAppPath());
38 }
39
40 public function testSetGetAppVersion()
41 {
42 BSRegister::SetAppVersion('1.0-test');
43 $this->assertEquals('1.0-test', BSRegister::GetAppVersion());
44 }
45
46 public function testSetGetApplication()
47 {
48 BSRegister::SetApplication('ISSO Tests');
49 $this->assertEquals('ISSO Tests', BSRegister::GetApplication());
50 }
51
52 public function testSetGetWebPath()
53 {
54 $path = DIRECTORY_SEPARATOR . 'Server' . DIRECTORY_SEPARATOR . 'htdocs' . DIRECTORY_SEPARATOR . 'ISSO';
55 BSRegister::SetWebPath($path);
56 $this->assertEquals($path . DIRECTORY_SEPARATOR, BSRegister::GetWebPath());
57 }
58
59 public function testSetGetDebug()
60 {
61 BSRegister::SetDebug(true);
62 $this->assertSame(true, BSRegister::GetDebug());
63 }
64
65 public function testDebugList()
66 {
67 $this->assertEquals('<select><option>Debug Notices (0)</option></select>', BSRegister::GetDebugList());
68
69 BSRegister::Debug('dbg');
70 $this->assertEquals('<select><option>Debug Notices (1)</option><option>--- dbg</option></select>', BSRegister::GetDebugList());
71 }
72
73 public function testRegisterValue()
74 {
75 BSRegister::Register('someKey', 'someValue');
76
77 $registry = BSRegister::GetAll();
78 $this->assertEquals($registry['someKey'], 'someValue');
79 }
80
81 public function testGetAll()
82 {
83 BSRegister::Register('test', 1);
84 $this->assertType('array', BSRegister::GetAll());
85 $this->assertEquals(sizeof(BSRegister::GetAll()), 2);
86 }
87
88 public function testOverWriteRegister()
89 {
90 BSRegister::Register('valueToOverWrite', 1);
91 BSRegister::Register('valueToOverWrite', 2);
92 // TODO - use exceptions
93 // $this->assertError();
94 $this->assertEquals(1, BSRegister::Get('valueToOverWrite'));
95 }
96
97 public function testGet()
98 {
99 BSRegister::Register('testGet', 123);
100 $this->assertEquals(123, BSRegister::Get('testGet'));
101 }
102
103 public function testUnregister()
104 {
105 BSRegister::Register('testUnregister', 1);
106 BSRegister::Unregister('testUnregister');
107 BSRegister::Register('testUnregister', 2);
108 // TODO - use exceptions
109 // $this->assertNoErrors();
110 $this->assertEquals(2, BSRegister::Get('testUnregister'));
111 }
112
113 /* TODO - use exceptions
114 public function testGetNoExist()
115 {
116 BSRegister::Get('doesNotExist');
117 $this->assertError();
118 }
119
120 public function testUnregisterNoExist()
121 {
122 BSRegister::Unregister('keyThatWontExist');
123 $this->assertError();
124 }
125 */
126
127 public function testGetType()
128 {
129 $input = BSRegister::LoadModule('Input');
130 BSRegister::Register('input', $input);
131 $this->assertSame($input, BSRegister::GetType('Input'));
132
133 $this->assertEquals(null, BSRegister::GetType('Date'));
134 }
135
136 /* TODO - use exceptions
137 public function testRequiredModules()
138 {
139 BSRegister::RequiredModules(array('Input'));
140 $this->assertNoErrors();
141
142 BSRegister::RequiredModules(array('Input', 'Db'));
143 $this->assertError();
144
145 BSRegister::RequiredModules(array('Date'));
146 $this->assertError();
147 }
148 */
149 }
150
151 ?>