[1] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * PHPUnit test case for App |
---|
[42] | 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 | * |
---|
[1] | 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 | { |
---|
[136] | 34 | $thisapp =& App::getInstance(); |
---|
[1] | 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 | { |
---|
[136] | 73 | $db =& DB::getInstance(); |
---|
| 74 | |
---|
| 75 | $qid = $db->query("SELECT 2 + 2"); |
---|
[1] | 76 | list($result) = mysql_fetch_row($qid); |
---|
| 77 | $this->assertEquals('4', $result); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | function test_raisemsg() |
---|
| 81 | { |
---|
[136] | 82 | $app =& App::getInstance(); |
---|
[1] | 83 | $expected = 'My message'; |
---|
[136] | 84 | $app->raiseMsg($expected, MSG_NOTICE, __FILE__, __LINE__); |
---|
[154] | 85 | $msg = current($_SESSION['_app'][$this->App->_ns]['messages']); |
---|
[1] | 86 | $this->assertEquals($expected, $msg['message']); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | function test_printraisedmessages() |
---|
| 90 | { |
---|
| 91 | ob_start(); |
---|
[136] | 92 | $app =& App::getInstance(); |
---|
| 93 | $app->printraisedmessages(); |
---|
[1] | 94 | $result = ob_get_clean(); |
---|
| 95 | $this->assertContains('My message', $result, 'Raised message not found in output.'); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | function test_logmsg() |
---|
| 99 | { |
---|
[136] | 100 | $app =& App::getInstance(); |
---|
[1] | 101 | $file = $this->App->getParam('log_directory') . '/' . $this->App->getParam('log_filename'); |
---|
[136] | 102 | $app->logMsg('Test log message', LOG_DEBUG, __FILE__, __LINE__); |
---|
[1] | 103 | if ($result = file($file)) { |
---|
| 104 | $result = end($result); |
---|
| 105 | } else { |
---|
| 106 | $result = ''; |
---|
| 107 | } |
---|
| 108 | $this->assertContains('Test log message', $result, 'Test message not recorded in log: ' . $file); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | function test_ohref() |
---|
| 112 | { |
---|
[136] | 113 | $app =& App::getInstance(); |
---|
[1] | 114 | $_GET['arg1'] = 'A'; |
---|
[136] | 115 | $result = $app->ohref('/some/url.php', array('arg1'), true); |
---|
[1] | 116 | $this->assertContains(session_name(), $result, 'SSID not found in URL.'); |
---|
| 117 | $this->assertContains('arg1=A', $result, 'Argument not passed through.'); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | function test_printhiddensession() |
---|
| 121 | { |
---|
[136] | 122 | $app =& App::getInstance(); |
---|
[1] | 123 | ob_start(); |
---|
[136] | 124 | $app->printhiddensession(); |
---|
[1] | 125 | $result = ob_get_clean(); |
---|
| 126 | $this->assertContains(session_name(), $result); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | // function test_dieurl() |
---|
| 130 | // { |
---|
[136] | 131 | // $app =& App::getInstance(); |
---|
| 132 | // $app->dieURL('/die/to/this/url.php'); |
---|
[1] | 133 | // } |
---|
[42] | 134 | // |
---|
[1] | 135 | // function test_dieboomerangurl() |
---|
| 136 | // { |
---|
| 137 | // $result = $this->App->dieboomerangurl(PARAM); |
---|
| 138 | // $expected = EXPECTED_VAL; |
---|
| 139 | // $this->assertEquals($expected, $result); |
---|
| 140 | // } |
---|
[42] | 141 | // |
---|
[1] | 142 | // function test_setboomerangurl() |
---|
| 143 | // { |
---|
| 144 | // $result = $this->App->setboomerangurl(PARAM); |
---|
| 145 | // $expected = EXPECTED_VAL; |
---|
| 146 | // $this->assertEquals($expected, $result); |
---|
| 147 | // } |
---|
[42] | 148 | // |
---|
[1] | 149 | // function test_getboomerangurl() |
---|
| 150 | // { |
---|
| 151 | // $result = $this->App->getboomerangurl(PARAM); |
---|
| 152 | // $expected = EXPECTED_VAL; |
---|
| 153 | // $this->assertEquals($expected, $result); |
---|
| 154 | // } |
---|
[42] | 155 | // |
---|
[1] | 156 | // function test_deleteboomerangurl() |
---|
| 157 | // { |
---|
| 158 | // $result = $this->App->deleteboomerangurl(PARAM); |
---|
| 159 | // $expected = EXPECTED_VAL; |
---|
| 160 | // $this->assertEquals($expected, $result); |
---|
| 161 | // } |
---|
[42] | 162 | // |
---|
[1] | 163 | // function test_validboomerangurl() |
---|
| 164 | // { |
---|
| 165 | // $result = $this->App->validboomerangurl(PARAM); |
---|
| 166 | // $expected = EXPECTED_VAL; |
---|
| 167 | // $this->assertEquals($expected, $result); |
---|
| 168 | // } |
---|
[42] | 169 | // |
---|
[1] | 170 | // function test_sslon() |
---|
| 171 | // { |
---|
| 172 | // $result = $this->App->sslon(PARAM); |
---|
| 173 | // $expected = EXPECTED_VAL; |
---|
| 174 | // $this->assertEquals($expected, $result); |
---|
| 175 | // } |
---|
[42] | 176 | // |
---|
[1] | 177 | // function test_ssloff() |
---|
| 178 | // { |
---|
| 179 | // $result = $this->App->ssloff(PARAM); |
---|
| 180 | // $expected = EXPECTED_VAL; |
---|
| 181 | // $this->assertEquals($expected, $result); |
---|
| 182 | // } |
---|
| 183 | |
---|
| 184 | } |
---|
| 185 | // Running the test. |
---|
| 186 | $suite = new PHPUnit_TestSuite('AppTest'); |
---|
| 187 | $result = PHPUnit::run($suite); |
---|
| 188 | echo $result->toString(); |
---|
| 189 | ?> |
---|