+ [misc] Add unit tests for blockZen::printProductOverviewBlock() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:09:48 +08:00
co-authored by Claude
parent cca9701949
commit ac039f9c28
2 changed files with 119 additions and 0 deletions
@@ -3444,4 +3444,58 @@ class blockTest
return $result;
}
/**
* Test printProductOverviewBlock method.
*
* @param object $block
* @param array $params
* @access public
* @return object
*/
public function printProductOverviewBlockTest($block, $params = array())
{
global $tester;
$result = new stdclass();
// 创建blockModel的别名为block类
if(!class_exists('block'))
{
class_alias('blockModel', 'block');
}
include_once dirname(__FILE__, 3) . '/zen.php';
$blockZen = new blockZen();
$blockZen->block = $this->objectModel;
// 初始化必要的属性
$blockZen->app = $tester->app;
$blockZen->session = $tester->app->session;
$blockZen->dao = $tester->dao;
$blockZen->view = new stdclass();
$blockZen->config = $tester->config;
// 调用被测试方法 - 需要通过反射调用protected方法
$reflection = new ReflectionClass(get_class($blockZen));
$method = $reflection->getMethod('printProductOverviewBlock');
$method->setAccessible(true);
ob_start();
try {
$method->invoke($blockZen, $block, $params);
$result->success = true;
$result->error = null;
} catch (Exception $e) {
$result->success = false;
$result->error = $e->getMessage();
}
$output = ob_get_clean();
$result->output = $output;
$result->blockWidth = isset($block->width) ? $block->width : 0;
$result->params = $params;
return $result;
}
}
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env php
<?php
/**
title=测试 blockZen::printProductOverviewBlock();
timeout=0
cid=0
- 步骤1:短区块宽度为1
- 属性success @1
- 属性blockWidth @1
- 步骤2:长区块宽度为3
- 属性success @1
- 属性blockWidth @3
- 步骤3:空宽度处理属性success @1
- 步骤4:带年份参数
- 属性success @1
- 属性blockWidth @3
- 步骤5:其他宽度值
- 属性success @1
- 属性blockWidth @2
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/block.unittest.class.php';
// 2. zendata数据准备
$table = zenData('block');
$table->id->range('1-10');
$table->module->range('product');
$table->title->range('产品总览区块{10}');
$table->gen(10);
// 3. 用户登录
su('admin');
// 4. 创建测试实例
$blockTest = new blockTest();
// 5. 创建测试数据对象
$block1 = new stdclass();
$block1->width = 1;
$block2 = new stdclass();
$block2->width = 3;
$block3 = new stdclass();
$block3->width = null;
$block4 = new stdclass();
$block4->width = 3;
$params4 = array('year' => 2023);
$block5 = new stdclass();
$block5->width = 2;
// 6. 必须包含至少5个测试步骤
r($blockTest->printProductOverviewBlockTest($block1)) && p('success,blockWidth') && e('1,1'); // 步骤1:短区块宽度为1
r($blockTest->printProductOverviewBlockTest($block2)) && p('success,blockWidth') && e('1,3'); // 步骤2:长区块宽度为3
r($blockTest->printProductOverviewBlockTest($block3)) && p('success') && e('1'); // 步骤3:空宽度处理
r($blockTest->printProductOverviewBlockTest($block4, $params4)) && p('success,blockWidth') && e('1,3'); // 步骤4:带年份参数
r($blockTest->printProductOverviewBlockTest($block5)) && p('success,blockWidth') && e('1,2'); // 步骤5:其他宽度值