diff --git a/module/search/test/search.class.php b/module/search/test/search.class.php index bd14163add..f271109890 100644 --- a/module/search/test/search.class.php +++ b/module/search/test/search.class.php @@ -520,4 +520,17 @@ class searchTest { return $this->objectModel->setCondition($field, $operator, $value); } + + /** + * 测试设置搜索条件。 + * Set where test. + * + * @access public + * @return string + */ + public function setWhereTest(string $field, string $operator, string $value, string $andOr): string + { + $where = ''; + return $this->objectModel->setWhere($where, $field, $operator, $value, $andOr); + } } diff --git a/module/search/test/tao/setwhere.php b/module/search/test/tao/setwhere.php new file mode 100755 index 0000000000..f87f3fc5b4 --- /dev/null +++ b/module/search/test/tao/setwhere.php @@ -0,0 +1,32 @@ +#!/usr/bin/env php +setCondition(); +timeout=0 +cid=0 + +- 测试 module 包含 id 为 1 的条件 @ and (`createdDate` >= '2023-12-08' AND `createdDate` <= '2023-12-08 23:59:59') +- 测试 module 包含 id 为 1 的条件 @ and (`createdDate` < '2023-12-08' OR `createdDate` > '2023-12-08 23:59:59') +- 测试 module 包含 id 为 1 的条件 @ and `createdDate` <= '2023-12-08 23:59:59' +- 测试 module 包含 id 为 1 的条件 @ and `createdDate` > '2023-12-08 23:59:59' + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/search.class.php'; + +su('admin'); + +$fields = array('createdDate', 'title'); +$operators = array('=', '!=', '<=', '>', 'include'); +$values = array('2023-12-08', 'test'); +$andOrs = array('and', 'or'); + +$search = new searchTest(); +r($search->setWhereTest($fields[0], $operators[0], $values[0], $andOrs[0])) && p() && e(" and (`createdDate` >= '2023-12-08' AND `createdDate` <= '2023-12-08 23:59:59')"); //测试等于某天的条件 +r($search->setWhereTest($fields[0], $operators[1], $values[0], $andOrs[1])) && p() && e(" or (`createdDate` < '2023-12-08' OR `createdDate` > '2023-12-08 23:59:59')"); //测试不等于某天的条件 +r($search->setWhereTest($fields[0], $operators[2], $values[0], $andOrs[0])) && p() && e(" and `createdDate` <= '2023-12-08 23:59:59'"); //测试小于等于某天的条件 +r($search->setWhereTest($fields[0], $operators[3], $values[0], $andOrs[1])) && p() && e(" or `createdDate` > '2023-12-08 23:59:59'"); //测试大于某天的条件 +r($search->setWhereTest($fields[1], $operators[4], $values[1], $andOrs[0])) && p() && e(" and `title` LIKE '%test%'"); //测试其他