From 88281eddaa37b86b867cadb3eb039d0c5a94aaa3 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 12 Sep 2025 12:23:40 +0800 Subject: [PATCH] + [misc] Add unit tests for searchTao::checkTestsuitePriv() 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 --- .../search/test/lib/search.unittest.class.php | 22 +++++ module/search/test/tao/checktestsuitepriv.php | 89 +++++++++++++++++++ .../yaml/testsuite_checktestsuitepriv.yaml | 28 ++++++ 3 files changed, 139 insertions(+) create mode 100755 module/search/test/tao/checktestsuitepriv.php create mode 100644 module/search/test/tao/yaml/testsuite_checktestsuitepriv.yaml diff --git a/module/search/test/lib/search.unittest.class.php b/module/search/test/lib/search.unittest.class.php index cfb2caa08f..69244e9100 100755 --- a/module/search/test/lib/search.unittest.class.php +++ b/module/search/test/lib/search.unittest.class.php @@ -999,4 +999,26 @@ class searchTest return count($result); } + + /** + * Test checkTestsuitePriv method. + * + * @param array $results + * @param array $objectIdList + * @param string $table + * @access public + * @return int + */ + public function checkTestsuitePrivTest(array $results, array $objectIdList, string $table): int + { + // 使用反射访问私有方法 + $reflection = new ReflectionClass($this->objectTao); + $method = $reflection->getMethod('checkTestsuitePriv'); + $method->setAccessible(true); + + $result = $method->invokeArgs($this->objectTao, array($results, $objectIdList, $table)); + if(dao::isError()) return -1; + + return count($result); + } } diff --git a/module/search/test/tao/checktestsuitepriv.php b/module/search/test/tao/checktestsuitepriv.php new file mode 100755 index 0000000000..25a45410d8 --- /dev/null +++ b/module/search/test/tao/checktestsuitepriv.php @@ -0,0 +1,89 @@ +#!/usr/bin/env php +id->range('1-10'); +$testsuite->project->range('0'); +$testsuite->product->range('1-3'); +$testsuite->name->range('Test Suite {1-10}'); +$testsuite->desc->range('This is test suite description {1-10}'); +$testsuite->type->range('public{5},private{5}'); +$testsuite->order->range('0'); +$testsuite->addedBy->range('admin{5},user{5}'); +$testsuite->addedDate->range('`2024-01-01`'); +$testsuite->lastEditedBy->range('admin{5},user{5}'); +$testsuite->lastEditedDate->range('`2024-01-01`'); +$testsuite->deleted->range('0'); +$testsuite->gen(10); + +// 3. 用户登录 +su('admin'); + +// 4. 创建测试实例 +$searchTest = new searchTest(); + +// 5. 测试步骤(必须包含至少5个测试步骤) + +// 步骤1:测试正常情况下过滤私有类型测试套件 +$results = array( + 1 => (object)array('id' => 1, 'objectType' => 'testsuite', 'objectID' => 1), + 2 => (object)array('id' => 2, 'objectType' => 'testsuite', 'objectID' => 6), + 3 => (object)array('id' => 3, 'objectType' => 'testsuite', 'objectID' => 7), + 4 => (object)array('id' => 4, 'objectType' => 'testsuite', 'objectID' => 8), + 5 => (object)array('id' => 5, 'objectType' => 'testsuite', 'objectID' => 9), + 6 => (object)array('id' => 6, 'objectType' => 'testsuite', 'objectID' => 10) +); +$objectIdList = array(1 => 1, 6 => 2, 7 => 3, 8 => 4, 9 => 5, 10 => 6); +$table = TABLE_TESTSUITE; +r($searchTest->checkTestsuitePrivTest($results, $objectIdList, $table)) && p() && e(1); // 步骤1:正常情况(私有套件被过滤) + +// 步骤2:测试结果数组为空的情况 +$emptyResults = array(); +$emptyObjectIdList = array(1 => 1, 2 => 2); +r($searchTest->checkTestsuitePrivTest($emptyResults, $emptyObjectIdList, $table)) && p() && e(0); // 步骤2:空结果数组 + +// 步骤3:测试objectIdList为空的情况 +$normalResults = array( + 1 => (object)array('id' => 1, 'objectType' => 'testsuite', 'objectID' => 1), + 2 => (object)array('id' => 2, 'objectType' => 'testsuite', 'objectID' => 2), + 3 => (object)array('id' => 3, 'objectType' => 'testsuite', 'objectID' => 3) +); +$emptyObjectIdList = array(); +r($searchTest->checkTestsuitePrivTest($normalResults, $emptyObjectIdList, $table)) && p() && e(3); // 步骤3:空对象ID列表 + +// 步骤4:测试所有套件都是公开类型的情况 +$publicResults = array( + 1 => (object)array('id' => 1, 'objectType' => 'testsuite', 'objectID' => 1), + 2 => (object)array('id' => 2, 'objectType' => 'testsuite', 'objectID' => 2), + 3 => (object)array('id' => 3, 'objectType' => 'testsuite', 'objectID' => 3) +); +$publicObjectIdList = array(1 => 1, 2 => 2, 3 => 3); +r($searchTest->checkTestsuitePrivTest($publicResults, $publicObjectIdList, $table)) && p() && e(3); // 步骤4:所有公开套件 + +// 步骤5:测试混合类型套件的权限过滤 +$mixedResults = array( + 1 => (object)array('id' => 1, 'objectType' => 'testsuite', 'objectID' => 1), + 2 => (object)array('id' => 2, 'objectType' => 'testsuite', 'objectID' => 6), + 3 => (object)array('id' => 3, 'objectType' => 'testsuite', 'objectID' => 2) +); +$mixedObjectIdList = array(1 => 1, 6 => 2, 2 => 3); +r($searchTest->checkTestsuitePrivTest($mixedResults, $mixedObjectIdList, $table)) && p() && e(2); // 步骤5:混合类型过滤 \ No newline at end of file diff --git a/module/search/test/tao/yaml/testsuite_checktestsuitepriv.yaml b/module/search/test/tao/yaml/testsuite_checktestsuitepriv.yaml new file mode 100644 index 0000000000..962b3b1b17 --- /dev/null +++ b/module/search/test/tao/yaml/testsuite_checktestsuitepriv.yaml @@ -0,0 +1,28 @@ +title: checkTestsuitePriv方法测试套件数据 +desc: 用于测试search模块tao层checkTestsuitePriv方法的测试套件数据 + +fields: +- field: id + range: 1-10 +- field: project + range: '0' +- field: product + range: '1-3' +- field: name + range: 'Test Suite {1-10}' +- field: desc + range: 'This is test suite description {1-10}' +- field: type + range: 'public{5},private{5}' +- field: order + range: '0' +- field: addedBy + range: 'admin{5},user{5}' +- field: addedDate + range: '`2024-01-01`' +- field: lastEditedBy + range: 'admin{5},user{5}' +- field: lastEditedDate + range: '`2024-01-01`' +- field: deleted + range: '0' \ No newline at end of file