From d2ebc185add4a280213f78f3e1ef8e93057fbc64 Mon Sep 17 00:00:00 2001 From: tianshujie Date: Mon, 25 Dec 2023 13:23:04 +0800 Subject: [PATCH] + Add space::getSpacesByAccount unit test. --- .../space/test/model/getspacesbyaccount.php | 27 ++++++++++++++++ module/space/test/space.class.php | 32 +++++++++++++++++++ module/space/test/yaml/space.yaml | 19 +++++++++++ 3 files changed, 78 insertions(+) create mode 100644 module/space/test/model/getspacesbyaccount.php create mode 100644 module/space/test/space.class.php create mode 100644 module/space/test/yaml/space.yaml diff --git a/module/space/test/model/getspacesbyaccount.php b/module/space/test/model/getspacesbyaccount.php new file mode 100644 index 0000000000..0889c61ebc --- /dev/null +++ b/module/space/test/model/getspacesbyaccount.php @@ -0,0 +1,27 @@ +#!/usr/bin/env php +getSpacesByAccount(); +cid=1 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/space.class.php'; + +zdTable('user')->gen(5); +zdTable('space')->config('space')->gen(5); + +$owners = array('', 'admin', 'user1', 'test'); + +$spaceTester = new spaceTest(); +r($spaceTester->getSpacesByAccountTest($owners[0])) && p() && e('0'); // 获取用户名为空的空间列表 +r($spaceTester->getSpacesByAccountTest($owners[1])) && p('0:name,k8space,owner,default') && e('空间1,k8space,admin,0'); // 获取用户名为admin的空间列表 +r($spaceTester->getSpacesByAccountTest($owners[2])) && p('0:name,k8space,owner,default') && e('空间2,k8space,user1,0'); // 获取用户名为user1的空间列表 +r($spaceTester->getSpacesByAccountTest($owners[3])) && p() && e('0'); // 获取用户名为test的空间列表 + +r(count($spaceTester->getSpacesByAccountTest($owners[0]))) && p() && e('0'); // 获取用户名为空的空间数量 +r(count($spaceTester->getSpacesByAccountTest($owners[1]))) && p() && e('1'); // 获取用户名为admin的空间数量 +r(count($spaceTester->getSpacesByAccountTest($owners[2]))) && p() && e('1'); // 获取用户名为user1的空间数量 +r(count($spaceTester->getSpacesByAccountTest($owners[3]))) && p() && e('0'); // 获取用户名为test的空间数量 diff --git a/module/space/test/space.class.php b/module/space/test/space.class.php new file mode 100644 index 0000000000..fc4207e6fa --- /dev/null +++ b/module/space/test/space.class.php @@ -0,0 +1,32 @@ +objectModel = $tester->loadModel('space'); + + $app->rawModule = 'space'; + $app->rawMethod = 'browse'; + $app->setModuleName('space'); + $app->setMethodName('browse'); + } + + /** + * 获取用户的空间列表。 + * Get space list by user account. + * + * @param string $account + * @access public + * @return array + */ + public function getSpacesByAccountTest(string $account): array + { + $spaceList = $this->objectModel->getSpacesByAccount($account); + + if(dao::isError()) return dao::getError(); + return $spaceList; + } +} diff --git a/module/space/test/yaml/space.yaml b/module/space/test/yaml/space.yaml new file mode 100644 index 0000000000..b9565828d5 --- /dev/null +++ b/module/space/test/yaml/space.yaml @@ -0,0 +1,19 @@ +title: zt_space +author: Shujie Tian +version: "1.0" +fields: + - field: id + range: 1-100 + - field: name + range: 1-100 + prefix: 空间 + - field: owner + fields: + - field: account1 + range: admin,user{9} + - field: account2 + range: "[],1-9" + - field: k8space + range: 'k8space' + - field: deleted + range: 0