From f154f10c9e8fedaf1d3000ee7492f77249d1e55a Mon Sep 17 00:00:00 2001 From: Guanxiying Date: Tue, 27 Apr 2021 19:05:12 +0800 Subject: [PATCH] * Add chdir and fix run and expect funtion. --- test/init.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/test/init.php b/test/init.php index 23acb0c613..7fbea75295 100644 --- a/test/init.php +++ b/test/init.php @@ -1,6 +1,6 @@ loadCommon() 方法创建名为 tester 的commonModel对象。 + * 本文件创建一个 app 实例,并且通过执行 $app->loadCommon() 方法创建名为 tester 的commonModel对象。 * This file build a app instance and provide a instance of commonModel named as tester by $app->loadCommon(). * * All request of entries should be routed by this router. @@ -13,13 +13,65 @@ * @link http://www.zentao.net */ /* Set the error reporting. */ -error_reporting(0); +error_reporting(E_ALL & E_STRICT); + +$frameworkRoot = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR; /* Load the framework. */ -include '../framework/router.class.php'; -include '../framework/control.class.php'; -include '../framework/model.class.php'; -include '../framework/helper.class.php'; +include $frameworkRoot . 'router.class.php'; +include $frameworkRoot . 'control.class.php'; +include $frameworkRoot . 'model.class.php'; +include $frameworkRoot . 'helper.class.php'; $app = router::createApp('pms', dirname(dirname(__FILE__)), 'router'); $tester = $app->loadCommon(); + +$config->zendataRoot = dirname(__FILE__) . DS . 'zendata'; +$config->zdPath = "/usr/local/zd/zd"; + +function run($result) +{ + global $_result; + $_result = $result; + return true; +} + +function expect($key, $delimiter = ',') +{ + global $_result; + echo ">> "; + $result = ""; + + if(!is_array($_result) and !is_object($_result)) + { + $result = (string) $_result; + } + else + { + $keyList = explode(',', $key); + $dimension = 1; + foreach($_result as $value) + { + if(is_array($value) or is_object($value)) $dimension = 2; + } + + if($dimension == 1) $_result = array($_result); + foreach($_result as $object) + { + foreach($keyList as $key) $result .= zget($object, $key, '') . $delimiter; + } + $result = trim($result, $delimiter); + } + echo $result . "\n"; + echo "\n"; +} + +function zdImport($table, $yaml, $count = 10) +{ + chdir(dirname(__FILE__)); + global $app, $config; + $dns = "mysql://{$config->db->user}:{$config->db->password}@{$config->db->host}:{$config->db->port}/{$config->db->name}#utf8"; + $table = trim($table, '`'); + $commad = "$config->zdPath -c $yaml -t $table -T -dns $dns --clear -n $count"; + system($commad); +}