[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[172] trunk/0.3
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2010-06-21 15:54:22
|
Revision: 172 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=172&view=rev Author: crazedsanity Date: 2010-06-21 15:54:15 +0000 (Mon, 21 Jun 2010) Log Message: ----------- More changes for unit testing. Modified Paths: -------------- trunk/0.3/abstract/cs_genericGroup.abstract.class.php trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php trunk/0.3/cs_genericPermission.class.php trunk/0.3/cs_phpDB.class.php trunk/0.3/setup/genericPermissions.pgsql.sql trunk/0.3/tests/testOfCSGenericPermissions.php Removed Paths: ------------- trunk/0.3/abstract/cs_group.abstract.class.php Modified: trunk/0.3/abstract/cs_genericGroup.abstract.class.php =================================================================== --- trunk/0.3/abstract/cs_genericGroup.abstract.class.php 2010-06-21 15:12:12 UTC (rev 171) +++ trunk/0.3/abstract/cs_genericGroup.abstract.class.php 2010-06-21 15:54:15 UTC (rev 172) @@ -1,7 +1,6 @@ <?php - /* - * Created on June 03, 2010 + * Created on June 18, 2010 * * FILE INFORMATION: * @@ -14,44 +13,51 @@ abstract class cs_genericGroupAbstract extends cs_webapplibsAbstract { + /** Database object. */ + public $db; + + /** cs_globalFunctions object, for cleaning strings & such. */ + public $gfObj; + /** Table name used to store groups. */ const groupTable = "cswal_group_table"; /** Sequence for groups table. */ - const groupSeq = "cswal_group_table_group_id_seq"; + const groupSeq = "cswal_group_table_group_id"; //============================================================================ - public abstract function __construct(cs_phpDB $db) { - parent::__construct($db); + public function __construct(cs_phpDB $db) { + $this->db = $db; + $this->gfObj = new cs_globalFunctions; }//end __construct() //============================================================================ //============================================================================ - protected function clean_group_name($groupName) { - try { - $retval = $this->clean_permission_name($groupName); + protected function clean_group_name($name) { + if(!is_null($name) && is_string($name) && strlen($name)) { + $name = $this->gfObj->cleanString(strtolower($name), 'email'); } - catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to clean group name (". $groupName .")"); + else { + throw new exception(__METHOD__ .":: invalid string (". $name .")"); } - return($retval); }//end clean_group_name() //============================================================================ //============================================================================ - public function create_group($groupName) { - try { - $groupName = $this->clean_group_name($groupName); - $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $groupName ."')"; - $newId = $this->db->run_insert($sql, self::groupSeq); + public function create_group($name) { + try{ + $name = $this->clean_group_name($name); + $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $name ."')"; + $newId = $this->db->run_insert($sql, self::gropuSeq); } catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to create group (". $groupName ."), DETAILS::: ". $e->getMessage()); + throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage()); } + return($newId); }//end create_group() //============================================================================ @@ -59,15 +65,16 @@ //============================================================================ - public function get_group($groupName) { + public function get_group($name) { try { - $groupName = $this->clean_group_name($groupName); - $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $groupName ."'"; + $name = $this->clean_group_name($name); + $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $name ."'"; $retval = $this->db->run_query($sql); } catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to locate group (". $groupName ."), DETAILS::: ". $e->getMessage()); + throw new exception(__METHOD__ .":: error while locating group '". $name ."', DETAILS::: ". $e->getMessage()); } + return($retval); }//end get_group() //============================================================================ @@ -86,11 +93,30 @@ } } catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to locate group ID (". $groupId ."), DETAILS::: ". $e->getMessage()); + throw new exception(__METHOD__ .":: error while locating group '". $groupId ."', DETAILS::: ". $e->getMessage()); } + return($retval); }//end get_group_by_id() //============================================================================ + + + //============================================================================ + /** + * Build the schema for the generic permissions system. + */ + protected function build_schema() { + try { + $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericPermissions.pgsql.sql'); + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage()); + } + if($result !== true) { + throw new exception(__METHOD__ .":: failed to create schema (no details)"); + } + }//end build_schema() + //============================================================================ } ?> Modified: trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php =================================================================== --- trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php 2010-06-21 15:12:12 UTC (rev 171) +++ trunk/0.3/abstract/cs_genericUserGroup.abstract.class.php 2010-06-21 15:54:15 UTC (rev 172) @@ -21,7 +21,7 @@ const ugSeq = "cswal_user_group_table_user_group_id_seq"; //============================================================================ - public abstract function __construct(cs_phpDB $db) { + public function __construct(cs_phpDB $db) { parent::__construct($db); }//end __construct() //============================================================================ @@ -36,7 +36,7 @@ $newId = $this->db->run_insert($sql, self::ugSeq); } catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to create group (". $groupName ."), DETAILS::: ". $e->getMessage()); + throw new exception(__METHOD__ .":: failed to create user group, DETAILS::: ". $e->getMessage()); } } else { Deleted: trunk/0.3/abstract/cs_group.abstract.class.php =================================================================== --- trunk/0.3/abstract/cs_group.abstract.class.php 2010-06-21 15:12:12 UTC (rev 171) +++ trunk/0.3/abstract/cs_group.abstract.class.php 2010-06-21 15:54:15 UTC (rev 172) @@ -1,122 +0,0 @@ -<?php -/* - * Created on June 18, 2010 - * - * FILE INFORMATION: - * - * $HeadURL$ - * $Id$ - * $LastChangedDate$ - * $LastChangedBy$ - * $LastChangedRevision$ - */ - -class cs_groupAbstract extends cs_webapplibsAbstract { - - /** Database object. */ - public $db; - - /** cs_globalFunctions object, for cleaning strings & such. */ - public $gfObj; - - /** Table name used to store groups. */ - const groupTable = "cswal_group_table"; - - /** Sequence for groups table. */ - const groupSeq = "cswal_group_table_group_id"; - - //============================================================================ - public abstract function __construct(cs_phpDB $db) { - $this->db = $db; - $this->gfObj = new cs_globalFunctions; - }//end __construct() - //============================================================================ - - - - //============================================================================ - protected function clean_group_name($name) { - if(!is_null($name) && is_string($name) && strlen($name)) { - $name = $this->gfObj->cleanString(strtolower($name), 'email'); - } - else { - throw new exception(__METHOD__ .":: invalid string (". $name .")"); - } - }//end clean_group_name() - //============================================================================ - - - - //============================================================================ - public function create_group($name) { - try{ - $name = $this->clean_group_name($name); - $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $name ."')"; - $newId = $this->db->run_insert($sql, self::gropuSeq); - } - catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage()); - } - - return($newId); - }//end create_group() - //============================================================================ - - - - //============================================================================ - public function get_group($name) { - try { - $name = $this->clean_group_name($name); - $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $name ."'"; - $retval = $this->db->run_query($sql); - } - catch(Exception $e) { - throw new exception(__METHOD__ .":: error while locating group '". $name ."', DETAILS::: ". $e->getMessage()); - } - - return($retval); - }//end get_group() - //============================================================================ - - - - //============================================================================ - public function get_group_by_id($groupId) { - try { - if(!is_null($groupId) && is_numeric($groupId)) { - $sql = "SELECT * FROM ". self::groupTable ." WHERE group_id='". $groupId ."'"; - $retval = $this->db->run_query($sql); - } - else { - throw new exception(__METHOD__ .":: invalid group ID (". $groupId .")"); - } - } - catch(Exception $e) { - throw new exception(__METHOD__ .":: error while locating group '". $groupId ."', DETAILS::: ". $e->getMessage()); - } - - return($retval); - }//end get_group_by_id() - //============================================================================ - - - - //============================================================================ - /** - * Build the schema for the generic permissions system. - */ - private function build_schema() { - try { - $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericPermissions.pgsql.sql'); - } - catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage()); - } - if($result !== true) { - throw new exception(__METHOD__ .":: failed to create schema (no details)"); - } - }//end build_schema() - //============================================================================ -} -?> Modified: trunk/0.3/cs_genericPermission.class.php =================================================================== --- trunk/0.3/cs_genericPermission.class.php 2010-06-21 15:12:12 UTC (rev 171) +++ trunk/0.3/cs_genericPermission.class.php 2010-06-21 15:54:15 UTC (rev 172) @@ -29,7 +29,7 @@ protected $keys = array(); //============================================================================ - public abstract function __construct(cs_phpDB $db) { + public function __construct(cs_phpDB $db) { $this->db = $db; parent::__construct($db); $this->gfObj = new cs_globalFunctions; @@ -70,7 +70,7 @@ //handle it like an array. for($x=0;$x<strlen($string);$x++) { $myVal = false; - if($string[$x] !== '-') + if($string[$x] !== '-') { $myVal = true; } $key = $this->keys[$x]; @@ -176,7 +176,7 @@ //============================================================================ public function get_object_by_id($objectId) { - return($this->get_permission_by_id($objectId); + return($this->get_permission_by_id($objectId)); }//end get_object_by_id() //============================================================================ Modified: trunk/0.3/cs_phpDB.class.php =================================================================== --- trunk/0.3/cs_phpDB.class.php 2010-06-21 15:12:12 UTC (rev 171) +++ trunk/0.3/cs_phpDB.class.php 2010-06-21 15:54:15 UTC (rev 172) @@ -205,14 +205,8 @@ $this->lastSQLFile = $filename; $fileContents = $fsObj->read($filename); - try { - $this->db->run_update($fileContents, true); - $this->build_cache(); - $retval = TRUE; - } - catch(exception $e) { - $retval = FALSE; - } + $this->run_update($fileContents, true); + $retval = TRUE; return($retval); }//end run_sql_file() Modified: trunk/0.3/setup/genericPermissions.pgsql.sql =================================================================== --- trunk/0.3/setup/genericPermissions.pgsql.sql 2010-06-21 15:12:12 UTC (rev 171) +++ trunk/0.3/setup/genericPermissions.pgsql.sql 2010-06-21 15:54:15 UTC (rev 172) @@ -7,7 +7,7 @@ CREATE TABLE cswal_group_table ( group_id serial NOT NULL PRIMARY KEY, group_name text NOT NULL UNIQUE, - group_admin integer NOT NULL REFERENCES cs_authtentication_table(uid) + group_admin integer REFERENCES cs_authentication_table(uid) ); -- Modified: trunk/0.3/tests/testOfCSGenericPermissions.php =================================================================== --- trunk/0.3/tests/testOfCSGenericPermissions.php 2010-06-21 15:12:12 UTC (rev 171) +++ trunk/0.3/tests/testOfCSGenericPermissions.php 2010-06-21 15:54:15 UTC (rev 172) @@ -20,6 +20,7 @@ if(!defined('CS_UNITTEST')) { throw new exception(__METHOD__ .": FATAL: constant 'CS_UNITTEST' not set, can't do testing safely"); } + $this->get_valid_users(); }//end __construct() //-------------------------------------------------------------------------- @@ -65,12 +66,40 @@ //-------------------------------------------------------------------------- + /** + * Just like the schema, this SQL will need to change to match your database in order to work. + */ + private function get_valid_users() { + $sql = "SELECT uid,username FROM cs_authentication_table ORDER BY uid"; + $db = $this->create_dbconn(); + $this->validUsers = $db->run_query($sql); + $this->gfObj->debug_print($this->validUsers); + }//end get_valid_users() + //-------------------------------------------------------------------------- + + + + //-------------------------------------------------------------------------- public function test_userGroups() { - $perm = new cs_genericPermission($this->create_dbconn()); + $perm = new _gpTester($this->create_dbconn()); + $perm->do_schema(); + + //create a group with an invalid group_id. + $perm->create_user_group($this->validUsers[0]['uid'],1); }//end test_userGroups //-------------------------------------------------------------------------- } + +class _gpTester extends cs_genericPermission { + public function __construct($db) { + parent::__construct($db); + } + + public function do_schema() { + $this->build_schema(); + } +} ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |