From fae8de8d3ca57057dbb3e1c95a990a8178bd33c9 Mon Sep 17 00:00:00 2001 From: tianshujie Date: Fri, 1 Dec 2023 17:24:54 +0800 Subject: [PATCH] + Add doc::getActionByObject unit test. --- module/doc/test/doc.class.php | 18 +++++++++++++ module/doc/test/model/getactionbyobject.php | 28 +++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 module/doc/test/model/getactionbyobject.php diff --git a/module/doc/test/doc.class.php b/module/doc/test/doc.class.php index 415ee02dbd..c71a1030d9 100644 --- a/module/doc/test/doc.class.php +++ b/module/doc/test/doc.class.php @@ -925,4 +925,22 @@ class docTest if(dao::isError()) return dao::getError(); return $this->objectModel->dao->select('deleted')->from(TABLE_FILE)->where('id')->in($idList)->fetchPairs(); } + + /** + * 获取文档的所有操作信息。 + * Get action by doc ID. + * + * @param int $docID + * @param string $action view|collect + * @param string $account + * @access public + * @return array|object|false + */ + public function getActionByObjectTest(int $docID, string $action, string $account = ''): array|object|bool + { + $actions = $this->objectModel->getActionByObject($docID, $action, $account); + + if(dao::isError()) return dao::getError(); + return $actions; + } } diff --git a/module/doc/test/model/getactionbyobject.php b/module/doc/test/model/getactionbyobject.php new file mode 100644 index 0000000000..f906b5ad94 --- /dev/null +++ b/module/doc/test/model/getactionbyobject.php @@ -0,0 +1,28 @@ +#!/usr/bin/env php +getActionByObject(); +timeout=0 +cid=1 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/doc.class.php'; + +zdTable('docaction')->config('docaction')->gen(20); +zdTable('user')->gen(5); +su('admin'); + +$docs = array(0, 1); +$actions = array('', 'collect', 'view'); +$accounts = array('', 'user1'); + +$docTester = new docTest(); +r($docTester->getActionByObjectTest($docs[0], $actions[0], $accounts[0])) && p() && e('0'); // 测试空数据 +r($docTester->getActionByObjectTest($docs[1], $actions[0], $accounts[0])) && p() && e('0'); // 测试查询docID=1的数据 +r($docTester->getActionByObjectTest($docs[1], $actions[1], $accounts[0])) && p('doc,action') && e('1,collect'); // 测试查询docID=1, action=collect的数据 +r($docTester->getActionByObjectTest($docs[1], $actions[2], $accounts[0])) && p('doc,action') && e('0'); // 测试查询docID=1, action=view的数据 +r($docTester->getActionByObjectTest($docs[1], $actions[1], $accounts[1])) && p('doc,action') && e('0'); // 测试查询docID=1, action=collect, account=user1的数据 +r($docTester->getActionByObjectTest($docs[1], $actions[2], $accounts[1])) && p() && e('0'); // 测试查询docID=1, action=view, account=user1的数据