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