00001 <?php 00008 class UTDb extends foUnitTestBase 00009 { 00010 public function doTest() 00011 { 00012 $this->_testDbClass(); 00013 $this->_testEscN(); 00014 $this->_testEscS(); 00015 } 00016 00017 private function _testDbClass() 00018 { 00019 $this->setSectionLabel('Db class'); 00020 $config = new Config(); 00021 00022 eval($this->needNotEmpty('$db = new Db($config)')); 00023 eval($this->needEmpty('$db->setConfigName("mysql")')); 00024 eval($this->needEqual('$db->getConfigName()', '"mysql"')); 00025 eval($this->needEmpty('$db->pushConfigName("dead_database")')); 00026 eval($this->needEqual('$db->getConfigName()', '"dead_database"')); 00027 eval($this->needEmpty('$db->popConfigName()')); 00028 eval($this->needEqual('$db->getConfigName()', '"mysql"')); 00029 eval($this->needNotEmpty('$conn = $db->getConnection()')); 00030 eval($this->needNotEmpty('$resultSet = $db->executeQuery("select \"Hey, Bishop. Do the thing with the knife. \" as col1")')); 00031 $resultSet->next(); 00032 eval($this->needEqual('$resultSet->getRecordCount()', '1')); 00033 eval($this->needEqual('$resultSet->getString("col1")', '"Hey, Bishop. Do the thing with the knife. "')); 00034 } 00035 00036 private function _testEscN() 00037 { 00038 $this->setSectionLabel('escN'); 00039 00040 $emptyString = ""; 00041 eval($this->needEqual('escN($emptyString)', '"NULL"')); 00042 00043 $number23 = 23; 00044 eval($this->needEqual('escN($number23)', 23)); 00045 00046 $zeroNumber = 0; 00047 eval($this->needEqual('escN($zeroNumber)', 0)); 00048 } 00049 00050 private function _testEscS() 00051 { 00052 $this->setSectionLabel('escS'); 00053 00054 $emptyString = ""; 00055 eval($this->needEqual('escS($emptyString)', '"NULL"')); 00056 00057 $notEmptyString = "Game over man"; 00058 eval($this->needEqual('escS($notEmptyString)', "'\'Game over man\''")); 00059 eval($this->needEqual('escS($notEmptyString, "%", ESC_NONE)', "'\'Game over man\''")); 00060 eval($this->needEqual('escS($notEmptyString, "%", ESC_LAST)', "'\'Game over man%\''")); 00061 eval($this->needEqual('escS($notEmptyString, "%", ESC_FIRST)', "'\'%Game over man\''")); 00062 eval($this->needEqual('escS($notEmptyString, "%", ESC_BOTH)', "'\'%Game over man%\''")); 00063 00064 $number23 = 23; 00065 eval($this->needEqual('escS($number23)', "'\'23\''")); 00066 00067 $zeroNumber = 0; 00068 eval($this->needEqual('escS($zeroNumber)', "'\'0\''")); 00069 00070 $zeroNumber = 0; 00071 eval($this->needEqual('escS($zeroNumber)', 0)); 00072 } 00073 } 00074 ?>