[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[120] trunk/0.3
Status: Beta
                
                Brought to you by:
                
                    crazedsanity
                    
                
            | 
      
      
      From: <cra...@us...> - 2009-08-20 14:55:30
      
     | 
| Revision: 120
          http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=120&view=rev
Author:   crazedsanity
Date:     2009-08-20 14:55:21 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
Drop tables (instead of DB), extra tests.
/cs_authToken.class.php:
	* __construct():
		-- create an instance of cs_webdbupgrade{} to see if an upgrade needs
		to be performed.
		-- NOTE::: this can be removed simply by adding logging, as
		cs_webdblogger::__construct() checks for upgrades.
/tests/testOfCSWebAppLibs.php:
	* create_dbconn() RENAMED FROM create_db()
	* remove_tables() [NEW]:
		-- does a DROP ... CASCADE on all tables belonging to cs-webapplibs
	* test_token_basics():
		-- updated references to use create_dbconn()
		-- move tests around slighly so I can view the database after & know
		for sure that the record that had only 1 use is actually missing
		(because there is a gap in auth_token_id's).
		-- test for creating a token with 0 max uses (to see that the invalid
		value for max_uses is ignored).
Modified Paths:
--------------
    trunk/0.3/cs_authToken.class.php
    trunk/0.3/tests/testOfCSWebAppLibs.php
Modified: trunk/0.3/cs_authToken.class.php
===================================================================
--- trunk/0.3/cs_authToken.class.php	2009-08-20 13:57:54 UTC (rev 119)
+++ trunk/0.3/cs_authToken.class.php	2009-08-20 14:55:21 UTC (rev 120)
@@ -41,6 +41,8 @@
 		}
 		$this->gfObj = new cs_globalFunctions();
 		
+		$upg = new cs_webdbupgrade(dirname(__FILE__) .'/VERSION', dirname(__FILE__) .'/upgrades/upgrade.xml');
+		$upg->check_versions(true);
 	}//end __construct()
 	//=========================================================================
 	
Modified: trunk/0.3/tests/testOfCSWebAppLibs.php
===================================================================
--- trunk/0.3/tests/testOfCSWebAppLibs.php	2009-08-20 13:57:54 UTC (rev 119)
+++ trunk/0.3/tests/testOfCSWebAppLibs.php	2009-08-20 14:55:21 UTC (rev 120)
@@ -126,7 +126,7 @@
 	
 	
 	//--------------------------------------------------------------------------
-	private function create_db() {
+	private function create_dbconn() {
 		$dbParams = array(
 			'host'		=> constant('DB_PG_HOST'),
 			'dbname'	=> constant('DB_PG_DBNAME'),
@@ -141,9 +141,33 @@
 	//--------------------------------------------------------------------------
 	
 	
+	
 	//--------------------------------------------------------------------------
+	private function remove_tables() {
+		$tableList = array(
+			'cswal_auth_token_table', 'cswal_version_table', 'cswdbl_attribute_table', 
+			'cswdbl_category_table', 'cswdbl_class_table', 'cswdbl_event_table', 
+			'cswdbl_log_attribute_table', 'cswdbl_log_table', 
+		);
+		
+		$db = $this->create_dbconn();
+		foreach($tableList as $name) {
+			try {
+				$db->run_update("DROP TABLE ". $name ." CASCADE", true);
+			}
+			catch(exception $e) {
+				//force an error.
+				$this->assertTrue(false, "Error while dropping (". $name .")::: ". $e->getMessage());
+			}
+		}
+	}//end remove_tables()
+	//--------------------------------------------------------------------------
+	
+	
+	//--------------------------------------------------------------------------
 	function test_token_basics() {
-		$db = $this->create_db();
+		$db = $this->create_dbconn();
+		$this->remove_tables();
 		$tok = new authTokenTester($db);
 		
 		//Generic test to ensure we get the appropriate data back.
@@ -157,11 +181,10 @@
 		
 		$this->assertEqual($tok->authenticate_token($tokenData['id'], 'test', $tokenData['hash']), 1);
 		
-		
-		//now create a token with a maximum lifetime...
+		//create a token with only 1 available use and try to authenticate it twice.
 		{
 			//Generic test to ensure we get the appropriate data back.
-			$tokenData = $tok->create_token(1, 'test', 'abc123', '2 years');
+			$tokenData = $tok->create_token(1, 'test', 'abc123', null, 1);
 			$this->assertTrue(is_array($tokenData));
 			$this->assertTrue((count($tokenData) == 2));
 			$this->assertTrue(isset($tokenData['id']));
@@ -169,13 +192,19 @@
 			$this->assertTrue(($tokenData['id'] > 0));
 			$this->assertTrue((strlen($tokenData['hash']) == 32));
 			
-			$this->assertEqual($tok->authenticate_token($tokenData['id'], 'test', $tokenData['hash']), 1);
+			if(!$this->assertEqual($tok->authenticate_token($tokenData['id'], 'test', $tokenData['hash']), 1)) {
+				$this->gfObj->debug_print($tok->tokenData($tokenData['id']),1);
+			}
+			if(!$this->assertTrue(($tok->authenticate_token($tokenData['id'], 'test', $tokenData['hash']) === null), "Able to authenticate twice on a token with only 1 use")) {
+				$this->gfObj->debug_print($tok->tokenData($tokenData['id']));
+			}
 		}
 		
-		//create a token with only 1 available use and try to authenticate it twice.
+		
+		//now create a token with a maximum lifetime...
 		{
 			//Generic test to ensure we get the appropriate data back.
-			$tokenData = $tok->create_token(1, 'test', 'abc123', null, 1);
+			$tokenData = $tok->create_token(1, 'test', 'abc123', '2 years');
 			$this->assertTrue(is_array($tokenData));
 			$this->assertTrue((count($tokenData) == 2));
 			$this->assertTrue(isset($tokenData['id']));
@@ -183,12 +212,20 @@
 			$this->assertTrue(($tokenData['id'] > 0));
 			$this->assertTrue((strlen($tokenData['hash']) == 32));
 			
-			if(!$this->assertEqual($tok->authenticate_token($tokenData['id'], 'test', $tokenData['hash']), 1)) {
-				$this->gfObj->debug_print($tok->tokenData($tokenData['id']),1);
+			$this->assertEqual($tok->authenticate_token($tokenData['id'], 'test', $tokenData['hash']), 1);
+		}
+		
+		//try to create a token with max_uses of 0.
+		{
+			$tokenData = $tok->create_token(2, 'test', 'xxxxyyyyyxxxx', null, 0);
+			$checkData = $tok->tokenData($tokenData['id']);
+			$checkData = $checkData[$tokenData['id']];
+			
+			$this->assertTrue(is_array($checkData));
+			if(!$this->assertEqual($tokenData['id'], $checkData['auth_token_id'])) {
+				$this->gfObj->debug_print($checkData);
 			}
-			if(!$this->assertTrue(($tok->authenticate_token($tokenData['id'], 'test', $tokenData['hash']) === null), "Able to authenticate twice on a token with only 1 use")) {
-				$this->gfObj->debug_print($tok->tokenData($tokenData['id']));
-			}
+			$this->assertEqual($checkData['max_uses'], null);
 		}
 	}//end test_token_basics()
 	//--------------------------------------------------------------------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |