* finish task 2322.
This commit is contained in:
@@ -840,233 +840,4 @@ class testcase extends control
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Export templet
|
||||
*
|
||||
* @param int $productID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function exportTemplet($productID)
|
||||
{
|
||||
if($_POST)
|
||||
{
|
||||
$fields['module'] = $this->lang->testcase->module;
|
||||
$fields['story'] = $this->lang->testcase->story;
|
||||
$fields['title'] = $this->lang->testcase->title;
|
||||
$fields['stepDesc'] = $this->lang->testcase->stepDesc;
|
||||
$fields['stepExpect'] = $this->lang->testcase->stepExpect;
|
||||
$fields['keywords'] = $this->lang->testcase->keywords;
|
||||
$fields['type'] = $this->lang->testcase->type;
|
||||
$fields['pri'] = $this->lang->testcase->pri;
|
||||
$fields['stage'] = $this->lang->testcase->stage;
|
||||
$fields['precondition'] = $this->lang->testcase->precondition;
|
||||
$this->post->set('fields', $fields);
|
||||
$this->post->set('kind', 'testcase');
|
||||
$this->post->set('rows', array());
|
||||
$this->post->set('extraNum', $this->post->num);
|
||||
$this->post->set('fileName', 'templet');
|
||||
$this->fetch('file', 'export2csv', $_POST);
|
||||
}
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Import csv
|
||||
*
|
||||
* @param int $productID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function import($productID)
|
||||
{
|
||||
if($_FILES)
|
||||
{
|
||||
$file = $this->loadModel('file')->getUpload('file');
|
||||
$file = $file[0];
|
||||
|
||||
$fc = file_get_contents($file['tmpname']);
|
||||
if( $this->post->encode != "utf-8")
|
||||
{
|
||||
if(function_exists('mb_convert_encoding'))
|
||||
{
|
||||
$fc = @mb_convert_encoding($fc, 'utf-8', $this->post->encode);
|
||||
}
|
||||
elseif(function_exists('iconv'))
|
||||
{
|
||||
$fc = @iconv($this->post->encode, 'utf-8', $fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
die(js::alert($this->lang->testcase->noFunction));
|
||||
}
|
||||
}
|
||||
file_put_contents($this->file->savePath . $file['pathname'], $fc);
|
||||
|
||||
$fileName = $this->file->savePath . $file['pathname'];
|
||||
$this->session->set('importFile', $fileName);
|
||||
|
||||
die(js::locate(inlink('showImport', "productID=$productID"), 'parent.parent'));
|
||||
}
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show import data
|
||||
*
|
||||
* @param int $productID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function showImport($productID)
|
||||
{
|
||||
if($_POST)
|
||||
{
|
||||
$this->testcase->createFromImport($productID);
|
||||
die(js::locate(inlink('browse', "productID=$productID"), 'parent'));
|
||||
}
|
||||
|
||||
$this->testcase->setMenu($this->products, $productID);
|
||||
|
||||
$file = $this->session->importFile;
|
||||
$caseLang = $this->lang->testcase;
|
||||
$caseConfig = $this->config->testcase;
|
||||
$fields = explode(',', $caseConfig->exportFields);
|
||||
$modules = $this->loadModel('tree')->getOptionMenu($productID, 'case');
|
||||
$stories = $this->loadModel('story')->getProductStoryPairs($productID);
|
||||
foreach($fields as $key => $fieldName)
|
||||
{
|
||||
$fieldName = trim($fieldName);
|
||||
$fields[$fieldName] = isset($caseLang->$fieldName) ? $caseLang->$fieldName : $fieldName;
|
||||
unset($fields[$key]);
|
||||
}
|
||||
|
||||
$rows = $this->loadModel('file')->parseCSV($file);
|
||||
$header = $rows[0];
|
||||
unset($rows[0]);
|
||||
|
||||
foreach($header as $title)
|
||||
{
|
||||
$field = array_search($title, $fields);
|
||||
if(!$field) continue;
|
||||
$columnKey[] = $field;
|
||||
}
|
||||
if(empty($columnKey))
|
||||
{
|
||||
echo js::alert($this->lang->testcase->errorEncode);
|
||||
die(js::locate(inlink('browse', "productID=$productID")));
|
||||
}
|
||||
|
||||
$endField = $field;
|
||||
$caseData = array();
|
||||
$stepData = array();
|
||||
foreach($rows as $row => $data)
|
||||
{
|
||||
$case = new stdclass();
|
||||
foreach($columnKey as $key => $field)
|
||||
{
|
||||
if(!isset($data[$key])) continue;
|
||||
$cellValue = $data[$key];
|
||||
if($field == 'story')
|
||||
{
|
||||
$case->$field = 0;
|
||||
if(strrpos($cellValue, '(#') !== false)
|
||||
{
|
||||
$id = trim(substr($cellValue, strrpos($cellValue,'(#') + 2), ')');
|
||||
$case->$field = $id;
|
||||
}
|
||||
}
|
||||
elseif($field == 'module')
|
||||
{
|
||||
$case->$field = 0;
|
||||
if(strrpos($cellValue, '(#') !== false)
|
||||
{
|
||||
$id = trim(substr($cellValue, strrpos($cellValue,'(#') + 2), ')');
|
||||
$case->$field = $id;
|
||||
}
|
||||
}
|
||||
elseif(in_array($field, $caseConfig->export->listFields))
|
||||
{
|
||||
if($field == 'stage')
|
||||
{
|
||||
$stages = explode("\n", $cellValue);
|
||||
foreach($stages as $stage) $case->stage[] = array_search($stage, $caseLang->{$field . 'List'});
|
||||
$case->stage = join(',', $case->stage);
|
||||
}
|
||||
else
|
||||
{
|
||||
$case->$field = array_search($cellValue, $caseLang->{$field . 'List'});
|
||||
}
|
||||
}
|
||||
elseif($field != 'stepDesc' and $field != 'stepExpect')
|
||||
{
|
||||
$case->$field = $cellValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
$steps = explode("\n", $cellValue);
|
||||
$stepKey = str_replace('step', '', strtolower($field));
|
||||
$caseStep = array();
|
||||
|
||||
foreach($steps as $step)
|
||||
{
|
||||
$step = trim($step);
|
||||
if(empty($step)) continue;
|
||||
if(preg_match('/^([0-9]+)([.、]{1})/U', $step, $out))
|
||||
{
|
||||
$num = $out[1];
|
||||
$sign = $out[2];
|
||||
$signbit = $sign == '.' ? 1 : 3;
|
||||
$step = trim(substr($step, strpos($step, $sign) + $signbit));
|
||||
if(!empty($step)) $caseStep[$num] = $step;
|
||||
}
|
||||
elseif(isset($num))
|
||||
{
|
||||
$caseStep[$num] .= "\n" . $step;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($field == 'stepDesc')
|
||||
{
|
||||
$num = 1;
|
||||
$caseStep[$num] = $step;
|
||||
}
|
||||
if($field == 'stepExpect' and isset($stepData[$row]['desc']))
|
||||
{
|
||||
end($stepData[$row]['desc']);
|
||||
$num = key($stepData[$row]['desc']);
|
||||
$caseStep[$num] = $step;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($num);
|
||||
unset($sign);
|
||||
$stepData[$row][$stepKey] = $caseStep;
|
||||
}
|
||||
}
|
||||
|
||||
$caseData[$row] = $case;
|
||||
unset($case);
|
||||
}
|
||||
|
||||
if(empty($caseData))
|
||||
{
|
||||
echo js::alert($this->lang->error->noData);
|
||||
die(js::locate($this->createLink('testcase', 'browse')));
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->testcase->common . $this->lang->colon . $this->lang->testcase->showImport;
|
||||
$this->view->position[] = $this->lang->testcase->showImport;
|
||||
|
||||
$this->view->stories = $stories;
|
||||
$this->view->modules = $modules;
|
||||
$this->view->cases = $this->dao->select('id, module, story')->from(TABLE_CASE)->where('product')->eq($productID)->andWhere('deleted')->eq(0)->fetchAll('id');
|
||||
$this->view->caseData = $caseData;
|
||||
$this->view->stepData = $stepData;
|
||||
$this->view->productID = $productID;
|
||||
$this->view->product = $this->products[$productID];
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user