[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/dbal/tests/ -> common.inc.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  class ConnectionTestStub
  11  {
  12    function quoteIdentifier($id)
  13    {
  14      return "'$id'";//let's keep tests clean

  15    }
  16  }
  17  
  18  function loadTestingDbDump($dump_path)
  19  {
  20    if(!file_exists($dump_path))
  21      die('"' . $dump_path . '" sql dump file not found!');
  22  
  23    $tables = array();
  24    $sql_array = file($dump_path);
  25  
  26    $toolkit = lmbToolkit :: instance();
  27    $conn = $toolkit->getDefaultDbConnection();
  28  
  29    foreach($sql_array as $sql)
  30    {
  31      if(!preg_match("|insert\s+?into\s+?([^\s]+)|i", $sql, $matches))
  32        continue;
  33  
  34      if(isset($tables[$matches[1]]))
  35        continue;
  36  
  37      $tables[$matches[1]] = $matches[1];
  38  
  39      $stmt = $conn->newStatement('DELETE FROM '. $matches[1]);
  40      $stmt->execute();
  41    }
  42  
  43    $GLOBALS['testing_db_tables'] = $tables;
  44  
  45    foreach($sql_array as $sql)
  46    {
  47      if(trim($sql))
  48      {
  49        $stmt = $conn->newStatement($sql);
  50        $stmt->execute();
  51      }
  52    }
  53  }
  54  
  55  function clearTestingDbTables()
  56  {
  57    if(!isset($GLOBALS['testing_db_tables']))
  58      return;
  59  
  60    $toolkit = lmbToolkit :: instance();
  61    $conn = $toolkit->getDefaultDbConnection();
  62  
  63    foreach($GLOBALS['testing_db_tables'] as $table)
  64    {
  65      $stmt = $conn->newStatement('DELETE FROM '. $table);
  66      $stmt->execute();
  67    }
  68  
  69    $GLOBALS['testing_db_tables'] = array();
  70  }
  71  
  72  function parseTestingCriteria($criteria)
  73  {
  74    $str = '';
  75    $criteria->appendStatementTo($str, $values);
  76    if($values)
  77      return strtr($str, $values);
  78    else
  79      return $str;
  80  }
  81  ?>


Generated: Fri Aug 29 04:49:26 2008 Cross-referenced by PHPXref 0.7