diff --git a/module/convert/test/lib/convert.unittest.class.php b/module/convert/test/lib/convert.unittest.class.php index f92a2d4cc1..1091cef5c6 100644 --- a/module/convert/test/lib/convert.unittest.class.php +++ b/module/convert/test/lib/convert.unittest.class.php @@ -155,4 +155,44 @@ class convertTest return $result; } + + /** + * Test splitFile method. + * + * @access public + * @return mixed + */ + public function splitFileTest() + { + try { + // 检查源文件是否存在 + global $app; + $jiraPath = $app->getTmpRoot() . 'jirafile/'; + $sourceFile = $jiraPath . 'entities.xml'; + + if(!file_exists($sourceFile)) + { + return 'no_source_file'; + } + + $this->objectModel->splitFile(); + if(dao::isError()) return dao::getError(); + + // 检查是否成功分割文件 + $checkFiles = array('action.xml', 'project.xml', 'issue.xml'); + $existFiles = 0; + foreach($checkFiles as $file) + { + if(file_exists($jiraPath . $file)) $existFiles++; + } + + return $existFiles > 0 ? 'success' : 'no_files'; + } catch (Exception $e) { + return 'exception: ' . $e->getMessage(); + } catch (TypeError $e) { + return 'type_error: ' . $e->getMessage(); + } catch (Error $e) { + return 'error: ' . $e->getMessage(); + } + } } \ No newline at end of file diff --git a/module/convert/test/model/splitfile.php b/module/convert/test/model/splitfile.php new file mode 100755 index 0000000000..548e250496 --- /dev/null +++ b/module/convert/test/model/splitfile.php @@ -0,0 +1,101 @@ +#!/usr/bin/env php +getTmpRoot() . 'jirafile/'; +if(!is_dir($jiraPath)) mkdir($jiraPath, 0755, true); + +// 清理之前的测试文件 +$testFiles = array('action.xml', 'project.xml', 'status.xml', 'resolution.xml', 'user.xml', 'issue.xml', 'changegroup.xml', 'changeitem.xml', 'issuelink.xml', 'issuelinktype.xml', 'fileattachment.xml', 'version.xml', 'issuetype.xml', 'nodeassociation.xml'); +foreach($testFiles as $file) +{ + if(file_exists($jiraPath . $file)) @unlink($jiraPath . $file); +} + +// 创建测试用的entities.xml文件 +$testXMLContent = ' + + + + + + + + + + + + + + + + + + + + +'; + +file_put_contents($jiraPath . 'entities.xml', $testXMLContent); + +// 测试步骤1:测试有效的entities.xml文件分割 +r($convertTest->splitFileTest()) && p() && e('success'); + +// 测试步骤2:测试空的entities.xml文件处理 +foreach($testFiles as $file) +{ + if(file_exists($jiraPath . $file)) @unlink($jiraPath . $file); +} +file_put_contents($jiraPath . 'entities.xml', ''); +r($convertTest->splitFileTest()) && p() && e('no_files'); + +// 测试步骤3:测试不存在entities.xml文件的处理 +if(file_exists($jiraPath . 'entities.xml')) @unlink($jiraPath . 'entities.xml'); +r($convertTest->splitFileTest()) && p() && e('no_source_file'); + +// 测试步骤4:测试包含特殊字符的XML内容处理 +foreach($testFiles as $file) +{ + if(file_exists($jiraPath . $file)) @unlink($jiraPath . $file); +} +$xmlWithSpecialChars = ' + + + +'; +file_put_contents($jiraPath . 'entities.xml', $xmlWithSpecialChars); +r($convertTest->splitFileTest()) && p() && e('success'); + +// 测试步骤5:检查分割后的文件完整性 +$actionFile = $jiraPath . 'action.xml'; +$hasValidXMLHeader = false; +$hasValidXMLFooter = false; +if(file_exists($actionFile)) +{ + $content = file_get_contents($actionFile); + $hasValidXMLHeader = strpos($content, "") !== false; + $hasValidXMLFooter = strpos($content, '') !== false; +} +r($hasValidXMLHeader && $hasValidXMLFooter) && p() && e('1'); \ No newline at end of file