[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/> |
---|
[396] | 5 | * Copyright 2001-2012 Strangecode, LLC |
---|
[468] | 6 | * |
---|
[362] | 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. |
---|
[468] | 13 | * |
---|
[362] | 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. |
---|
[468] | 18 | * |
---|
[362] | 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 | |
---|
[468] | 33 | class AppTest extends PHPUnit_Framework_TestCase { |
---|
| 34 | |
---|
[1] | 35 | var $App; |
---|
| 36 | |
---|
[468] | 37 | static $shared_session; |
---|
[1] | 38 | |
---|
| 39 | function setUp() |
---|
| 40 | { |
---|
| 41 | require dirname(__FILE__) . '/_config.inc.php'; |
---|
| 42 | $this->App =& $app; |
---|
[547] | 43 | $this->App->cli = false; |
---|
[468] | 44 | $_SESSION = AppTest::$shared_session; |
---|
[1] | 45 | } |
---|
| 46 | |
---|
| 47 | function tearDown() |
---|
| 48 | { |
---|
| 49 | unset($this->App); |
---|
[468] | 50 | AppTest::$shared_session = $_SESSION; |
---|
[1] | 51 | } |
---|
| 52 | |
---|
| 53 | function test_getinstance() |
---|
| 54 | { |
---|
[136] | 55 | $thisapp =& App::getInstance(); |
---|
[547] | 56 | $this->assertTrue(serialize($thisapp) === serialize($this->App), 'Objects do not match across instantiations.'); |
---|
[1] | 57 | } |
---|
| 58 | |
---|
| 59 | function test_setParam() |
---|
| 60 | { |
---|
| 61 | $this->App->setParam(array( |
---|
| 62 | 'test_config_value' => 1234 |
---|
| 63 | )); |
---|
[468] | 64 | $this->assertTrue(1234 === $this->App->getParam('test_config_value')); |
---|
[1] | 65 | } |
---|
| 66 | |
---|
| 67 | function test_getParam() |
---|
| 68 | { |
---|
[468] | 69 | //$this->App->setParam('test_config_value2', 'okay'); |
---|
| 70 | $this->App->setParam(array( |
---|
| 71 | 'test_config_value2' => 'okay' |
---|
| 72 | )); |
---|
[1] | 73 | $result = $this->App->getParam('test_config_value2'); |
---|
| 74 | $this->assertEquals('okay', $result); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | function test_start() |
---|
| 78 | { |
---|
| 79 | unset($_SESSION); |
---|
| 80 | $this->App->stop(); |
---|
| 81 | $this->App->start(); |
---|
| 82 | |
---|
| 83 | $this->assertEquals(ini_get('error_reporting'), E_ALL, 'Error reporting not set to E_ALL.'); |
---|
| 84 | $this->assertTrue($this->App->db->dbh && is_resource($this->App->db->dbh), 'DB handler not a resource'); |
---|
| 85 | $this->assertTrue(isset($_SESSION), '$_SESSION is not set.'); |
---|
| 86 | $_SESSION['sess_test_value'] = 'okay'; |
---|
| 87 | $this->assertEquals($_SESSION['sess_test_value'], 'okay', '$_SESSION not storing values.'); |
---|
| 88 | $this->assertTrue(session_name() == 'StrangecodeTestSession', 'Session_name not set correctly.'); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | function test_stop() |
---|
| 92 | { |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | function test_dbquery() |
---|
| 96 | { |
---|
[479] | 97 | $db =& DB::getInstance(); |
---|
[468] | 98 | |
---|
[136] | 99 | $qid = $db->query("SELECT 2 + 2"); |
---|
[1] | 100 | list($result) = mysql_fetch_row($qid); |
---|
| 101 | $this->assertEquals('4', $result); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | function test_raisemsg() |
---|
| 105 | { |
---|
[136] | 106 | $app =& App::getInstance(); |
---|
[1] | 107 | $expected = 'My message'; |
---|
[136] | 108 | $app->raiseMsg($expected, MSG_NOTICE, __FILE__, __LINE__); |
---|
[468] | 109 | $msg = current($_SESSION['_app']['testapp']['messages']); |
---|
[1] | 110 | $this->assertEquals($expected, $msg['message']); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | function test_printraisedmessages() |
---|
| 114 | { |
---|
[541] | 115 | $app =& App::getInstance(); |
---|
[1] | 116 | ob_start(); |
---|
[468] | 117 | $this->test_raisemsg(); //had to add this line for phpunit ver. 3.7 /// |
---|
[136] | 118 | $app->printraisedmessages(); |
---|
[1] | 119 | $result = ob_get_clean(); |
---|
| 120 | $this->assertContains('My message', $result, 'Raised message not found in output.'); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | function test_logmsg() |
---|
| 124 | { |
---|
[136] | 125 | $app =& App::getInstance(); |
---|
[1] | 126 | $file = $this->App->getParam('log_directory') . '/' . $this->App->getParam('log_filename'); |
---|
[136] | 127 | $app->logMsg('Test log message', LOG_DEBUG, __FILE__, __LINE__); |
---|
[1] | 128 | if ($result = file($file)) { |
---|
| 129 | $result = end($result); |
---|
| 130 | } else { |
---|
| 131 | $result = ''; |
---|
| 132 | } |
---|
| 133 | $this->assertContains('Test log message', $result, 'Test message not recorded in log: ' . $file); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | function test_ohref() |
---|
| 137 | { |
---|
[136] | 138 | $app =& App::getInstance(); |
---|
[1] | 139 | $_GET['arg1'] = 'A'; |
---|
[136] | 140 | $result = $app->ohref('/some/url.php', array('arg1'), true); |
---|
[1] | 141 | $this->assertContains(session_name(), $result, 'SSID not found in URL.'); |
---|
| 142 | $this->assertContains('arg1=A', $result, 'Argument not passed through.'); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | function test_printhiddensession() |
---|
| 146 | { |
---|
[136] | 147 | $app =& App::getInstance(); |
---|
[541] | 148 | $app->setParam(array('session_use_trans_sid' => true)); |
---|
[1] | 149 | ob_start(); |
---|
[136] | 150 | $app->printhiddensession(); |
---|
[1] | 151 | $result = ob_get_clean(); |
---|
| 152 | $this->assertContains(session_name(), $result); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | // function test_dieurl() |
---|
| 156 | // { |
---|
[136] | 157 | // $app =& App::getInstance(); |
---|
| 158 | // $app->dieURL('/die/to/this/url.php'); |
---|
[1] | 159 | // } |
---|
[42] | 160 | // |
---|
[1] | 161 | // function test_dieboomerangurl() |
---|
| 162 | // { |
---|
| 163 | // $result = $this->App->dieboomerangurl(PARAM); |
---|
| 164 | // $expected = EXPECTED_VAL; |
---|
| 165 | // $this->assertEquals($expected, $result); |
---|
| 166 | // } |
---|
[42] | 167 | // |
---|
[1] | 168 | // function test_setboomerangurl() |
---|
| 169 | // { |
---|
| 170 | // $result = $this->App->setboomerangurl(PARAM); |
---|
| 171 | // $expected = EXPECTED_VAL; |
---|
| 172 | // $this->assertEquals($expected, $result); |
---|
| 173 | // } |
---|
[42] | 174 | // |
---|
[1] | 175 | // function test_getboomerangurl() |
---|
| 176 | // { |
---|
| 177 | // $result = $this->App->getboomerangurl(PARAM); |
---|
| 178 | // $expected = EXPECTED_VAL; |
---|
| 179 | // $this->assertEquals($expected, $result); |
---|
| 180 | // } |
---|
[42] | 181 | // |
---|
[1] | 182 | // function test_deleteboomerangurl() |
---|
| 183 | // { |
---|
| 184 | // $result = $this->App->deleteboomerangurl(PARAM); |
---|
| 185 | // $expected = EXPECTED_VAL; |
---|
| 186 | // $this->assertEquals($expected, $result); |
---|
| 187 | // } |
---|
[42] | 188 | // |
---|
[1] | 189 | // function test_validboomerangurl() |
---|
| 190 | // { |
---|
| 191 | // $result = $this->App->validboomerangurl(PARAM); |
---|
| 192 | // $expected = EXPECTED_VAL; |
---|
| 193 | // $this->assertEquals($expected, $result); |
---|
| 194 | // } |
---|
[42] | 195 | // |
---|
[1] | 196 | // function test_sslon() |
---|
| 197 | // { |
---|
| 198 | // $result = $this->App->sslon(PARAM); |
---|
| 199 | // $expected = EXPECTED_VAL; |
---|
| 200 | // $this->assertEquals($expected, $result); |
---|
| 201 | // } |
---|
[42] | 202 | // |
---|
[1] | 203 | // function test_ssloff() |
---|
| 204 | // { |
---|
| 205 | // $result = $this->App->ssloff(PARAM); |
---|
| 206 | // $expected = EXPECTED_VAL; |
---|
| 207 | // $this->assertEquals($expected, $result); |
---|
| 208 | // } |
---|
| 209 | |
---|
| 210 | } |
---|
| 211 | // Running the test. |
---|
[468] | 212 | /* |
---|
[1] | 213 | $suite = new PHPUnit_TestSuite('AppTest'); |
---|
| 214 | $result = PHPUnit::run($suite); |
---|
| 215 | echo $result->toString(); |
---|
[468] | 216 | */ |
---|