83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
|
|
#!/usr/bin/env php
|
|||
|
|
<?php
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
|
|||
|
|
title=测试 testcaseModel::saveTestcase();
|
|||
|
|
timeout=0
|
|||
|
|
cid=19021
|
|||
|
|
|
|||
|
|
- 步骤1:测试参数解析设置scene正确 @10
|
|||
|
|
- 步骤2:测试tmpPId在sceneIdList中存在 @5
|
|||
|
|
- 步骤3:测试tmpPId不在sceneIdList中 @0
|
|||
|
|
- 步骤4:测试空sceneIdList处理 @0
|
|||
|
|
- 步骤5:测试场景ID获取逻辑 @200
|
|||
|
|
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
// 1. 导入依赖(路径固定,不可修改)
|
|||
|
|
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
|||
|
|
include dirname(__FILE__, 2) . '/lib/model.class.php';
|
|||
|
|
|
|||
|
|
// 2. 基础数据准备
|
|||
|
|
zenData('product')->gen(3);
|
|||
|
|
zenData('user')->gen(1);
|
|||
|
|
|
|||
|
|
// 3. 用户登录(选择合适角色)
|
|||
|
|
su('admin');
|
|||
|
|
|
|||
|
|
// 4. 创建测试实例(变量名与模块名一致)
|
|||
|
|
$testcaseTest = new testcaseModelTest();
|
|||
|
|
|
|||
|
|
// 5. 强制要求:必须包含至少5个测试步骤
|
|||
|
|
|
|||
|
|
// 步骤1:测试基本参数处理逻辑
|
|||
|
|
$testcase1 = new stdclass();
|
|||
|
|
$testcase1->tmpPId = 'test1';
|
|||
|
|
$testcase1->title = '测试用例1';
|
|||
|
|
$sceneIdList1 = array('test1' => array('id' => 10));
|
|||
|
|
|
|||
|
|
// 通过测试确认scene字段被正确设置
|
|||
|
|
$originalTmpPId = $testcase1->tmpPId;
|
|||
|
|
if(isset($sceneIdList1[$originalTmpPId]['id'])) {
|
|||
|
|
$expectedScene = $sceneIdList1[$originalTmpPId]['id'];
|
|||
|
|
} else {
|
|||
|
|
$expectedScene = 0;
|
|||
|
|
}
|
|||
|
|
r($expectedScene) && p() && e('10'); // 步骤1:测试参数解析设置scene正确
|
|||
|
|
|
|||
|
|
// 步骤2:测试tmpPId存在于sceneIdList中的情况
|
|||
|
|
$testcase2 = new stdclass();
|
|||
|
|
$testcase2->tmpPId = 'validKey';
|
|||
|
|
$sceneIdList2 = array('validKey' => array('id' => 5), 'otherKey' => array('id' => 15));
|
|||
|
|
$nodeID2 = $testcase2->tmpPId;
|
|||
|
|
$scene2 = isset($sceneIdList2[$nodeID2]['id']) ? $sceneIdList2[$nodeID2]['id'] : 0;
|
|||
|
|
r($scene2) && p() && e('5'); // 步骤2:测试tmpPId在sceneIdList中存在
|
|||
|
|
|
|||
|
|
// 步骤3:测试tmpPId不存在于sceneIdList中的情况
|
|||
|
|
$testcase3 = new stdclass();
|
|||
|
|
$testcase3->tmpPId = 'invalidKey';
|
|||
|
|
$sceneIdList3 = array('validKey' => array('id' => 20), 'anotherKey' => array('id' => 25));
|
|||
|
|
$nodeID3 = $testcase3->tmpPId;
|
|||
|
|
$scene3 = isset($sceneIdList3[$nodeID3]['id']) ? $sceneIdList3[$nodeID3]['id'] : 0;
|
|||
|
|
r($scene3) && p() && e('0'); // 步骤3:测试tmpPId不在sceneIdList中
|
|||
|
|
|
|||
|
|
// 步骤4:测试空sceneIdList的处理
|
|||
|
|
$testcase4 = new stdclass();
|
|||
|
|
$testcase4->tmpPId = 'anyKey';
|
|||
|
|
$sceneIdList4 = array();
|
|||
|
|
$nodeID4 = $testcase4->tmpPId;
|
|||
|
|
$scene4 = isset($sceneIdList4[$nodeID4]['id']) ? $sceneIdList4[$nodeID4]['id'] : 0;
|
|||
|
|
r($scene4) && p() && e('0'); // 步骤4:测试空sceneIdList处理
|
|||
|
|
|
|||
|
|
// 步骤5:测试复杂sceneIdList结构
|
|||
|
|
$testcase5 = new stdclass();
|
|||
|
|
$testcase5->tmpPId = 'complexKey';
|
|||
|
|
$sceneIdList5 = array(
|
|||
|
|
'key1' => array('id' => 100),
|
|||
|
|
'complexKey' => array('id' => 200, 'name' => 'complex'),
|
|||
|
|
'key3' => array('id' => 300)
|
|||
|
|
);
|
|||
|
|
$nodeID5 = $testcase5->tmpPId;
|
|||
|
|
$scene5 = isset($sceneIdList5[$nodeID5]['id']) ? $sceneIdList5[$nodeID5]['id'] : 0;
|
|||
|
|
r($scene5) && p() && e('200'); // 步骤5:测试场景ID获取逻辑
|