1 | <?php |
---|
2 | /** |
---|
3 | * PHPUnit test case for App |
---|
4 | * |
---|
5 | * The method skeletons below need to be filled in with |
---|
6 | * real data so that the tests will run correctly. Replace |
---|
7 | * all EXPECTED_VAL and PARAM strings with real data. |
---|
8 | * |
---|
9 | * Created with PHPUnit_Skeleton on 2005-08-09 |
---|
10 | */ |
---|
11 | require_once 'PHPUnit.php'; |
---|
12 | class AppTest extends PHPUnit_TestCase { |
---|
13 | |
---|
14 | var $App; |
---|
15 | |
---|
16 | function AppTest($name) |
---|
17 | { |
---|
18 | $this->PHPUnit_TestCase($name); |
---|
19 | } |
---|
20 | |
---|
21 | function setUp() |
---|
22 | { |
---|
23 | require dirname(__FILE__) . '/_config.inc.php'; |
---|
24 | $this->App =& $app; |
---|
25 | } |
---|
26 | |
---|
27 | function tearDown() |
---|
28 | { |
---|
29 | unset($this->App); |
---|
30 | } |
---|
31 | |
---|
32 | function test_getinstance() |
---|
33 | { |
---|
34 | $thisapp =& App::getinstance(); |
---|
35 | $this->assertTrue(serialize($thisapp) == serialize($this->App), 'Objects do not match across instantiations.'); |
---|
36 | } |
---|
37 | |
---|
38 | function test_setParam() |
---|
39 | { |
---|
40 | $this->App->setParam(array( |
---|
41 | 'test_config_value' => 1234 |
---|
42 | )); |
---|
43 | $this->assertTrue(1234 === $this->App->_params['test_config_value']); |
---|
44 | } |
---|
45 | |
---|
46 | function test_getParam() |
---|
47 | { |
---|
48 | $this->App->_params['test_config_value2'] = 'okay'; |
---|
49 | $result = $this->App->getParam('test_config_value2'); |
---|
50 | $this->assertEquals('okay', $result); |
---|
51 | } |
---|
52 | |
---|
53 | function test_start() |
---|
54 | { |
---|
55 | unset($_SESSION); |
---|
56 | $this->App->stop(); |
---|
57 | $this->App->start(); |
---|
58 | |
---|
59 | $this->assertEquals(ini_get('error_reporting'), E_ALL, 'Error reporting not set to E_ALL.'); |
---|
60 | $this->assertTrue($this->App->db->dbh && is_resource($this->App->db->dbh), 'DB handler not a resource'); |
---|
61 | $this->assertTrue(isset($_SESSION), '$_SESSION is not set.'); |
---|
62 | $_SESSION['sess_test_value'] = 'okay'; |
---|
63 | $this->assertEquals($_SESSION['sess_test_value'], 'okay', '$_SESSION not storing values.'); |
---|
64 | $this->assertTrue(session_name() == 'StrangecodeTestSession', 'Session_name not set correctly.'); |
---|
65 | } |
---|
66 | |
---|
67 | function test_stop() |
---|
68 | { |
---|
69 | } |
---|
70 | |
---|
71 | function test_dbquery() |
---|
72 | { |
---|
73 | $db =& DB::getInstance(); |
---|
74 | |
---|
75 | $qid = $db->query("SELECT 2 + 2"); |
---|
76 | list($result) = mysql_fetch_row($qid); |
---|
77 | $this->assertEquals('4', $result); |
---|
78 | } |
---|
79 | |
---|
80 | function test_raisemsg() |
---|
81 | { |
---|
82 | $expected = 'My message'; |
---|
83 | $app->raiseMsg($expected, MSG_NOTICE, __FILE__, __LINE__); |
---|
84 | $msg = current($_SESSION[$this->App->app]['messages']); |
---|
85 | $this->assertEquals($expected, $msg['message']); |
---|
86 | } |
---|
87 | |
---|
88 | function test_printraisedmessages() |
---|
89 | { |
---|
90 | ob_start(); |
---|
91 | $app->printraisedmessages(); |
---|
92 | $result = ob_get_clean(); |
---|
93 | $this->assertContains('My message', $result, 'Raised message not found in output.'); |
---|
94 | } |
---|
95 | |
---|
96 | function test_logmsg() |
---|
97 | { |
---|
98 | $file = $this->App->getParam('log_directory') . '/' . $this->App->getParam('log_filename'); |
---|
99 | $app->logMsg('Test log message', LOG_DEBUG, __FILE__, __LINE__); |
---|
100 | if ($result = file($file)) { |
---|
101 | $result = end($result); |
---|
102 | } else { |
---|
103 | $result = ''; |
---|
104 | } |
---|
105 | $this->assertContains('Test log message', $result, 'Test message not recorded in log: ' . $file); |
---|
106 | } |
---|
107 | |
---|
108 | function test_ohref() |
---|
109 | { |
---|
110 | $_GET['arg1'] = 'A'; |
---|
111 | $result = $app->ohref('/some/url.php', array('arg1'), true); |
---|
112 | $this->assertContains(session_name(), $result, 'SSID not found in URL.'); |
---|
113 | $this->assertContains('arg1=A', $result, 'Argument not passed through.'); |
---|
114 | } |
---|
115 | |
---|
116 | function test_printhiddensession() |
---|
117 | { |
---|
118 | ob_start(); |
---|
119 | $app->printhiddensession(); |
---|
120 | $result = ob_get_clean(); |
---|
121 | $this->assertContains(session_name(), $result); |
---|
122 | } |
---|
123 | |
---|
124 | // function test_dieurl() |
---|
125 | // { |
---|
126 | // $app->dieURL('/die/to/this/url.php'); |
---|
127 | // } |
---|
128 | // |
---|
129 | // function test_dieboomerangurl() |
---|
130 | // { |
---|
131 | // $result = $this->App->dieboomerangurl(PARAM); |
---|
132 | // $expected = EXPECTED_VAL; |
---|
133 | // $this->assertEquals($expected, $result); |
---|
134 | // } |
---|
135 | // |
---|
136 | // function test_setboomerangurl() |
---|
137 | // { |
---|
138 | // $result = $this->App->setboomerangurl(PARAM); |
---|
139 | // $expected = EXPECTED_VAL; |
---|
140 | // $this->assertEquals($expected, $result); |
---|
141 | // } |
---|
142 | // |
---|
143 | // function test_getboomerangurl() |
---|
144 | // { |
---|
145 | // $result = $this->App->getboomerangurl(PARAM); |
---|
146 | // $expected = EXPECTED_VAL; |
---|
147 | // $this->assertEquals($expected, $result); |
---|
148 | // } |
---|
149 | // |
---|
150 | // function test_deleteboomerangurl() |
---|
151 | // { |
---|
152 | // $result = $this->App->deleteboomerangurl(PARAM); |
---|
153 | // $expected = EXPECTED_VAL; |
---|
154 | // $this->assertEquals($expected, $result); |
---|
155 | // } |
---|
156 | // |
---|
157 | // function test_validboomerangurl() |
---|
158 | // { |
---|
159 | // $result = $this->App->validboomerangurl(PARAM); |
---|
160 | // $expected = EXPECTED_VAL; |
---|
161 | // $this->assertEquals($expected, $result); |
---|
162 | // } |
---|
163 | // |
---|
164 | // function test_sslon() |
---|
165 | // { |
---|
166 | // $result = $this->App->sslon(PARAM); |
---|
167 | // $expected = EXPECTED_VAL; |
---|
168 | // $this->assertEquals($expected, $result); |
---|
169 | // } |
---|
170 | // |
---|
171 | // function test_ssloff() |
---|
172 | // { |
---|
173 | // $result = $this->App->ssloff(PARAM); |
---|
174 | // $expected = EXPECTED_VAL; |
---|
175 | // $this->assertEquals($expected, $result); |
---|
176 | // } |
---|
177 | |
---|
178 | } |
---|
179 | // Running the test. |
---|
180 | $suite = new PHPUnit_TestSuite('AppTest'); |
---|
181 | $result = PHPUnit::run($suite); |
---|
182 | echo $result->toString(); |
---|
183 | ?> |
---|