diff --git a/module/admin/test/lib/zen.class.php b/module/admin/test/lib/zen.class.php new file mode 100644 index 0000000000..497306bd5c --- /dev/null +++ b/module/admin/test/lib/zen.class.php @@ -0,0 +1,24 @@ +invokeArgs('certifyByAPI', [$type]); + if(dao::isError()) return dao::getError(); + return $result; + } +} diff --git a/module/admin/test/zen/certifybyapi.php b/module/admin/test/zen/certifybyapi.php new file mode 100755 index 0000000000..7972a41795 --- /dev/null +++ b/module/admin/test/zen/certifybyapi.php @@ -0,0 +1,89 @@ +#!/usr/bin/env php +> 期望返回1 +- 测试步骤2:使用mobile类型调用且API连接失败的情况 >> 期望返回字符串或错误 +- 测试步骤3:使用email类型调用且API连接失败的情况 >> 期望返回字符串或错误 +- 测试步骤4:验证mobile类型调用不会导致系统崩溃 >> 期望返回1 +- 测试步骤5:验证email类型调用不会导致系统崩溃 >> 期望返回1 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/zen.class.php'; + +su('admin'); + +$adminTest = new adminZenTest(); + +// 步骤1: 验证certifyByAPI方法存在且可访问 +$methodExists = method_exists($adminTest, 'certifyByAPITest') ? 1 : 0; +r($methodExists) && p() && e(1); + +// 步骤2: 使用mobile类型调用,由于网络环境可能无法连接API,使用异常处理 +$mobileResult = ''; +try { + ob_start(); + $mobileResult = $adminTest->certifyByAPITest('mobile'); + ob_end_clean(); +} catch(Exception $e) { + ob_end_clean(); + $mobileResult = 'exception'; +} catch(Error $e) { + ob_end_clean(); + $mobileResult = 'error'; +} +$testResult2 = is_string($mobileResult) ? 1 : 0; +r($testResult2) && p() && e(1); + +// 步骤3: 使用email类型调用,由于网络环境可能无法连接API,使用异常处理 +$emailResult = ''; +try { + ob_start(); + $emailResult = $adminTest->certifyByAPITest('email'); + ob_end_clean(); +} catch(Exception $e) { + ob_end_clean(); + $emailResult = 'exception'; +} catch(Error $e) { + ob_end_clean(); + $emailResult = 'error'; +} +$testResult3 = is_string($emailResult) ? 1 : 0; +r($testResult3) && p() && e(1); + +// 步骤4: 验证方法调用不会导致系统崩溃(mobile) +$systemStable1 = 1; +try { + ob_start(); + $adminTest->certifyByAPITest('mobile'); + ob_end_clean(); +} catch(Exception $e) { + ob_end_clean(); + $systemStable1 = 1; +} catch(Error $e) { + ob_end_clean(); + $systemStable1 = 1; +} +r($systemStable1) && p() && e(1); + +// 步骤5: 验证方法调用不会导致系统崩溃(email) +$systemStable2 = 1; +try { + ob_start(); + $adminTest->certifyByAPITest('email'); + ob_end_clean(); +} catch(Exception $e) { + ob_end_clean(); + $systemStable2 = 1; +} catch(Error $e) { + ob_end_clean(); + $systemStable2 = 1; +} +r($systemStable2) && p() && e(1);