conf = new stdClass(); $this->conf->db_name = 'firestats_test'; $this->conf->pass='firestats'; $this->conf->user='firestats'; $this->conf->ver='5.0'; $this->conf->host = 'localhost'; $this->conf->fs_version = '1.6'; // $this->conf->ver='4.0'; // $this->conf->host = '127.0.0.1'; // $this->conf->port = 3311; $this->conf->bin='mysql'; $this->initDb($this->conf); require_once FS_ABS_PATH.'/php/db-sql.php'; } function tearDown() { global $DB_USER; global $DB_PASS; global $DB_NAME; global $MYSQL_BIN; $tables = fs_get_tables_list(); $conf = $this->conf; foreach($tables as $table) { $this->fs_exec("echo 'drop table if exists $table' | $conf->bin -u $conf->user --password=$conf->pass $conf->db_name"); } } function initDb($conf) { global $OVERRIDE_CONFIG; $OVERRIDE_CONFIG = true; global $fs_config; $fs_config['DB_NAME'] = $conf->db_name; $fs_config['DB_PREFIX'] = isset($conf->prefix) ? $conf->prefix : ''; $fs_config['DB_USER'] = $conf->user; $fs_config['DB_PASS'] = $conf->pass; $fs_config['DB_HOST'] = $conf->host; if (isset($conf->port)) { $fs_config['DB_HOST'] .= ":".$conf->port; } require_once '../../php/init.php'; $this->fs_test_dummy_auth(); $this->clear($conf); } function clear($conf) { $ver = $conf->ver; $fs_ver = $conf->fs_version; $pass = $conf->pass; $port = isset($conf->port) ? "--port=$conf->port" : ""; $cmd = "gunzip -c ../firestats-$fs_ver-empty-mysql-$ver.sql.gz | $conf->bin -h $conf->host $port -u $conf->user --password=$pass $conf->db_name"; $this->fs_exec($cmd); } function fs_exec($cmd) { $descriptorspec = array ( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr is a file to write to ); $process = proc_open($cmd, $descriptorspec, $pipes); if (is_resource($process)) { proc_close($process); while(is_resource($pipes[2]) && !feof($pipes[2])) { $str = fgets($pipes[2]); if ($str == false) break; echo $str; } } else { echo "Error opening $cmd"; } } function fs_test_dummy_auth() { $user = new stdClass(); $user->id = 1; $user->dummy = true; $user->name = "Dummy admin"; $user->security_level = SEC_ADMIN; $res = fs_start_user_session($user); if ($res) fs_store_session(); } } ?>