[1] | 1 | <?php |
---|
| 2 | /** |
---|
[362] | 3 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 4 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[376] | 5 | * Copyright 2001-2010 Strangecode, LLC |
---|
[362] | 6 | * |
---|
| 7 | * This file is part of The Strangecode Codebase. |
---|
[42] | 8 | * |
---|
[362] | 9 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 11 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 12 | * any later version. |
---|
| 13 | * |
---|
| 14 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 17 | * details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License along with |
---|
| 20 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * PHPUnit test case for codebase/lib/App.inc.php |
---|
| 25 | * |
---|
[42] | 26 | * The method skeletons below need to be filled in with |
---|
| 27 | * real data so that the tests will run correctly. Replace |
---|
| 28 | * all EXPECTED_VAL and PARAM strings with real data. |
---|
| 29 | * |
---|
[1] | 30 | * Created with PHPUnit_Skeleton on 2005-08-09 |
---|
| 31 | */ |
---|
| 32 | require_once 'PHPUnit.php'; |
---|
| 33 | class AppTest extends PHPUnit_TestCase { |
---|
| 34 | |
---|
| 35 | var $App; |
---|
| 36 | |
---|
| 37 | function AppTest($name) |
---|
| 38 | { |
---|
| 39 | $this->PHPUnit_TestCase($name); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | function setUp() |
---|
| 43 | { |
---|
| 44 | require dirname(__FILE__) . '/_config.inc.php'; |
---|
| 45 | $this->App =& $app; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | function tearDown() |
---|
| 49 | { |
---|
| 50 | unset($this->App); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | function test_getinstance() |
---|
| 54 | { |
---|
[136] | 55 | $thisapp =& App::getInstance(); |
---|
[1] | 56 | $this->assertTrue(serialize($thisapp) == serialize($this->App), 'Objects do not match across instantiations.'); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | function test_setParam() |
---|
| 60 | { |
---|
| 61 | $this->App->setParam(array( |
---|
| 62 | 'test_config_value' => 1234 |
---|
| 63 | )); |
---|
| 64 | $this->assertTrue(1234 === $this->App->_params['test_config_value']); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | function test_getParam() |
---|
| 68 | { |
---|
| 69 | $this->App->_params['test_config_value2'] = 'okay'; |
---|
| 70 | $result = $this->App->getParam('test_config_value2'); |
---|
| 71 | $this->assertEquals('okay', $result); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | function test_start() |
---|
| 75 | { |
---|
| 76 | unset($_SESSION); |
---|
| 77 | $this->App->stop(); |
---|
| 78 | $this->App->start(); |
---|
| 79 | |
---|
| 80 | $this->assertEquals(ini_get('error_reporting'), E_ALL, 'Error reporting not set to E_ALL.'); |
---|
| 81 | $this->assertTrue($this->App->db->dbh && is_resource($this->App->db->dbh), 'DB handler not a resource'); |
---|
| 82 | $this->assertTrue(isset($_SESSION), '$_SESSION is not set.'); |
---|
| 83 | $_SESSION['sess_test_value'] = 'okay'; |
---|
| 84 | $this->assertEquals($_SESSION['sess_test_value'], 'okay', '$_SESSION not storing values.'); |
---|
| 85 | $this->assertTrue(session_name() == 'StrangecodeTestSession', 'Session_name not set correctly.'); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | function test_stop() |
---|
| 89 | { |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | function test_dbquery() |
---|
| 93 | { |
---|
[136] | 94 | $db =& DB::getInstance(); |
---|
| 95 | |
---|
| 96 | $qid = $db->query("SELECT 2 + 2"); |
---|
[1] | 97 | list($result) = mysql_fetch_row($qid); |
---|
| 98 | $this->assertEquals('4', $result); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | function test_raisemsg() |
---|
| 102 | { |
---|
[136] | 103 | $app =& App::getInstance(); |
---|
[1] | 104 | $expected = 'My message'; |
---|
[136] | 105 | $app->raiseMsg($expected, MSG_NOTICE, __FILE__, __LINE__); |
---|
[154] | 106 | $msg = current($_SESSION['_app'][$this->App->_ns]['messages']); |
---|
[1] | 107 | $this->assertEquals($expected, $msg['message']); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | function test_printraisedmessages() |
---|
| 111 | { |
---|
| 112 | ob_start(); |
---|
[136] | 113 | $app =& App::getInstance(); |
---|
| 114 | $app->printraisedmessages(); |
---|
[1] | 115 | $result = ob_get_clean(); |
---|
| 116 | $this->assertContains('My message', $result, 'Raised message not found in output.'); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | function test_logmsg() |
---|
| 120 | { |
---|
[136] | 121 | $app =& App::getInstance(); |
---|
[1] | 122 | $file = $this->App->getParam('log_directory') . '/' . $this->App->getParam('log_filename'); |
---|
[136] | 123 | $app->logMsg('Test log message', LOG_DEBUG, __FILE__, __LINE__); |
---|
[1] | 124 | if ($result = file($file)) { |
---|
| 125 | $result = end($result); |
---|
| 126 | } else { |
---|
| 127 | $result = ''; |
---|
| 128 | } |
---|
| 129 | $this->assertContains('Test log message', $result, 'Test message not recorded in log: ' . $file); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | function test_ohref() |
---|
| 133 | { |
---|
[136] | 134 | $app =& App::getInstance(); |
---|
[1] | 135 | $_GET['arg1'] = 'A'; |
---|
[136] | 136 | $result = $app->ohref('/some/url.php', array('arg1'), true); |
---|
[1] | 137 | $this->assertContains(session_name(), $result, 'SSID not found in URL.'); |
---|
| 138 | $this->assertContains('arg1=A', $result, 'Argument not passed through.'); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | function test_printhiddensession() |
---|
| 142 | { |
---|
[136] | 143 | $app =& App::getInstance(); |
---|
[1] | 144 | ob_start(); |
---|
[136] | 145 | $app->printhiddensession(); |
---|
[1] | 146 | $result = ob_get_clean(); |
---|
| 147 | $this->assertContains(session_name(), $result); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | // function test_dieurl() |
---|
| 151 | // { |
---|
[136] | 152 | // $app =& App::getInstance(); |
---|
| 153 | // $app->dieURL('/die/to/this/url.php'); |
---|
[1] | 154 | // } |
---|
[42] | 155 | // |
---|
[1] | 156 | // function test_dieboomerangurl() |
---|
| 157 | // { |
---|
| 158 | // $result = $this->App->dieboomerangurl(PARAM); |
---|
| 159 | // $expected = EXPECTED_VAL; |
---|
| 160 | // $this->assertEquals($expected, $result); |
---|
| 161 | // } |
---|
[42] | 162 | // |
---|
[1] | 163 | // function test_setboomerangurl() |
---|
| 164 | // { |
---|
| 165 | // $result = $this->App->setboomerangurl(PARAM); |
---|
| 166 | // $expected = EXPECTED_VAL; |
---|
| 167 | // $this->assertEquals($expected, $result); |
---|
| 168 | // } |
---|
[42] | 169 | // |
---|
[1] | 170 | // function test_getboomerangurl() |
---|
| 171 | // { |
---|
| 172 | // $result = $this->App->getboomerangurl(PARAM); |
---|
| 173 | // $expected = EXPECTED_VAL; |
---|
| 174 | // $this->assertEquals($expected, $result); |
---|
| 175 | // } |
---|
[42] | 176 | // |
---|
[1] | 177 | // function test_deleteboomerangurl() |
---|
| 178 | // { |
---|
| 179 | // $result = $this->App->deleteboomerangurl(PARAM); |
---|
| 180 | // $expected = EXPECTED_VAL; |
---|
| 181 | // $this->assertEquals($expected, $result); |
---|
| 182 | // } |
---|
[42] | 183 | // |
---|
[1] | 184 | // function test_validboomerangurl() |
---|
| 185 | // { |
---|
| 186 | // $result = $this->App->validboomerangurl(PARAM); |
---|
| 187 | // $expected = EXPECTED_VAL; |
---|
| 188 | // $this->assertEquals($expected, $result); |
---|
| 189 | // } |
---|
[42] | 190 | // |
---|
[1] | 191 | // function test_sslon() |
---|
| 192 | // { |
---|
| 193 | // $result = $this->App->sslon(PARAM); |
---|
| 194 | // $expected = EXPECTED_VAL; |
---|
| 195 | // $this->assertEquals($expected, $result); |
---|
| 196 | // } |
---|
[42] | 197 | // |
---|
[1] | 198 | // function test_ssloff() |
---|
| 199 | // { |
---|
| 200 | // $result = $this->App->ssloff(PARAM); |
---|
| 201 | // $expected = EXPECTED_VAL; |
---|
| 202 | // $this->assertEquals($expected, $result); |
---|
| 203 | // } |
---|
| 204 | |
---|
| 205 | } |
---|
| 206 | // Running the test. |
---|
| 207 | $suite = new PHPUnit_TestSuite('AppTest'); |
---|
| 208 | $result = PHPUnit::run($suite); |
---|
| 209 | echo $result->toString(); |
---|
| 210 | ?> |
---|