Changeset 136 for trunk/tests
- Timestamp:
- Jun 3, 2006 7:47:48 PM (18 years ago)
- Location:
- trunk/tests
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/AppTest.php
r42 r136 32 32 function test_getinstance() 33 33 { 34 $thisapp =& App::get instance();34 $thisapp =& App::getInstance(); 35 35 $this->assertTrue(serialize($thisapp) == serialize($this->App), 'Objects do not match across instantiations.'); 36 36 } … … 71 71 function test_dbquery() 72 72 { 73 $qid = DB::query("SELECT 2 + 2"); 73 $db =& DB::getInstance(); 74 75 $qid = $db->query("SELECT 2 + 2"); 74 76 list($result) = mysql_fetch_row($qid); 75 77 $this->assertEquals('4', $result); … … 78 80 function test_raisemsg() 79 81 { 82 $app =& App::getInstance(); 80 83 $expected = 'My message'; 81 App::raiseMsg($expected, MSG_NOTICE, __FILE__, __LINE__);82 $msg = current($_SESSION[$this->App-> app]['messages']);84 $app->raiseMsg($expected, MSG_NOTICE, __FILE__, __LINE__); 85 $msg = current($_SESSION[$this->App->_ns]['messages']); 83 86 $this->assertEquals($expected, $msg['message']); 84 87 } … … 87 90 { 88 91 ob_start(); 89 App::printraisedmessages(); 92 $app =& App::getInstance(); 93 $app->printraisedmessages(); 90 94 $result = ob_get_clean(); 91 95 $this->assertContains('My message', $result, 'Raised message not found in output.'); … … 94 98 function test_logmsg() 95 99 { 100 $app =& App::getInstance(); 96 101 $file = $this->App->getParam('log_directory') . '/' . $this->App->getParam('log_filename'); 97 App::logMsg('Test log message', LOG_DEBUG, __FILE__, __LINE__);102 $app->logMsg('Test log message', LOG_DEBUG, __FILE__, __LINE__); 98 103 if ($result = file($file)) { 99 104 $result = end($result); … … 106 111 function test_ohref() 107 112 { 113 $app =& App::getInstance(); 108 114 $_GET['arg1'] = 'A'; 109 $result = App::ohref('/some/url.php', array('arg1'), true);115 $result = $app->ohref('/some/url.php', array('arg1'), true); 110 116 $this->assertContains(session_name(), $result, 'SSID not found in URL.'); 111 117 $this->assertContains('arg1=A', $result, 'Argument not passed through.'); … … 114 120 function test_printhiddensession() 115 121 { 122 $app =& App::getInstance(); 116 123 ob_start(); 117 App::printhiddensession();124 $app->printhiddensession(); 118 125 $result = ob_get_clean(); 119 126 $this->assertContains(session_name(), $result); … … 122 129 // function test_dieurl() 123 130 // { 124 // App::dieURL('/die/to/this/url.php'); 131 // $app =& App::getInstance(); 132 // $app->dieURL('/die/to/this/url.php'); 125 133 // } 126 134 // -
trunk/tests/Auth_FileTest.php
r42 r136 23 23 require dirname(__FILE__) . '/_config.inc.php'; 24 24 require_once '../lib/Auth_File.inc.php'; 25 $this->Auth_File =& new Auth_File(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd')); 25 $this->Auth_File =& new Auth_File('test_auth'); 26 $this->Auth_File->setParam(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd')); 26 27 } 27 28 … … 44 45 $result = $this->Auth_File->login('testuser', 'testpass'); 45 46 $this->assertTrue($result, 'testuser login failed.'); 46 $this->assertTrue($_SESSION[ '_auth']['authenticated'], 'testuser authentication not found in session.');47 $this->assertTrue($_SESSION[$this->Auth_File->_ns]['authenticated'], 'testuser authentication not found in session.'); 47 48 } 48 49 … … 51 52 $result = $this->Auth_File->login('testuser', 'testpass'); 52 53 $this->Auth_File->clearauth(); 53 $this->assertFalse($_SESSION[ '_auth']['authenticated'], 'testuser authentication not false in session.');54 $this->assertFalse($_SESSION[$this->Auth_File->_ns]['authenticated'], 'testuser authentication not false in session.'); 54 55 } 55 56 -
trunk/tests/Auth_SQLTest.php
r42 r136 21 21 function setUp() 22 22 { 23 23 require dirname(__FILE__) . '/_config.inc.php'; 24 24 require_once '../lib/Auth_SQL.inc.php'; 25 25 $this->Auth_SQL =& new Auth_SQL('testauth'); … … 29 29 'db_login_table' => 'test_login_tbl', 30 30 'login_url' => '/login.php', 31 'blocking' => true 31 'blocking' => true, 32 'encryption_type' => AUTH_ENCRYPT_MD5_HARDENED, 32 33 )); 33 34 … … 36 37 37 38 // Insert test data. 38 DB::query(" 39 $db =& DB::getInstance(); 40 $db->query(" 39 41 INSERT INTO test_user_tbl ( 40 42 username, … … 46 48 ) VALUES ( 47 49 'testuser', 48 md5('testpass'),50 '" . $this->Auth_SQL->encryptPassword('testpass') . "', 49 51 'John', 50 52 'Doe', … … 58 60 function tearDown() 59 61 { 60 unset($this->Auth_SQL); 61 DB::query("DROP TABLE IF EXISTS test_user_tbl"); 62 DB::query("DROP TABLE IF EXISTS test_login_tbl"); 62 $db =& DB::getInstance(); 63 64 unset($this->Auth_SQL); 65 $db->query("DROP TABLE IF EXISTS test_user_tbl"); 66 $db->query("DROP TABLE IF EXISTS test_login_tbl"); 63 67 } 64 68 … … 66 70 { 67 71 $this->Auth_SQL->setval('testuserkey', 'testuserval'); 68 $this->assertEquals('testuserval', $_SESSION[$this->Auth_SQL->_ sess]['user_data']['testuserkey']);72 $this->assertEquals('testuserval', $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey']); 69 73 } 70 74 71 75 function test_getval() 72 76 { 73 $_SESSION[$this->Auth_SQL->_ sess]['user_data']['testuserkey'] = 'testuserval';77 $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey'] = 'testuserval'; 74 78 $val = $this->Auth_SQL->getVal('testuserkey'); 75 79 $this->assertEquals('testuserval', $val); … … 107 111 $this->assertTrue($true, 'User login failed, but should have succeeded.'); 108 112 109 echo "Testing wrong password...\n";113 // Testing wrong password. 110 114 $false = $this->Auth_SQL->authenticate('testuser', 'wrongpass'); 111 115 … … 122 126 $after_logged_in = $this->Auth_SQL->isloggedin(); 123 127 $this->assertFalse($after_logged_in, '3. User is still logged in but should not be.'); 124 125 echo "Testing wrong password...\n";128 129 // Testing wrong password. 126 130 $login2 = $this->Auth_SQL->login('testuser', 'wrongpass'); 127 131 $this->assertFalse($login2, '4. User login succeeded, but should have failed.'); … … 140 144 function test_blockaccount() 141 145 { 146 $db =& DB::getInstance(); 147 142 148 $this->Auth_SQL->login('testuser', 'testpass'); 143 149 $this->Auth_SQL->blockaccount(null, 'blocktestuser'); 144 $qid = DB::query("150 $qid = $db->query(" 145 151 SELECT blocked_reason 146 152 FROM test_user_tbl … … 152 158 function test_unblockaccount() 153 159 { 154 DB::query(" 160 $db =& DB::getInstance(); 161 162 $db->query(" 155 163 UPDATE test_user_tbl SET blocked_reason = 'blocktestuser' 156 164 "); 157 165 $this->Auth_SQL->unblockaccount(); 158 166 159 $qid = DB::query("167 $qid = $db->query(" 160 168 SELECT blocked_reason 161 169 FROM test_user_tbl … … 185 193 function test_encryptpassword() 186 194 { 195 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_MD5)); 187 196 $result = $this->Auth_SQL->encryptpassword('123'); 188 197 $this->assertEquals('202cb962ac59075b964b07152d234b70', $result); 198 199 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_MD5_HARDENED)); 200 $result = $this->Auth_SQL->encryptpassword('123'); 201 $this->assertEquals('c55e4ac608a8768ecd758fab971b0646', $result); 202 203 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1)); 204 $result = $this->Auth_SQL->encryptpassword('123'); 205 $this->assertEquals('40bd001563085fc35165329ea1ff5c5ecbdbbeef', $result); 206 207 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1_HARDENED)); 208 $result = $this->Auth_SQL->encryptpassword('123'); 209 $this->assertEquals('33d90af96a5928ac93cbd41fc436e8c55d2768c2', $result); 210 211 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_PLAINTEXT)); 212 $result = $this->Auth_SQL->encryptpassword('123'); 213 $this->assertEquals('123', $result); 214 215 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_CRYPT)); 216 $result = $this->Auth_SQL->encryptpassword('123', 'saltstring'); 217 $this->assertEquals('saEZ6MlWYV9nQ', $result); 189 218 } 190 219 191 220 function test_setpassword() 192 221 { 222 $db =& DB::getInstance(); 223 224 $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1_HARDENED)); 193 225 $this->Auth_SQL->setpassword(null, '123'); 194 $qid = DB::query("226 $qid = $db->query(" 195 227 SELECT userpass 196 228 FROM test_user_tbl 197 229 "); 198 230 list($pass) = mysql_fetch_row($qid); 199 $this->assertEquals(' 202cb962ac59075b964b07152d234b70', $pass);231 $this->assertEquals('33d90af96a5928ac93cbd41fc436e8c55d2768c2', $pass); 200 232 } 201 233 -
trunk/tests/DBSessionHandlerTest.php
r42 r136 24 24 require_once '../lib/DBSessionHandler.inc.php'; 25 25 session_write_close(); 26 $this->DBSessionHandler = new DBSessionHandler($app->db); 27 $this->DBSessionHandler = new DBSessionHandler(null, array( 28 'db_server' => $app->getParam('db_server'), 29 'db_name' => $app->getParam('db_name'), 30 'db_user' => $app->getParam('db_user'), 31 'db_pass' => $app->getParam('db_pass'), 32 'db_always_debug' => $app->getParam('db_always_debug'), 33 'db_debug' => $app->getParam('db_debug'), 34 'db_die_on_failure' => $app->getParam('db_die_on_failure'), 26 $this->DBSessionHandler = new DBSessionHandler($app->db, array( 27 'db_table' => 'session_tbl', 28 'create_table' => true, 35 29 )); 36 30 } -
trunk/tests/RecordLockTest.php
r42 r136 21 21 22 22 function setUp() 23 { 23 { 24 24 require dirname(__FILE__) . '/_config.inc.php'; 25 25 require_once '../lib/RecordLock.inc.php'; 26 26 require_once '../lib/Auth_SQL.inc.php'; 27 27 28 $this->Auth_SQL =& new Auth_SQL('test auth');28 $this->Auth_SQL =& new Auth_SQL('test'); 29 29 $this->Auth_SQL->setParam(array( 30 30 'db_table' => 'test_user_tbl', … … 39 39 40 40 // Insert test data. 41 DB::query(" 41 $db =& DB::getInstance(); 42 $db->query(" 42 43 INSERT INTO test_user_tbl ( 43 44 username, … … 49 50 ) VALUES ( 50 51 'testuser', 51 md5('testpass'),52 '" . $this->Auth_SQL->encryptPassword('testpass') . "', 52 53 'John', 53 54 'Doe', … … 57 58 "); 58 59 $this->Auth_SQL->login('testuser', 'testpass'); 60 61 if (!$this->Auth_SQL->isLoggedIn()) { 62 trigger_error("User login failed...tests canceled.", E_USER_ERROR); 63 } 59 64 60 65 $this->RecordLock =& RecordLock::getInstance($this->Auth_SQL); … … 67 72 function tearDown() 68 73 { 74 $db =& DB::getInstance(); 75 69 76 unset($this->RecordLock); 70 77 unset($this->Auth_SQL); 71 DB::query("DROP TABLE IF EXISTS test_user_tbl");72 DB::query("DROP TABLE IF EXISTS test_login_tbl");73 DB::query("DROP TABLE IF EXISTS test_lock_tbl");78 $db->query("DROP TABLE IF EXISTS test_user_tbl"); 79 $db->query("DROP TABLE IF EXISTS test_login_tbl"); 80 $db->query("DROP TABLE IF EXISTS test_lock_tbl"); 74 81 } 75 82 -
trunk/tests/RecordVersionTest.php
r42 r136 21 21 22 22 function setUp() 23 { 23 { 24 24 require dirname(__FILE__) . '/_config.inc.php'; 25 25 require_once '../lib/RecordVersion.inc.php'; … … 39 39 40 40 // Insert test data. 41 DB::query(" 41 $db =& DB::getInstance(); 42 $db->query(" 42 43 INSERT INTO test_user_tbl ( 43 44 username, … … 68 69 function tearDown() 69 70 { 71 $db =& DB::getInstance(); 72 70 73 unset($this->RecordVersion); 71 74 unset($this->Auth_SQL); 72 DB::query("DROP TABLE IF EXISTS test_user_tbl");73 DB::query("DROP TABLE IF EXISTS test_login_tbl");74 DB::query("DROP TABLE IF EXISTS test_version_tbl");75 $db->query("DROP TABLE IF EXISTS test_user_tbl"); 76 $db->query("DROP TABLE IF EXISTS test_login_tbl"); 77 $db->query("DROP TABLE IF EXISTS test_version_tbl"); 75 78 } 76 79 -
trunk/tests/SessionCacheTest.php
r42 r136 4 4 5 5 /** 6 * PHPUnit test case for SessionCache6 * PHPUnit test case for Cache 7 7 * 8 8 * The method skeletons below need to be filled in with … … 13 13 */ 14 14 require_once 'PHPUnit.php'; 15 class SessionCacheTest extends PHPUnit_TestCase {15 class CacheTest extends PHPUnit_TestCase { 16 16 17 var $ SessionCache;17 var $Cache; 18 18 19 function SessionCacheTest($name)19 function CacheTest($name) 20 20 { 21 21 $this->PHPUnit_TestCase($name); … … 25 25 { 26 26 require dirname(__FILE__) . '/_config.inc.php'; 27 require_once '../lib/ SessionCache.inc.php';28 $this-> SessionCache =& new SessionCache(PARAM);27 require_once '../lib/Cache.inc.php'; 28 $this->Cache =& new Cache(PARAM); 29 29 } 30 30 31 31 function tearDown() 32 32 { 33 unset($this-> SessionCache);33 unset($this->Cache); 34 34 } 35 35 36 36 function test_getinstance() 37 37 { 38 $result = $this-> SessionCache->getinstance(PARAM);38 $result = $this->Cache->getinstance(PARAM); 39 39 $expected = EXPECTED_VAL; 40 40 $this->assertEquals($expected, $result); … … 43 43 function test_setparam() 44 44 { 45 $result = $this-> SessionCache->setparam(PARAM);45 $result = $this->Cache->setparam(PARAM); 46 46 $expected = EXPECTED_VAL; 47 47 $this->assertEquals($expected, $result); … … 50 50 function test_getparam() 51 51 { 52 $result = $this-> SessionCache->getparam(PARAM);52 $result = $this->Cache->getparam(PARAM); 53 53 $expected = EXPECTED_VAL; 54 54 $this->assertEquals($expected, $result); … … 57 57 function test_putcache() 58 58 { 59 $result = $this-> SessionCache->putcache(PARAM);59 $result = $this->Cache->putcache(PARAM); 60 60 $expected = EXPECTED_VAL; 61 61 $this->assertEquals($expected, $result); … … 64 64 function test_getcache() 65 65 { 66 $result = $this-> SessionCache->getcache(PARAM);66 $result = $this->Cache->getcache(PARAM); 67 67 $expected = EXPECTED_VAL; 68 68 $this->assertEquals($expected, $result); … … 71 71 function test_iscached() 72 72 { 73 $result = $this-> SessionCache->iscached(PARAM);73 $result = $this->Cache->iscached(PARAM); 74 74 $expected = EXPECTED_VAL; 75 75 $this->assertEquals($expected, $result); … … 78 78 function test_breakcache() 79 79 { 80 $result = $this-> SessionCache->breakcache(PARAM);80 $result = $this->Cache->breakcache(PARAM); 81 81 $expected = EXPECTED_VAL; 82 82 $this->assertEquals($expected, $result); … … 85 85 } 86 86 // Running the test. 87 $suite = new PHPUnit_TestSuite(' SessionCacheTest');87 $suite = new PHPUnit_TestSuite('CacheTest'); 88 88 $result = PHPUnit::run($suite); 89 89 echo $result->toString(); -
trunk/tests/_config.inc.php
r43 r136 1 1 <?php 2 2 require_once '../lib/App.inc.php'; 3 $app =& App::get instance('testapp');3 $app =& App::getInstance('testapp'); 4 4 5 5 $app->setParam(array(
Note: See TracChangeset
for help on using the changeset viewer.