* Copyright 2001-2012 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /** * PHPUnit test case for codebase/lib/App.inc.php * * The method skeletons below need to be filled in with * real data so that the tests will run correctly. Replace * all EXPECTED_VAL and PARAM strings with real data. * * Created with PHPUnit_Skeleton on 2005-08-09 */ class AppTest extends PHPUnit_Framework_TestCase { var $App; static $shared_session; function setUp() { require dirname(__FILE__) . '/_config.inc.php'; $this->App =& $app; $this->App->cli = false; $_SESSION = AppTest::$shared_session; } function tearDown() { unset($this->App); AppTest::$shared_session = $_SESSION; } function test_getinstance() { $thisapp =& App::getInstance(); $this->assertTrue($thisapp === $this->App, 'Objects do not match across instantiations.'); } function test_setParam() { $this->App->setParam(array( 'test_config_value' => 1234 )); $this->assertTrue(1234 === $this->App->getParam('test_config_value')); } function test_getParam() { //$this->App->setParam('test_config_value2', 'okay'); $this->App->setParam(array( 'test_config_value2' => 'okay' )); $result = $this->App->getParam('test_config_value2'); $this->assertEquals('okay', $result); } function test_start() { unset($_SESSION); $this->App->stop(); $this->App->start(); $this->assertEquals(ini_get('error_reporting'), E_ALL, 'Error reporting not set to E_ALL.'); $this->assertTrue(isset($_SESSION), '$_SESSION is not set.'); $_SESSION['sess_test_value'] = 'okay'; $this->assertEquals($_SESSION['sess_test_value'], 'okay', '$_SESSION not storing values.'); $this->assertTrue(session_name() == 'StrangecodeTestSession', 'Session_name not set correctly.'); } function test_stop() { } function test_dbquery() { $db =& DB::getInstance(); $qid = $db->query("SELECT 2 + 2"); list($result) = mysql_fetch_row($qid); $this->assertEquals('4', $result); } function test_raisemsg() { $app =& App::getInstance(); $expected = 'My message'; $app->raiseMsg($expected, MSG_NOTICE, __FILE__, __LINE__); $msg = current($_SESSION['_app']['testapp']['messages']); $this->assertEquals($expected, $msg['message']); } function test_printraisedmessages() { $app =& App::getInstance(); ob_start(); $this->test_raisemsg(); //had to add this line for phpunit ver. 3.7 $app->printraisedmessages(); $result = ob_get_clean(); $this->assertContains('My message', $result, 'Raised message not found in output.'); } function test_logmsg() { $app =& App::getInstance(); $file = $this->App->getParam('log_directory') . '/' . $this->App->getParam('log_filename'); $app->logMsg('Test log message', LOG_DEBUG, __FILE__, __LINE__); if ($result = file($file)) { $result = end($result); } else { $result = ''; } $this->assertContains('Test log message', $result, 'Test message not recorded in log: ' . $file); } function test_ohref() { $app =& App::getInstance(); $_REQUEST['arg1'] = 'A'; $result = $app->ohref('/some/url.php', array('arg1'), true); $this->assertContains(session_name(), $result, 'SSID not found in URL.'); $this->assertContains('arg1=A', $result, 'Argument not passed through.'); } function test_printhiddensession() { $app =& App::getInstance(); $app->setParam(array('session_use_trans_sid' => true)); ob_start(); $app->printhiddensession(); $result = ob_get_clean(); $this->assertContains(session_name(), $result); } // function test_dieurl() // { // $app =& App::getInstance(); // $app->dieURL('/die/to/this/url.php'); // } // // function test_dieboomerangurl() // { // $result = $this->App->dieboomerangurl(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } // // function test_setboomerangurl() // { // $result = $this->App->setboomerangurl(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } // // function test_getboomerangurl() // { // $result = $this->App->getboomerangurl(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } // // function test_deleteboomerangurl() // { // $result = $this->App->deleteboomerangurl(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } // // function test_validboomerangurl() // { // $result = $this->App->validboomerangurl(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } // // function test_sslon() // { // $result = $this->App->sslon(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } // // function test_ssloff() // { // $result = $this->App->ssloff(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } } // Running the test. /* $suite = new PHPUnit_TestSuite('AppTest'); $result = PHPUnit::run($suite); echo $result->toString(); */