From cef01a4f8501e3a4c88282fcc59e4653437fa457 Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 17 Sep 2025 09:12:58 +0800 Subject: [PATCH] + [misc] Add repoZen buildRepoPaths test class implementation 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 --- .../repozen_buildrepopaths.unittest.class.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 module/repo/test/lib/repozen_buildrepopaths.unittest.class.php diff --git a/module/repo/test/lib/repozen_buildrepopaths.unittest.class.php b/module/repo/test/lib/repozen_buildrepopaths.unittest.class.php new file mode 100644 index 0000000000..bcd0876505 --- /dev/null +++ b/module/repo/test/lib/repozen_buildrepopaths.unittest.class.php @@ -0,0 +1,91 @@ + $path) + { + $paths = explode('/', $path); + $parent = ''; + foreach($paths as $pathSegment) + { + $pathSegment = trim($pathSegment); + if($pathSegment === '') continue; + + $parentID = $parent == '' ? '0' : $pathList[$parent]['path']; + $parent .= $parent == '' ? $pathSegment : '/' . $pathSegment; + if(!isset($pathList[$parent])) + { + $pathList[$parent] = array( + 'value' => $repoID, + 'parent' => $parentID, + 'path' => $parent, + 'text' => $pathSegment, + ); + } + } + } + + ksort($pathList); + $result = $this->buildRepoTreeTest($pathList, '0'); + + if(dao::isError()) return dao::getError(); + + return $result; + } + + /** + * Helper method to build repo tree structure. + * + * @param array $pathList + * @param string $parent + * @access private + * @return array + */ + private function buildRepoTreeTest(array $pathList = array(), string $parent = '0'): array + { + $treeList = array(); + $key = 0; + $pathName = array(); + $repoName = array(); + + foreach($pathList as $path) + { + if ($path['parent'] == $parent) + { + $treeList[$key] = $path; + $repoName[$key] = $path['text']; + /* Default value is '~', because his ascii code is large in string. */ + $pathName[$key] = '~'; + + $children = $this->buildRepoTreeTest($pathList, $path['path']); + + if($children) + { + unset($treeList[$key]['value']); + $treeList[$key]['disabled'] = true; + $treeList[$key]['items'] = $children; + $repoName[$key] = ''; + $pathName[$key] = $path['path']; + } + } + + $key++; + } + + array_multisort($pathName, SORT_ASC, $repoName, SORT_ASC, $treeList); + return $treeList; + } +} \ No newline at end of file