From cf253d2eb42f76ea73ceb5d25bfce2856e802afd Mon Sep 17 00:00:00 2001 From: liugang Date: Thu, 6 Nov 2025 13:40:41 +0800 Subject: [PATCH] + [misc] Add unit tests for convertTao::createWorkflowField() 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 --- .../test/lib/convert.unittest.class.php | 11 +- .../convert/test/tao/createworkflowfield.php | 112 ++++++++++++++++++ 2 files changed, 121 insertions(+), 2 deletions(-) create mode 100755 module/convert/test/tao/createworkflowfield.php diff --git a/module/convert/test/lib/convert.unittest.class.php b/module/convert/test/lib/convert.unittest.class.php index b7da8bd758..7caafcbc26 100755 --- a/module/convert/test/lib/convert.unittest.class.php +++ b/module/convert/test/lib/convert.unittest.class.php @@ -3910,15 +3910,22 @@ class convertTest */ public function createWorkflowFieldTest($relations = array(), $fields = array(), $fieldOptions = array(), $jiraResolutions = array(), $jiraPriList = array()) { + global $tester; + + if(!isset($this->objectTao->workflowfield)) + { + $this->objectTao->workflowfield = $this->createMockWorkflowField(); + } + $reflection = new ReflectionClass($this->objectTao); $method = $reflection->getMethod('createWorkflowField'); $method->setAccessible(true); - + try { $result = $method->invokeArgs($this->objectTao, array($relations, $fields, $fieldOptions, $jiraResolutions, $jiraPriList)); if(dao::isError()) return dao::getError(); - + return $result; } catch(Exception $e) diff --git a/module/convert/test/tao/createworkflowfield.php b/module/convert/test/tao/createworkflowfield.php new file mode 100755 index 0000000000..549f083f4c --- /dev/null +++ b/module/convert/test/tao/createworkflowfield.php @@ -0,0 +1,112 @@ +#!/usr/bin/env php +dbh->exec($sql); + $tester->dbh->exec('TRUNCATE TABLE jiratmprelation'); +} catch (Exception $e) { + // 忽略表创建错误 +} + +zenData('workflowfield')->gen(0); +zenData('workflow')->gen(0); + +// 设置必要的配置 +if(!isset($config->workflowfield)) $config->workflowfield = new stdclass(); +if(!isset($config->workflowfield->numberTypes)) $config->workflowfield->numberTypes = array('int', 'decimal', 'float'); + +su('admin'); + +$convertTest = new convertTest(); + +// 测试步骤1: 开源版直接返回relations +$originalEdition = $config->edition; +$config->edition = 'open'; +$relations1 = array('zentaoObject' => array('Story' => 'story'), 'zentaoFieldStory' => array()); +r($convertTest->createWorkflowFieldTest($relations1, array(), array(), array(), array())) && p('zentaoObject:Story') && e('story'); + +// 测试步骤2: 企业版无自定义字段的情况 +$config->edition = 'biz'; +$relations2 = array('zentaoObject' => array('Story' => 'story')); +r($convertTest->createWorkflowFieldTest($relations2, array(), array(), array(), array())) && p('zentaoObject:Story') && e('story'); + +// 测试步骤3: 正常创建工作流字段 +$relations3 = array( + 'zentaoObject' => array('Story' => 'story'), + 'zentaoFieldStory' => array('customfield_10001' => 'add_field') +); +$fields3 = array( + 'customfield_10001' => (object)array( + 'cfname' => 'Test Custom Field', + 'customfieldtypekey' => 'com.atlassian.jira.plugin.system.customfieldtypes:textfield' + ) +); +$result3 = $convertTest->createWorkflowFieldTest($relations3, $fields3, array(), array(), array()); +r(isset($result3['zentaoFieldStory']['customfield_10001']) && strpos($result3['zentaoFieldStory']['customfield_10001'], 'jirafield') === 0 ? 1 : 0) && p() && e('1'); + +// 测试步骤4: 字段已存在时重用 +$tester->dbh->exec("INSERT INTO jiratmprelation (AType, AID, BType, BID, extra) VALUES ('jcustomfield', 'customfield_10002', 'zworkflowfield', 'existingfield001', 'story')"); +$relations4 = array( + 'zentaoObject' => array('Story' => 'story'), + 'zentaoFieldStory' => array('customfield_10002' => 'add_field') +); +$fields4 = array( + 'customfield_10002' => (object)array( + 'cfname' => 'Existing Field', + 'customfieldtypekey' => 'com.atlassian.jira.plugin.system.customfieldtypes:textfield' + ) +); +r($convertTest->createWorkflowFieldTest($relations4, $fields4, array(), array(), array())) && p('zentaoFieldStory:customfield_10002') && e('existingfield001'); + +// 测试步骤5: 包含选项的自定义字段 +$relations5 = array( + 'zentaoObject' => array('Bug' => 'bug'), + 'zentaoFieldBug' => array('customfield_10003' => 'add_field') +); +$fields5 = array( + 'customfield_10003' => (object)array( + 'cfname' => 'Select Field', + 'customfieldtypekey' => 'com.atlassian.jira.plugin.system.customfieldtypes:select' + ) +); +$fieldOptions5 = array( + '1001' => (object)array('customfield' => 'customfield_10003', 'customvalue' => 'Option 1'), + '1002' => (object)array('customfield' => 'customfield_10003', 'customvalue' => 'Option 2') +); +$result5 = $convertTest->createWorkflowFieldTest($relations5, $fields5, $fieldOptions5, array(), array()); +r(isset($result5['zentaoFieldBug']['customfield_10003']) && strpos($result5['zentaoFieldBug']['customfield_10003'], 'jirafield') === 0 ? 1 : 0) && p() && e('1'); + +$config->edition = $originalEdition; \ No newline at end of file