Changeset 444

Show
Ignore:
Timestamp:
05/28/07 14:33:08 (2 years ago)
Author:
laurentj
Message:

fix bug #180 : because of a bug in PDO, jDbPdoResulset::fetch was not called when we used this resultset as an iterator, so results were not stored in an object, but in an array. This causes bugs in jDAO too. Added new unit tests on jDb and jDao

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/manifests/testapp.mn

    r423 r444  
    7575  utselectormod.class.php 
    7676  utsimpletest.class.php 
     77  utjdb.class.php 
     78  utjdb_pdo.class.php 
     79  utjdb_profile.class.php 
    7780  utdao.class.php 
    78   utdao2.class.php 
     81  utdaopdo.class.php 
     82  utdao_parser.class.php 
     83  utdao_parser2.class.php 
    7984  utdao_conditions.class.php 
    8085  utfilter.class.php 
     
    109114  tpl.classic.php 
    110115  acl.classic.php 
     116  db.classic.php 
     117cd testapp/modules/unittest/daos 
     118  products.dao.xml 
    111119 
    112120cd testapp/var 
  • trunk/build/manifests/testapp.mn

    r423 r444  
    7575  utselectormod.class.php 
    7676  utsimpletest.class.php 
     77  utjdb.class.php 
     78  utjdb_pdo.class.php 
     79  utjdb_profile.class.php 
    7780  utdao.class.php 
    78   utdao2.class.php 
     81  utdaopdo.class.php 
     82  utdao_parser.class.php 
     83  utdao_parser2.class.php 
    7984  utdao_conditions.class.php 
    8085  utfilter.class.php 
     
    109114  tpl.classic.php 
    110115  acl.classic.php 
     116  db.classic.php 
     117cd testapp/modules/unittest/daos 
     118  products.dao.xml 
    111119 
    112120cd testapp/var 
  • trunk/lib/jelix/core/jConfigCompiler.class.php

    r375 r444  
    6262            $config->urlengine['basePath'] = $path; 
    6363        } 
     64 
     65        /*if(preg_match("/^([a-zA-Z]{2})(?:_([a-zA-Z]{2}))?$/",$config->defaultLocale,$m)){ 
     66            if(!isset($m[2])){ 
     67                $m[2] = $m[1]; 
     68            } 
     69            $config->defaultLang = strtolower($m[1]); 
     70            $config->defaultCountry = strtoupper($m[2]); 
     71            $config->defaultLocale = $config->defaultLang.'_'.$config->defaultCountry; 
     72        }else{ 
     73            die("Syntax error in the defaultLocale parameter in Jelix config file $configFile !"); 
     74        }*/ 
    6475#else 
    6576        $config = jIniFile::read(JELIX_LIB_CORE_PATH.'defaultconfig.ini.php'); 
     
    97108            $config['urlengine']['basePath'] = $path; 
    98109        } 
     110 
     111        /*if(preg_match("/^([a-zA-Z]{2})(?:_([a-zA-Z]{2}))?$/",$config['defaultLocale'],$m)){ 
     112            if(!isset($m[2])){ 
     113                $m[2] = $m[1]; 
     114            } 
     115            $config['defaultLang'] = strtolower($m[1]); 
     116            $config['defaultCountry'] = strtoupper($m[2]); 
     117            $config['defaultLocale'] = $config['defaultLang'].'_'.$config['defaultCountry']; 
     118        }else{ 
     119            die("Syntax error in the defaultLocale parameter in Jelix config file $configFile !"); 
     120        }*/ 
    99121#endif 
    100122 
  • trunk/lib/jelix/core/jConfigCompiler.class.php

    r375 r444  
    6262            $config->urlengine['basePath'] = $path; 
    6363        } 
     64 
     65        /*if(preg_match("/^([a-zA-Z]{2})(?:_([a-zA-Z]{2}))?$/",$config->defaultLocale,$m)){ 
     66            if(!isset($m[2])){ 
     67                $m[2] = $m[1]; 
     68            } 
     69            $config->defaultLang = strtolower($m[1]); 
     70            $config->defaultCountry = strtoupper($m[2]); 
     71            $config->defaultLocale = $config->defaultLang.'_'.$config->defaultCountry; 
     72        }else{ 
     73            die("Syntax error in the defaultLocale parameter in Jelix config file $configFile !"); 
     74        }*/ 
    6475#else 
    6576        $config = jIniFile::read(JELIX_LIB_CORE_PATH.'defaultconfig.ini.php'); 
     
    97108            $config['urlengine']['basePath'] = $path; 
    98109        } 
     110 
     111        /*if(preg_match("/^([a-zA-Z]{2})(?:_([a-zA-Z]{2}))?$/",$config['defaultLocale'],$m)){ 
     112            if(!isset($m[2])){ 
     113                $m[2] = $m[1]; 
     114            } 
     115            $config['defaultLang'] = strtolower($m[1]); 
     116            $config['defaultCountry'] = strtoupper($m[2]); 
     117            $config['defaultLocale'] = $config['defaultLang'].'_'.$config['defaultCountry']; 
     118        }else{ 
     119            die("Syntax error in the defaultLocale parameter in Jelix config file $configFile !"); 
     120        }*/ 
    99121#endif 
    100122 
  • trunk/lib/jelix/core/jSelector.class.php

    r431 r444  
    474474        if($isprofil){ 
    475475            $p = jDb::getProfil($driver); 
    476             $this->driver= $p['driver']; 
     476            if($p['driver'] == 'pdo'){ 
     477                $this->driver=substr($p['dsn'],0,strpos($p['dsn'],':')); 
     478            }else{ 
     479                $this->driver= $p['driver']; 
     480            } 
     481            if($this->driver=='pgsql') 
     482                $this->driver='postgresql'; 
    477483        }else{ 
    478484            $this->driver=$driver; 
     
    537543    /** 
    538544     * @param string $sel the template selector 
    539      * @param string $outputtype  the type of output (html, text..) By default, it take the response type 
     545     * @param string $outputtype  the type of output (html, text..) By default, it takes the response type 
    540546     */ 
    541547    function __construct($sel, $outputtype=''){ 
  • trunk/lib/jelix/core/jSelector.class.php

    r431 r444  
    474474        if($isprofil){ 
    475475            $p = jDb::getProfil($driver); 
    476             $this->driver= $p['driver']; 
     476            if($p['driver'] == 'pdo'){ 
     477                $this->driver=substr($p['dsn'],0,strpos($p['dsn'],':')); 
     478            }else{ 
     479                $this->driver= $p['driver']; 
     480            } 
     481            if($this->driver=='pgsql') 
     482                $this->driver='postgresql'; 
    477483        }else{ 
    478484            $this->driver=$driver; 
     
    537543    /** 
    538544     * @param string $sel the template selector 
    539      * @param string $outputtype  the type of output (html, text..) By default, it take the response type 
     545     * @param string $outputtype  the type of output (html, text..) By default, it takes the response type 
    540546     */ 
    541547    function __construct($sel, $outputtype=''){ 
  • trunk/lib/jelix/dao/jDaoCompiler.class.php

    r386 r444  
    5555 
    5656    /** 
    57      * The db driver nam
     57     * The database typ
    5858     * @var string 
    5959     */ 
    60     static public $dbDriver=''; 
     60    static public $dbType=''; 
    6161 
    6262    /** 
     
    6767        jDaoCompiler::$daoId = $selector->toString(); 
    6868        jDaoCompiler::$daoPath = $selector->getPath(); 
    69         jDaoCompiler::$dbDriver = $selector->driver; 
     69        jDaoCompiler::$dbType = $selector->driver; 
    7070 
    7171        // chargement du fichier XML 
  • trunk/lib/jelix/dao/jDaoCompiler.class.php

    r386 r444  
    5555 
    5656    /** 
    57      * The db driver nam
     57     * The database typ
    5858     * @var string 
    5959     */ 
    60     static public $dbDriver=''; 
     60    static public $dbType=''; 
    6161 
    6262    /** 
     
    6767        jDaoCompiler::$daoId = $selector->toString(); 
    6868        jDaoCompiler::$daoPath = $selector->getPath(); 
    69         jDaoCompiler::$dbDriver = $selector->driver; 
     69        jDaoCompiler::$dbType = $selector->driver; 
    7070 
    7171        // chargement du fichier XML 
  • trunk/lib/jelix/dao/jDaoGenerator.class.php

    r404 r444  
    9090      $pkFields          = $this->_getPropertiesBy('PkFields'); 
    9191      $pTableRealName    = $tables[$this->_datasParser->getPrimaryTable()]['realname']; 
    92       $driverName        = jDaoCompiler::$dbDriver
     92      $database          = jDaoCompiler::$dbType
    9393      $pkai              = $this->_getAutoIncrementField(); 
    9494      $sqlPkCondition    = $this->_buildSimpleConditions($pkFields); 
     
    137137         $src[] = '}else{'; 
    138138 
    139          if (($driverName=='mysql') || ($driverName=='sqlserver') || ($driverName=='postgresql')) { 
     139         if (($database=='mysql') || ($database=='sqlserver') || ($database=='postgresql')) { 
    140140            $fields = $this->_getPropertiesBy('PrimaryFieldsExcludeAutoIncrement'); 
    141141         /*}elseif ($pkai->sequenceName != ''){ 
     
    166166      if($pkai !== null){ 
    167167         $src[] = '   if($result){'; 
    168          if ($driverName=='mysql') { 
     168         if ($database=='sqlserver') { 
     169            $src[] = '      if($record->'.$pkai->name.' < 1 ) $record->'.$pkai->name.'= $this->_conn->lastIdInTable(\''.$pkai->fieldName.'\',\''.$pTableRealName.'\');'; 
     170         }else if ($database=='postgresql') { 
     171            $src[] = '      if($record->'.$pkai->name.' < 1  ) $record->'.$pkai->name.'= $this->_conn->lastInsertId(\''.$pkai->sequenceName.'\');'; 
     172         }else{ 
    169173            $src[] = '      if($record->'.$pkai->name.' < 1  ) $record->'.$pkai->name.'= $this->_conn->lastInsertId();'; 
    170          }else if ($driverName=='sqlserver') { 
    171             $src[] = '      if($record->'.$pkai->name.' < 1 ) $record->'.$pkai->name.'= $this->_conn->lastIdInTable(\''.$pkai->fieldName.'\',\''.$pTableRealName.'\');'; 
    172          }else if ($driverName=='postgresql') { 
    173             $src[] = '      if($record->'.$pkai->name.' < 1  ) $record->'.$pkai->name.'= $this->_conn->lastInsertId(\''.$pkai->sequenceName.'\');'; 
    174174         } 
    175175         $src[] = '    return $result;'; 
     
    346346    private function _getFromClause(){ 
    347347 
    348       $driverName = jDaoCompiler::$dbDriver
    349       $aliaslink = ($driverName == 'oci8'?' ':' AS '); 
     348      $database = jDaoCompiler::$dbType
     349      $aliaslink = ($database == 'oci8'?' ':' AS '); 
    350350 
    351351      $sqlWhere = ''; 
     
    367367 
    368368         $fieldjoin=''; 
    369          if ($driverName == 'oci8') { 
     369         if ($database == 'oci8') { 
    370370            if($tablejoin[1] == 0){ 
    371371               $operand='='; $opafter='(+)'; 
     
    416416      $result = array(); 
    417417 
    418       $driverName = jDaoCompiler::$dbDriver
     418      $database = jDaoCompiler::$dbType
    419419 
    420420      $tables = $this->_datasParser->getTables(); 
     
    425425         if ($prop->selectMotif !=''){ 
    426426            if ($prop->selectMotif =='%s'){ 
    427                if ($prop->fieldName != $prop->name || $driverName == 'sqlite'){ 
     427               if ($prop->fieldName != $prop->name || $database == 'sqlite'){ 
    428428                     //in oracle we must escape name 
    429                   if ($driverName == 'oci8') { 
     429                  if ($database == 'oci8') { 
    430430                     $field = $table.$prop->fieldName.' "'.$prop->name.'"'; 
    431431                  }else{ 
     
    437437            }else{ 
    438438               //in oracle we must escape name 
    439                if ($driverName == 'oci8') { 
     439               if ($database == 'oci8') { 
    440440                  $field = sprintf ($prop->selectMotif, $table.$prop->fieldName).' "'.$prop->name.'"'; 
    441441               }else{ 
     
    529529        } 
    530530 
    531         $driverName = jDaoCompiler::$dbDriver
     531        $database = jDaoCompiler::$dbType
    532532        $tb = $this->_datasParser->getTables(); 
    533533        $tb = $tb[$this->_datasParser->getPrimaryTable()]['realname']; 
     
    535535        foreach ($using as $id=>$field) { 
    536536            if ($field->datatype == 'autoincrement' || $field->datatype == 'bigautoincrement') { 
    537                if($driverName=="postgresql" && !strlen($field->sequenceName)){ 
     537               if($database=="postgresql" && !strlen($field->sequenceName)){ 
    538538                  $field->sequenceName = $tb.'_'.$field->name.'_seq'; 
    539539               } 
  • trunk/lib/jelix/dao/jDaoGenerator.class.php

    r404 r444  
    9090      $pkFields          = $this->_getPropertiesBy('PkFields'); 
    9191      $pTableRealName    = $tables[$this->_datasParser->getPrimaryTable()]['realname']; 
    92       $driverName        = jDaoCompiler::$dbDriver
     92      $database          = jDaoCompiler::$dbType
    9393      $pkai              = $this->_getAutoIncrementField(); 
    9494      $sqlPkCondition    = $this->_buildSimpleConditions($pkFields); 
     
    137137         $src[] = '}else{'; 
    138138 
    139          if (($driverName=='mysql') || ($driverName=='sqlserver') || ($driverName=='postgresql')) { 
     139         if (($database=='mysql') || ($database=='sqlserver') || ($database=='postgresql')) { 
    140140            $fields = $this->_getPropertiesBy('PrimaryFieldsExcludeAutoIncrement'); 
    141141         /*}elseif ($pkai->sequenceName != ''){ 
     
    166166      if($pkai !== null){ 
    167167         $src[] = '   if($result){'; 
    168          if ($driverName=='mysql') { 
     168         if ($database=='sqlserver') { 
     169            $src[] = '      if($record->'.$pkai->name.' < 1 ) $record->'.$pkai->name.'= $this->_conn->lastIdInTable(\''.$pkai->fieldName.'\',\''.$pTableRealName.'\');'; 
     170         }else if ($database=='postgresql') { 
     171            $src[] = '      if($record->'.$pkai->name.' < 1  ) $record->'.$pkai->name.'= $this->_conn->lastInsertId(\''.$pkai->sequenceName.'\');'; 
     172         }else{ 
    169173            $src[] = '      if($record->'.$pkai->name.' < 1  ) $record->'.$pkai->name.'= $this->_conn->lastInsertId();'; 
    170          }else if ($driverName=='sqlserver') { 
    171             $src[] = '      if($record->'.$pkai->name.' < 1 ) $record->'.$pkai->name.'= $this->_conn->lastIdInTable(\''.$pkai->fieldName.'\',\''.$pTableRealName.'\');'; 
    172          }else if ($driverName=='postgresql') { 
    173             $src[] = '      if($record->'.$pkai->name.' < 1  ) $record->'.$pkai->name.'= $this->_conn->lastInsertId(\''.$pkai->sequenceName.'\');'; 
    174174         } 
    175175         $src[] = '    return $result;'; 
     
    346346    private function _getFromClause(){ 
    347347 
    348       $driverName = jDaoCompiler::$dbDriver
    349       $aliaslink = ($driverName == 'oci8'?' ':' AS '); 
     348      $database = jDaoCompiler::$dbType
     349      $aliaslink = ($database == 'oci8'?' ':' AS '); 
    350350 
    351351      $sqlWhere = ''; 
     
    367367 
    368368         $fieldjoin=''; 
    369          if ($driverName == 'oci8') { 
     369         if ($database == 'oci8') { 
    370370            if($tablejoin[1] == 0){ 
    371371               $operand='='; $opafter='(+)'; 
     
    416416      $result = array(); 
    417417 
    418       $driverName = jDaoCompiler::$dbDriver
     418      $database = jDaoCompiler::$dbType
    419419 
    420420      $tables = $this->_datasParser->getTables(); 
     
    425425         if ($prop->selectMotif !=''){ 
    426426            if ($prop->selectMotif =='%s'){ 
    427                if ($prop->fieldName != $prop->name || $driverName == 'sqlite'){ 
     427               if ($prop->fieldName != $prop->name || $database == 'sqlite'){ 
    428428                     //in oracle we must escape name 
    429                   if ($driverName == 'oci8') { 
     429                  if ($database == 'oci8') { 
    430430                     $field = $table.$prop->fieldName.' "'.$prop->name.'"'; 
    431431                  }else{ 
     
    437437            }else{ 
    438438               //in oracle we must escape name 
    439                if ($driverName == 'oci8') { 
     439               if ($database == 'oci8') { 
    440440                  $field = sprintf ($prop->selectMotif, $table.$prop->fieldName).' "'.$prop->name.'"'; 
    441441               }else{ 
     
    529529        } 
    530530 
    531         $driverName = jDaoCompiler::$dbDriver
     531        $database = jDaoCompiler::$dbType
    532532        $tb = $this->_datasParser->getTables(); 
    533533        $tb = $tb[$this->_datasParser->getPrimaryTable()]['realname']; 
     
    535535        foreach ($using as $id=>$field) { 
    536536            if ($field->datatype == 'autoincrement' || $field->datatype == 'bigautoincrement') { 
    537                if($driverName=="postgresql" && !strlen($field->sequenceName)){ 
     537               if($database=="postgresql" && !strlen($field->sequenceName)){ 
    538538                  $field->sequenceName = $tb.'_'.$field->name.'_seq'; 
    539539               } 
  • trunk/lib/jelix/dao/jDaoParser.class.php

    r404 r444  
    529529            } 
    530530            if (isset($attr['driver']) && !empty($attr['driver'])) { 
    531                 if (jDaoCompiler::$dbDriver != $attr['driver']) { 
     531                if (jDaoCompiler::$dbType != $attr['driver']) { 
    532532                    throw new jDaoXmlException ('method.condition.driver.notallowed', array($this->name, $op,$field_id)); 
    533533                } 
     
    548548            } 
    549549            if (isset($attr['driver']) && !empty($attr['driver'])) { 
    550                 if (jDaoCompiler::$dbDriver != $attr['driver']) { 
     550                if (jDaoCompiler::$dbType != $attr['driver']) { 
    551551                    throw new jDaoXmlException ('method.condition.driver.notallowed', array($this->name, $op,$field_id)); 
    552552                } 
  • trunk/lib/jelix/dao/jDaoParser.class.php

    r404 r444  
    529529            } 
    530530            if (isset($attr['driver']) && !empty($attr['driver'])) { 
    531                 if (jDaoCompiler::$dbDriver != $attr['driver']) { 
     531                if (jDaoCompiler::$dbType != $attr['driver']) { 
    532532                    throw new jDaoXmlException ('method.condition.driver.notallowed', array($this->name, $op,$field_id)); 
    533533                } 
     
    548548            } 
    549549            if (isset($attr['driver']) && !empty($attr['driver'])) { 
    550                 if (jDaoCompiler::$dbDriver != $attr['driver']) { 
     550                if (jDaoCompiler::$dbType != $attr['driver']) { 
    551551                    throw new jDaoXmlException ('method.condition.driver.notallowed', array($this->name, $op,$field_id)); 
    552552                } 
  • trunk/lib/jelix/db/jDbPDOConnection.class.php

    r386 r444  
    5454        }else{ 
    5555            return parent::fetchAll( JPDO_FETCH_OBJ); 
    56         } 
    57     } 
    58  
    59     /** 
    60      * return next result in the resultset. 
    61      * Arguments are ignored. JDb don't care about it (fetch always as classes or objects) 
    62      * But there are here because of the compatibility of internal methods of PDOStatement 
    63      * @param integer $fetch_style ignored 
    64      * @param integer $cur_or ignored 
    65      * @param integer $cur_offset  ignored 
    66      * @return array an object which contains datas of a row 
    67      */ 
    68     public function fetch( $fetch_style= null, $cur_or=JPDO_FETCH_ORI_NEXT, $cur_offset=0 ){ 
    69         if($this->_fetchMode){ 
    70             return parent::fetch($this->_fetchMode, $cur_or, $cur_offset); 
    71         }else{ 
    72             return parent::fetch(JPDO_FETCH_OBJ,$cur_or,$cur_offset); 
    7356        } 
    7457    } 
     
    140123    } 
    141124 
     125    /** 
     126     * @internal the implementation of Iterator on PDOStatement doesn't call fetch method of classes which inherit of PDOStatement 
     127     * so, we cannot indicate to fetch object directly in jDbPDOResultSet::fetch(). So we overload query() to do it. 
     128     */ 
     129    public function query(){ 
     130        $args=func_get_args(); 
     131        switch(count($args)){ 
     132        case 1: 
     133            $rs = parent::query($args[0]); 
     134            $rs->setFetchMode(JPDO_FETCH_OBJ); 
     135            return $rs; 
     136            break; 
     137        case 2: 
     138            return parent::query($args[0], $args[1]); 
     139            break; 
     140        case 3: 
     141            return parent::query($args[0], $args[1]); 
     142            break; 
     143        default: 
     144            trigger_error('bad argument number in query',E_USER_ERROR); 
     145        } 
     146 
     147    } 
     148 
     149 
    142150    public function limitQuery ($queryString, $limitOffset = null, $limitCount = null){ 
    143151        if ($limitOffset !== null && $limitCount !== null){ 
  • trunk/lib/jelix/db/jDbPDOConnection.class.php

    r386 r444  
    5454        }else{ 
    5555            return parent::fetchAll( JPDO_FETCH_OBJ); 
    56         } 
    57     } 
    58  
    59     /** 
    60      * return next result in the resultset. 
    61      * Arguments are ignored. JDb don't care about it (fetch always as classes or objects) 
    62      * But there are here because of the compatibility of internal methods of PDOStatement 
    63      * @param integer $fetch_style ignored 
    64      * @param integer $cur_or ignored 
    65      * @param integer $cur_offset  ignored 
    66      * @return array an object which contains datas of a row 
    67      */ 
    68     public function fetch( $fetch_style= null, $cur_or=JPDO_FETCH_ORI_NEXT, $cur_offset=0 ){ 
    69         if($this->_fetchMode){ 
    70             return parent::fetch($this->_fetchMode, $cur_or, $cur_offset); 
    71         }else{ 
    72             return parent::fetch(JPDO_FETCH_OBJ,$cur_or,$cur_offset); 
    7356        } 
    7457    } 
     
    140123    } 
    141124 
     125    /** 
     126     * @internal the implementation of Iterator on PDOStatement doesn't call fetch method of classes which inherit of PDOStatement 
     127     * so, we cannot indicate to fetch object directly in jDbPDOResultSet::fetch(). So we overload query() to do it. 
     128     */ 
     129    public function query(){ 
     130        $args=func_get_args(); 
     131        switch(count($args)){ 
     132        case 1: 
     133            $rs = parent::query($args[0]); 
     134            $rs->setFetchMode(JPDO_FETCH_OBJ); 
     135            return $rs; 
     136            break; 
     137        case 2: 
     138            return parent::query($args[0], $args[1]); 
     139            break; 
     140        case 3: 
     141            return parent::query($args[0], $args[1]); 
     142            break; 
     143        default: 
     144            trigger_error('bad argument number in query',E_USER_ERROR); 
     145        } 
     146 
     147    } 
     148 
     149 
    142150    public function limitQuery ($queryString, $limitOffset = null, $limitCount = null){ 
    143151        if ($limitOffset !== null && $limitCount !== null){ 
  • trunk/lib/simpletest/compatibility.php

    r289 r444  
    175175         *    @static 
    176176         */ 
    177         function getStackTrace() { 
     177        static function getStackTrace() { 
    178178            if (function_exists('debug_backtrace')) { 
    179179                return array_reverse(debug_backtrace()); 
  • trunk/lib/simpletest/compatibility.php

    r289 r444  
    175175         *    @static 
    176176         */ 
    177         function getStackTrace() { 
     177        static function getStackTrace() { 
    178178            if (function_exists('debug_backtrace')) { 
    179179                return array_reverse(debug_backtrace()); 
  • trunk/testapp/modules/testapp/install/base.mysql.sql

    r132 r444  
    1212INSERT INTO myconfig VALUES ('engine', 'jelix'); 
    1313INSERT INTO myconfig VALUES ('browser', 'firefox'); 
     14 
     15 
     16CREATE TABLE `product_test` ( 
     17`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , 
     18`name` VARCHAR( 150 ) NOT NULL , 
     19`price` FLOAT NOT NULL 
     20) TYPE = MYISAM ; 
  • trunk/testapp/modules/testapp/install/base.mysql.sql

    r132 r444  
    1212INSERT INTO myconfig VALUES ('engine', 'jelix'); 
    1313INSERT INTO myconfig VALUES ('browser', 'firefox'); 
     14 
     15 
     16CREATE TABLE `product_test` ( 
     17`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , 
     18`name` VARCHAR( 150 ) NOT NULL , 
     19`price` FLOAT NOT NULL 
     20) TYPE = MYISAM ; 
  • trunk/testapp/modules/unittest/classes/junittestcase.class.php

    r399 r444  
    1111 
    1212class jUnitTestCase extends UnitTestCase { 
     13 
     14    // for database management 
     15 
     16    protected $dbProfil =''; 
     17    protected $needPDO = false; 
     18 
     19    function run(&$reporter) { 
     20        SimpleTest::setCurrent($this); 
     21        $this->_reporter = &$reporter; 
     22        $this->_reporter->paintCaseStart($this->getLabel()); 
     23        if($this->needPDO){ 
     24            $this->_reporter->makeDry(!$this->assertTrue(class_exists('PDO',false), 'PDO does not exists ! Test cannot run')); 
     25        } 
     26        foreach ($this->getTests() as $method) { 
     27            if ($this->_reporter->shouldInvoke($this->getLabel(), $method)) { 
     28                $invoker = &$this->_reporter->createInvoker($this->createInvoker()); 
     29                $invoker->before($method); 
     30                $invoker->invoke($method); 
     31                $invoker->after($method); 
     32            } 
     33        } 
     34        $this->_reporter->paintCaseEnd($this->getLabel()); 
     35        unset($this->_reporter); 
     36        return $reporter->getStatus(); 
     37    } 
     38 
    1339 
    1440    /** 
  • trunk/testapp/modules/unittest/classes/junittestcase.class.php

    r399 r444  
    1111 
    1212class jUnitTestCase extends UnitTestCase { 
     13 
     14    // for database management 
     15 
     16    protected $dbProfil =''; 
     17    protected $needPDO = false; 
     18 
     19    function run(&$reporter) { 
     20        SimpleTest::setCurrent($this); 
     21        $this->_reporter = &$reporter; 
     22        $this->_reporter->paintCaseStart($this->getLabel()); 
     23        if($this->needPDO){ 
     24            $this->_reporter->makeDry(!$this->assertTrue(class_exists('PDO',false), 'PDO does not exists ! Test cannot run')); 
     25        } 
     26        foreach ($this->getTests() as $method) { 
     27            if ($this->_reporter->shouldInvoke($this->getLabel(), $method)) { 
     28                $invoker = &$this->_reporter->createInvoker($this->createInvoker()); 
     29                $invoker->before($method); 
     30                $invoker->invoke($method); 
     31                $invoker->after($method); 
     32            } 
     33        } 
     34        $this->_reporter->paintCaseEnd($this->getLabel()); 
     35        unset($this->_reporter); 
     36        return $reporter->getStatus(); 
     37    } 
     38 
    1339 
    1440    /** 
  • trunk/testapp/modules/unittest/classes/junittestcasedb.class.php

    r412 r444  
    1212 
    1313class jUnitTestCaseDb extends jUnitTestCase { 
    14  
    15     // for database management 
    16  
    17     protected $dbProfil =''; 
    1814 
    1915    /** 
     
    8480    } 
    8581 
    86  
     82    /** 
     83     * check if a table has a specific number of records 
     84     */ 
    8785    function assertTableHasNRecords($table, $n, $message="%s"){ 
    8886        $db = jDb::getConnection($this->dbProfil); 
     
    102100        } 
    103101    } 
    104  
    105  
    106102 
    107103    /** 
     
    123119            $results[]=get_object_vars($r); 
    124120         } 
    125         $dumper = new SimpleDumper(); 
     121 
    126122        $globalok=true; 
    127123        $resultsSaved = $results; 
     
    137133            if(!$ok){ 
    138134                $globalok = false; 
    139                 $this->fail($message.'. Not found record : '. var_export($rec,true)); 
     135                $this->fail($message.'. No record found : '. var_export($rec,true)); 
    140136            } 
    141137        } 
  • trunk/testapp/modules/unittest/classes/junittestcasedb.class.php

    r412 r444  
    1212 
    1313class jUnitTestCaseDb extends jUnitTestCase { 
    14  
    15     // for database management 
    16  
    17     protected $dbProfil =''; 
    1814 
    1915    /** 
     
    8480    } 
    8581 
    86  
     82    /** 
     83     * check if a table has a specific number of records 
     84     */ 
    8785    function assertTableHasNRecords($table, $n, $message="%s"){ 
    8886        $db = jDb::getConnection($this->dbProfil); 
     
    102100        } 
    103101    } 
    104  
    105  
    106102 
    107103    /** 
     
    123119            $results[]=get_object_vars($r); 
    124120         } 
    125         $dumper = new SimpleDumper(); 
     121 
    126122        $globalok=true; 
    127123        $resultsSaved = $results; 
     
    137133            if(!$ok){ 
    138134                $globalok = false; 
    139                 $this->fail($message.'. Not found record : '. var_export($rec,true)); 
     135                $this->fail($message.'. No record found : '. var_export($rec,true)); 
    140136            } 
    141137        } 
  • trunk/testapp/modules/unittest/classes/unittestservice.class.php

    r409 r444  
    1212require_once(LIB_PATH.'/simpletest/unit_tester.php'); 
    1313require_once(dirname(__FILE__).'/jhtmlrespreporter.class.php'); 
    14  
    15  
    1614 
    1715class UnitTestService { 
     
    5654 
    5755   function daoParserTest(){ 
    58       $test = jClasses::create("utdao"); 
     56      $test = jClasses::create("utdao_parser"); 
    5957      $test->run(new jHtmlRespReporter($this->_rep)); 
    6058   } 
    6159 
    6260   function daoParser2Test(){ 
    63