$prop) { $diff = array_diff(array_keys($prop),$max_prop_arr); foreach($diff as $key) { trigger_error("unknown dbobj config option '$key'=>".var_export($prop[$key],1)." in '$className' class, '$propName' property",E_USER_ERROR); } } return $conf; } dbobj::$connectionParameters = array( 'local' => array( 'driver' => 'pgsql', 'dsn' => 'host=localhost', 'username' => 'dbobjdev', 'password' => 'dbobjdev', ), ); //var_dump(dbobj::$connectionParameters); /** define classes **/ class class1 extends dbobj { static $dbobj_config = array('table'=>'klasszTable', 'conn' => 'local', 'properties'=>array( 'id'=>array('type'=>'integer','access'=>'pub','PK'=>true), 'id2'=>array('type'=>'integer','access'=>'pub','PK'=>true), 'i'=>array('type'=>'integer','read_access'=>'pub','write_access'=>'pub'), 't'=>array('type'=>'varchar(50)','access'=>'pub','defaultLoad'=>0), 'relTest'=>array('sources'=>'i','type'=>'>autoIDtest(id)','access'=>'pub'), ), ); var $elso = 1; var $masodik = 6; function korte() { echo OK; return true; } function __construct($id = null, $id2 = null) { if(isset($id)) { $this->id = $id; $this->id = $id2; $GLOBALS['constructor_has_ran'] = true; } } } class autoIDtest extends dbobj { static $dbobj_config = array('table'=>'autoIDtestTable', 'conn' => 'local', 'properties'=>array( 'id'=>array('type'=>'serial:autoIDtestTable_id_seq','autoID'=>true,'access'=>'pub'), 't'=>array('type'=>'text','access'=>'pub','dbField'=>'alma'), 'backrelTest'=>array('sources'=>'id','type'=>'>class1(i)','access'=>'pub'), ), ); function __construct($t) { echo OK; $this->t = $t; } } /** autoIDtest + constructor **/ echo "autoIDtest with constructor:\t"; $a = new autoIDtest('alma'); if(!$a) { die(FAILED); } $a = null; /** dbobj_find **/ echo "dbobj_find:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); if(!$a) { die(FAILED); } else { echo OK; } $a = null; /** Singleton test **/ echo "Singleton:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); $b = dbobj_find('class1',array('id'=>3,'id2'=>5)); if($a !== $b) { die(FAILED); } else { echo OK; } $a = $b = null; /** isset test 1 **/ echo "isset(\$a->this_is_not_in_the_config):\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); $value = isset($a->this_is_not_in_the_config); if($value) die(FAILED); else echo OK; $a = null; /** isset test 2 **/ echo "isset(\$in_db->id):\t"; $in_db = dbobj_find('class1',array('id'=>3,'id2'=>5)); $value = isset($in_db->id); if(!$value) die(FAILED); else echo OK; $in_db = null; /** isset test 3 **/ echo "isset(\$in_memory->id):\t"; $in_memory = new class1(); $value = isset($in_memory->id); if($value) die(FAILED); else echo OK; $in_memory->delete_on_save(true); $in_memory = null; /** var_export test **/ echo "var_export:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); if(var_export($a,true)) { echo OK; } else { die(FAILED); } $a = null; /** Search by PKs for non-existent **/ echo "Search by PKs for non-existent:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>6876515)); if($a === null) { echo OK; } else { die(FAILED); } $a = null; /** Search by non-PKs for non-existent **/ echo "Search by non-PKs for non-existent:\t"; $a = dbobj_find('class1',array('id2'=>6876515)); if($a === null) { echo OK; } else { die(FAILED); } $a = null; /** Refcount test **/ echo "Refcount:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); $a = null; $b = dbobj_find('class1',array('id'=>3,'id2'=>5)); $b = null; echo OK; /** FindAll (empty array) test **/ echo "FindAll (empty array):\t"; $a = dbobj_find('class1',array()); if($a) { echo OK; } else { die(FAILED); } $a = null; /** FindAll (one param) test **/ echo "FindAll (one param):\t"; $a = dbobj_find('class1'); if($a) { echo OK; } else { die(FAILED); } $a = null; /** iterator->current test **/ echo "iterator->current() :\t"; $a = dbobj_find('class1'); if($a && $a->current()) { echo OK; } else { die(FAILED); } $a = null; /** constructor **/ echo "constructor for non-autoID:\t"; $a = new class1(3,5); if($a && $GLOBALS['constructor_has_ran']) { echo OK; } else { die(FAILED); } $a->delete_on_save(true); $a = null; /** PK attribute read **/ echo "PK Attribute read:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); if($a->id2 == 5) { echo OK; } else { die(FAILED); } $a = null; /** Attribute read **/ echo "Attribute read:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); if($a->i == 127) { echo OK; } else { echo "\t... doing automatic correction, reRun to see result ..."; $a->i = 127; $a->save(); die(FAILED); } /** Attribute write same **/ echo "Attribute write same:\t"; $a->i = 127; if($a->i == 127) { echo OK; } else { echo(FAILED); } /** Attribute write **/ echo "Attribute write:\t"; $tmp = $a->i; $a->i = $tmp + 1; if($a->i == $tmp + 1) { echo OK; } else { echo(FAILED); } $a->save(); // these cancel each other out, so they must be used together echo "Attribute direct write:\t"; $a->i --; $a->save(); if($a->i == 127) { echo OK; } else { echo(FAILED); } /** Method call **/ echo "Method call:\t"; if($a->korte()) { } else { die(FAILED); } /** Relation test **/ echo "Relation test:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); if(!$a) die(FAILED); $b = $a->relTest; if(!$b) die(FAILED); $c = $a->relTest; if(!$c) die(FAILED); $d = $a->relTest->backrelTest; if(!$d) die(FAILED); $tmp = 0; foreach($d as $o) { echo OK; $tmp++; break; } if(!$tmp) die(FAILED); $d = $b = $c = null; /** Serialize test **/ echo "Serialize test:\t"; $a = dbobj_find('class1',array('id'=>3,'id2'=>5)); if(!$a) die(FAILED); $a_serialized = serialize($a); $a_unserialized = unserialize($a_serialized); if($a == $a_unserialized) { echo OK; } else { die(FAILED); } $a = $a_serialized = null; $b = $a_unserialized; $a_unserialized = null; $b = null; /** **/ echo "** END **"; /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ ?>