+ [misc] Add unit tests for reportZen::assignAnnualReport() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -23,4 +23,37 @@ class reportZenTest extends baseTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test assignAnnualReport method.
|
||||
*
|
||||
* @param string $year
|
||||
* @param string $dept
|
||||
* @param string $account
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function assignAnnualReportTest(string $year, string $dept, string $account)
|
||||
{
|
||||
// 获取或创建report zen实例
|
||||
$instance = $this->getInstance($this->moduleName, $this->className);
|
||||
|
||||
// 调用方法
|
||||
$this->invokeArgs('assignAnnualReport', [$year, $dept, $account]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 收集view属性用于验证,view应该在instance对象中
|
||||
$result = array();
|
||||
$result['dept'] = isset($instance->view->dept) ? (string)$instance->view->dept : '';
|
||||
$result['year'] = isset($instance->view->year) ? (string)$instance->view->year : '';
|
||||
$result['hasYears'] = isset($instance->view->years) && !empty($instance->view->years) ? 'yes' : 'no';
|
||||
$result['hasMonths'] = isset($instance->view->months) && !empty($instance->view->months) ? 'yes' : 'no';
|
||||
$result['hasContributionGroups'] = isset($instance->view->contributionGroups) && !empty($instance->view->contributionGroups) ? 'yes' : 'no';
|
||||
$result['hasRadarData'] = isset($instance->view->radarData) && is_array($instance->view->radarData) ? 'yes' : 'no';
|
||||
$result['hasMaxCount'] = isset($instance->view->maxCount) && is_numeric($instance->view->maxCount) ? 'yes' : 'no';
|
||||
$result['hasContributionCount'] = isset($instance->view->contributionCount) && is_numeric($instance->view->contributionCount) ? 'yes' : 'no';
|
||||
$result['hasData'] = isset($instance->view->data) && is_array($instance->view->data) ? 'yes' : 'no';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 reportZen::assignAnnualReport();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 测试带有account参数的正常情况,返回year属性year @2025
|
||||
- 测试带有dept参数的正常情况,返回dept属性dept @1
|
||||
- 测试带有year参数的正常情况,返回hasMonths属性hasMonths @yes
|
||||
- 测试空year参数的情况,应返回当前年份属性year @2025
|
||||
- 测试有效account的情况,返回hasData属性hasData @yes
|
||||
- 测试dept为0的边界情况,返回dept属性dept @0
|
||||
- 测试正常情况返回hasYears属性hasYears @yes
|
||||
- 测试正常情况返回hasRadarData属性hasRadarData @yes
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/zen.class.php';
|
||||
|
||||
zenData('user')->gen(20);
|
||||
zenData('dept')->gen(10);
|
||||
zenData('action')->gen(100);
|
||||
zenData('todo')->gen(50);
|
||||
zenData('effort')->gen(50);
|
||||
zenData('story')->gen(30);
|
||||
zenData('task')->gen(40);
|
||||
zenData('bug')->gen(25);
|
||||
zenData('case')->gen(30);
|
||||
zenData('product')->gen(5);
|
||||
zenData('project')->gen(10);
|
||||
|
||||
su('admin');
|
||||
|
||||
$reportTest = new reportZenTest();
|
||||
|
||||
r($reportTest->assignAnnualReportTest('2025', '1', 'admin')) && p('year') && e('2025'); // 测试带有account参数的正常情况,返回year
|
||||
r($reportTest->assignAnnualReportTest('2025', '1', '')) && p('dept') && e('1'); // 测试带有dept参数的正常情况,返回dept
|
||||
r($reportTest->assignAnnualReportTest('2025', '1', '')) && p('hasMonths') && e('yes'); // 测试带有year参数的正常情况,返回hasMonths
|
||||
r($reportTest->assignAnnualReportTest('', '1', '')) && p('year') && e('2025'); // 测试空year参数的情况,应返回当前年份
|
||||
r($reportTest->assignAnnualReportTest('2025', '1', 'admin')) && p('hasData') && e('yes'); // 测试有效account的情况,返回hasData
|
||||
r($reportTest->assignAnnualReportTest('2025', '0', '')) && p('dept') && e('0'); // 测试dept为0的边界情况,返回dept
|
||||
r($reportTest->assignAnnualReportTest('2025', '1', '')) && p('hasYears') && e('yes'); // 测试正常情况返回hasYears
|
||||
r($reportTest->assignAnnualReportTest('2025', '1', '')) && p('hasRadarData') && e('yes'); // 测试正常情况返回hasRadarData
|
||||
Reference in New Issue
Block a user