pub / serci

Search the web with !keywords
git clone https://https://src.jayvii.de/pub/serci.git
Home | Log | Files | Exports | Refs | README | RSS

commit 831cbe5a9fefc2aad2d30883baebc3058c262ef6
parent cc3acd2408315ddafe31a3236e4dfa13bc78d6dd
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Fri, 18 Oct 2024 13:17:27 +0200

feat: add and document tests

Diffstat:
MREADME.md | 16++++++++++++++++
Atests/keywords.php | 28++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -106,6 +106,22 @@ Example-configuration for Apache2: </VirtualHost> ``` +## Testing + +There are test scripts in place to test the validity of your configuration. +Tests may be conducted to check: + +1. Whether all categories assigned to search engines are defined themselves +2. Whether all defined categories have at least one search engine assigned to + them +3. Whether all keywords are unique, i.e. no keyword is assigned to multiple + search engines + +```bash +php tests/categories.php +php tests/keywords.php +``` + ## License serĉi is under the AGPL-3.0 license. It is [REUSE](https://reuse.software) diff --git a/tests/keywords.php b/tests/keywords.php @@ -0,0 +1,28 @@ +<?php + +include("./config/config.php"); + +/* Find duplicate keywords -------------------------------------------------- */ + +$searchkeys = array(); + +foreach (array_keys($searches) as $sid) { + foreach ($searches[$sid]["keywords"] as $keyword) { + if (array_key_exists($keyword, $searchkeys)) { + array_push($searchkeys[$keyword], $sid); + } else { + $searchkeys[$keyword] = array($sid); + } + + $assignments = count($searchkeys[$keyword]); + if ($assignments > 1) { + echo "[WARN] Keyword \"" . $keyword . "\" assigned multiple times:"; + for ($i = 0; $i < $assignments; $i++) { + echo " " . ($i + 1) . ". " . $searchkeys[$keyword][$i]; + } + echo PHP_EOL; + } + } +} + +?>