Merge branch 'sprint/autoTest_liumengyi_product' into 'master'
* Add auto test of product. See merge request easycorp/zentaopms!2563
This commit is contained in:
@@ -1030,4 +1030,70 @@ class productTest
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test change the projects set of the program.
|
||||
*
|
||||
* @param int $productID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function updateProjectsTest($productID)
|
||||
{
|
||||
$singleLinkProjects = array();
|
||||
$multipleLinkProjects = array();
|
||||
|
||||
global $tester;
|
||||
/* Get the projects linked with this product. */
|
||||
$projectPairs = $tester->dao->select('t2.id,t2.name')->from(TABLE_PROJECTPRODUCT)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
|
||||
->where('t1.product')->eq($productID)
|
||||
->andWhere('t2.type')->eq('project')
|
||||
->andWhere('t2.deleted')->eq('0')
|
||||
->fetchPairs();
|
||||
|
||||
$projects = ',';
|
||||
if(!empty($projectPairs))
|
||||
{
|
||||
foreach($projectPairs as $projectID => $projectName)
|
||||
{
|
||||
$projects .= $projectID . ',';
|
||||
$products = $tester->dao->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($projectID)->fetchPairs();
|
||||
if(count($products) == 1)
|
||||
{
|
||||
$singleLinkProjects[$projectID] = $projectName;
|
||||
}
|
||||
|
||||
if(count($products) > 1)
|
||||
{
|
||||
$multipleLinkProjects[$projectID] = $projectName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$_POST['changeProjects'] = $projects;
|
||||
|
||||
$product = $this->objectModel->getById($productID);
|
||||
$_POST['program'] = $product->program == 1 ? 2 : 1;
|
||||
|
||||
$this->objectModel->updateProjects($productID, $singleLinkProjects, $multipleLinkProjects);
|
||||
|
||||
$object = $tester->dao->select('t2.id,t2.parent,t2.path')->from(TABLE_PROJECTPRODUCT)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
|
||||
->where('t1.product')->eq($productID)
|
||||
->andWhere('t2.type')->eq('project')
|
||||
->andWhere('t2.deleted')->eq('0')
|
||||
->fetchAll();
|
||||
|
||||
unset($_POST);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php'; su('admin');
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/product.class.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试productModel->updateProjects();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
$productIDList = array('101', '102', '103', '111', '112');
|
||||
|
||||
$product = new productTest('admin');
|
||||
|
||||
r($product->updateProjectsTest($productIDList[0])) && p('0:id,parent,path') && e('731,1,,1,731,'); // 测试更新产品101的项目信息
|
||||
r($product->updateProjectsTest($productIDList[1])) && p('0:id,parent,path') && e('0'); // 测试更新产品102的项目信息
|
||||
r($product->updateProjectsTest($productIDList[2])) && p('0:id,parent,path') && e('0'); // 测试更新产品103的项目信息
|
||||
r($product->updateProjectsTest($productIDList[3])) && p('0:id,parent,path;1:id,parent,path;2:id,parent,path;3:id,parent,path;4:id,parent,path') && e('733,1,,1,733,;734,1,,1,734,;735,1,,1,735,;736,1,,1,736,;737,1,,1,737,'); // 测试更新产品111的项目信息
|
||||
r($product->updateProjectsTest($productIDList[4])) && p('0:id,parent,path;1:id,parent,path;2:id,parent,path;3:id,parent,path;4:id,parent,path') && e('738,1,,1,738,;739,1,,1,739,;740,1,,1,740,;741,1,,1,741,;742,1,,1,742,'); // 测试更新产品112的项目信息
|
||||
system("./ztest init");
|
||||
Reference in New Issue
Block a user