From 947f9fb362d34683d1a94c156ce8a08043f9661e Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 7 Nov 2025 14:09:50 +0800 Subject: [PATCH] + [misc] Add unit tests for blockZen::printBugStatisticBlock() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../block/test/zen/printbugstatisticblock.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 module/block/test/zen/printbugstatisticblock.php diff --git a/module/block/test/zen/printbugstatisticblock.php b/module/block/test/zen/printbugstatisticblock.php new file mode 100755 index 0000000000..301b13bb47 --- /dev/null +++ b/module/block/test/zen/printbugstatisticblock.php @@ -0,0 +1,72 @@ +#!/usr/bin/env php +id->range('1-8'); +$table->name->range('正常产品1,正常产品2,正常产品3,正常产品4,正常产品5,影子产品1,影子产品2,已关闭产品1'); +$table->code->range('product1,product2,product3,product4,product5,shadow1,shadow2,closed1'); +$table->status->range('normal{7},closed{1}'); +$table->shadow->range('0{5},1{2},0{1}'); +$table->deleted->range('0{8}'); +$table->gen(8); + +su('admin'); + +$blockTest = new blockTest(); + +// 测试场景1:正常block对象,传入普通产品ID +$normalBlock = new stdclass(); +$normalBlock->params = new stdclass(); +$normalBlock->params->type = ''; +$normalBlock->params->count = 10; + +// 测试场景2:影子产品测试 +$shadowBlock = new stdclass(); +$shadowBlock->params = new stdclass(); +$shadowBlock->params->type = ''; +$shadowBlock->params->count = 10; +$shadowParams = array('active' => 6); + +// 测试场景3:空block对象 +$emptyBlock = new stdclass(); + +// 测试场景4:count为字符串'0'的block对象 +$stringZeroCountBlock = new stdclass(); +$stringZeroCountBlock->params = new stdclass(); +$stringZeroCountBlock->params->type = ''; +$stringZeroCountBlock->params->count = '0'; + +// 测试场景5:按状态过滤的block对象 +$statusBlock = new stdclass(); +$statusBlock->params = new stdclass(); +$statusBlock->params->type = 'normal'; +$statusBlock->params->count = 10; + +// 步骤1:正常情况测试 - 验证普通产品的Bug总数 +r($blockTest->printBugStatisticBlockTest($normalBlock)) && p('totalBugs') && e('10'); +// 步骤2:影子产品测试 - 验证影子产品的Bug总数 +r($blockTest->printBugStatisticBlockTest($shadowBlock, $shadowParams)) && p('totalBugs') && e('15'); +// 步骤3:空对象测试 - 验证默认选择第一个产品 +r($blockTest->printBugStatisticBlockTest($emptyBlock)) && p('totalBugs') && e('10'); +// 步骤4:count为字符串'0'测试 - 验证count为'0'时Bug总数为0 +r($blockTest->printBugStatisticBlockTest($stringZeroCountBlock)) && p('totalBugs') && e('0'); +// 步骤5:按状态过滤测试 - 验证按normal状态过滤后的Bug总数 +r($blockTest->printBugStatisticBlockTest($statusBlock)) && p('totalBugs') && e('10'); \ No newline at end of file