+ [misc] Add unit tests for blockZen::printZentaoDynamicBlock() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1144,4 +1144,51 @@ class blockTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test printZentaoDynamicBlock method in zen layer.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function printZentaoDynamicBlockTest()
|
||||
{
|
||||
global $tester;
|
||||
|
||||
include_once dirname(__FILE__, 3) . '/model.php';
|
||||
|
||||
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->config = $tester->app->config;
|
||||
$blockZen->lang = $tester->app->lang;
|
||||
$blockZen->view = new stdclass();
|
||||
|
||||
// 使用反射访问受保护的方法
|
||||
$reflection = new ReflectionClass($blockZen);
|
||||
$method = $reflection->getMethod('printZentaoDynamicBlock');
|
||||
$method->setAccessible(true);
|
||||
|
||||
// 执行方法
|
||||
$method->invoke($blockZen);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 返回设置的view数据
|
||||
$result = new stdclass();
|
||||
$result->dynamics = isset($blockZen->view->dynamics) ? $blockZen->view->dynamics : array();
|
||||
$result->hasInternet = isset($blockZen->session->hasInternet) ? $blockZen->session->hasInternet : null;
|
||||
$result->isSlowNetwork = isset($blockZen->session->isSlowNetwork) ? $blockZen->session->isSlowNetwork : null;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 blockZen::printZentaoDynamicBlock();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 执行$result1->dynamics @1
|
||||
- 执行$result2 @1
|
||||
- 执行$result3->dynamics @1
|
||||
- 执行$result4) && isset($result4->dynamics @1
|
||||
- 执行dynamics) && is_array($result5模块的dynamics方法 @1
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/block.unittest.class.php';
|
||||
|
||||
$blockTest = new blockTest();
|
||||
|
||||
su('admin');
|
||||
|
||||
// 步骤1:测试网络连接状态检查(无网络情况)
|
||||
$_SESSION['hasInternet'] = false;
|
||||
$result1 = $blockTest->printZentaoDynamicBlockTest();
|
||||
r(is_array($result1->dynamics)) && p() && e('1');
|
||||
|
||||
// 步骤2:测试网络连接状态检查(有网络情况)
|
||||
$_SESSION['hasInternet'] = true;
|
||||
$_SESSION['isSlowNetwork'] = null;
|
||||
$result2 = $blockTest->printZentaoDynamicBlockTest();
|
||||
r(is_object($result2)) && p() && e('1');
|
||||
|
||||
// 步骤3:测试网络慢情况
|
||||
$_SESSION['hasInternet'] = true;
|
||||
$_SESSION['isSlowNetwork'] = true;
|
||||
$result3 = $blockTest->printZentaoDynamicBlockTest();
|
||||
r(is_array($result3->dynamics)) && p() && e('1');
|
||||
|
||||
// 步骤4:测试正常网络情况(模拟获取数据)
|
||||
$_SESSION['hasInternet'] = true;
|
||||
$_SESSION['isSlowNetwork'] = false;
|
||||
$result4 = $blockTest->printZentaoDynamicBlockTest();
|
||||
r(is_object($result4) && isset($result4->dynamics)) && p() && e('1');
|
||||
|
||||
// 步骤5:测试方法返回结构完整性
|
||||
$_SESSION['hasInternet'] = true;
|
||||
$result5 = $blockTest->printZentaoDynamicBlockTest();
|
||||
r(isset($result5->dynamics) && is_array($result5->dynamics)) && p() && e('1');
|
||||
Reference in New Issue
Block a user