Compare commits
166 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f90bd193d9 | ||
|
|
0e31180868 | ||
|
|
68c9164eaa | ||
|
|
c2389db1c9 | ||
|
|
f9558cd3aa | ||
|
|
ae3011fe22 | ||
|
|
9b9dfeac69 | ||
|
|
33cb05a002 | ||
|
|
ec110499a8 | ||
|
|
09839f3451 | ||
|
|
067e0aed5d | ||
|
|
545de5c4a1 | ||
|
|
2fe37bf92a | ||
|
|
cd81d15d9a | ||
|
|
8a33ee5c15 | ||
|
|
46e1419ef5 | ||
|
|
c441063437 | ||
|
|
5290d5f351 | ||
|
|
2635ccb82b | ||
|
|
4f2ac2ed1b | ||
|
|
5b8e4e4e3e | ||
|
|
53192da571 | ||
|
|
f29e915068 | ||
|
|
46bc5f2da6 | ||
|
|
d70182a84e | ||
|
|
7243f69826 | ||
|
|
1fc144e178 | ||
|
|
c383a7b7b7 | ||
|
|
69077c384c | ||
|
|
cfd49947ad | ||
|
|
6985dc4e9d | ||
|
|
5f2668b011 | ||
|
|
eba1ef9c59 | ||
|
|
8497144053 | ||
|
|
2006798388 | ||
|
|
bf63d850ca | ||
|
|
53e267ce24 | ||
|
|
1754ecf2ee | ||
|
|
3c37899a48 | ||
|
|
0436cfe3da | ||
|
|
3606de1a00 | ||
|
|
3081439eda | ||
|
|
7af0e74b85 | ||
|
|
7748b83a6b | ||
|
|
f83293ff1a | ||
|
|
9c3be2942e | ||
|
|
ee62bd98ee | ||
|
|
02e9610fad | ||
|
|
8a41db4649 | ||
|
|
e27ea3dc9f | ||
|
|
ec4bf54d81 | ||
|
|
ec3ca787fa | ||
|
|
86acbbb85b | ||
|
|
8e0af7a5f7 | ||
|
|
b022662dfc | ||
|
|
3039ebf913 | ||
|
|
e2e080c404 | ||
|
|
4671143d1c | ||
|
|
b492558cca | ||
|
|
64e76530d4 | ||
|
|
0b93f9f146 | ||
|
|
4c6fe1cd6c | ||
|
|
83ba48f598 | ||
|
|
62c6de8244 | ||
|
|
1c2f9f0c2c | ||
|
|
30bb0e8895 | ||
|
|
75c4c98de8 | ||
|
|
f72055909b | ||
|
|
b0a8783276 | ||
|
|
7b5ad92e66 | ||
|
|
250067927a | ||
|
|
7c2cbbaca7 | ||
|
|
ac037eabde | ||
|
|
0250b86b3f | ||
|
|
e45acc412b | ||
|
|
854206bc70 | ||
|
|
b192e98a8a | ||
|
|
c4e2c781c6 | ||
|
|
e80b3b8dfd | ||
|
|
2b079ff836 | ||
|
|
37201799b5 | ||
|
|
b9d8911c7b | ||
|
|
c51ceb926e | ||
|
|
b4b33d6873 | ||
|
|
959240b0fa | ||
|
|
7eace1013e | ||
|
|
be1e55cad7 | ||
|
|
11a8c6440b | ||
|
|
742cbc31df | ||
|
|
28909fdc03 | ||
|
|
c3b29ad0d7 | ||
|
|
6d481657df | ||
|
|
fc57aabf5d | ||
|
|
d56ee68482 | ||
|
|
b89ab09e12 | ||
|
|
e873ade6c0 | ||
|
|
5910b884ac | ||
|
|
e3bd2c1c3b | ||
|
|
90a8c5540f | ||
|
|
ea503fffe9 | ||
|
|
feba79a2e8 | ||
|
|
6bec59e387 | ||
|
|
03fbcaecfb | ||
|
|
283e7de1dc | ||
|
|
d952c5f774 | ||
|
|
cd8351d761 | ||
|
|
b992901072 | ||
|
|
1596654149 | ||
|
|
44f37b7f74 | ||
|
|
829f5c567f | ||
|
|
710a48abcd | ||
|
|
f564c27319 | ||
|
|
00b98e7230 | ||
|
|
7cae3e701a | ||
|
|
da67d1bde3 | ||
|
|
16c3653cee | ||
|
|
47c4c5cb69 | ||
|
|
7b9dc9c8b2 | ||
|
|
6133da9069 | ||
|
|
fa0b102d1a | ||
|
|
0e99700bbe | ||
|
|
2f0b9fb360 | ||
|
|
c7cc3c2938 | ||
|
|
f508b607a6 | ||
|
|
f94b350ba4 | ||
|
|
53eef03387 | ||
|
|
5a81445a28 | ||
|
|
4bbbd653cd | ||
|
|
4c28e6d0ec | ||
|
|
66b7e81463 | ||
|
|
cf58f86802 | ||
|
|
ff644310cd | ||
|
|
58988b9c0f | ||
|
|
fe75f1d724 | ||
|
|
0607cdc3be | ||
|
|
6cb14daf49 | ||
|
|
330582f273 | ||
|
|
b0293b52bd | ||
|
|
00591deb00 | ||
|
|
737f70fac5 | ||
|
|
0328ccd2fe | ||
|
|
eba1e2885f | ||
|
|
53813261fb | ||
|
|
df2ae66942 | ||
|
|
78e1d73cd9 | ||
|
|
620a5878c1 | ||
|
|
5a0b09a916 | ||
|
|
98c6033c75 | ||
|
|
6dcebc9b67 | ||
|
|
c97520e186 | ||
|
|
764ca1f098 | ||
|
|
3d23e5b066 | ||
|
|
90e418ba24 | ||
|
|
b6a0937e0c | ||
|
|
b3f6f8ef18 | ||
|
|
d9d5400498 | ||
|
|
b1be681afb | ||
|
|
8ef309d479 | ||
|
|
6e59b63791 | ||
|
|
9c7b3cea83 | ||
|
|
26af6a07f4 | ||
|
|
b7c6d4b478 | ||
|
|
9936fc04da | ||
|
|
1e0dfa2106 | ||
|
|
3af6f6a8f0 | ||
|
|
1e793c0d16 |
@@ -26,6 +26,8 @@
|
||||
use Phan\Config;
|
||||
|
||||
return [
|
||||
// "target_php_version" => "8.2",
|
||||
"minimum_target_php_version" => "8.1",
|
||||
// turn color on (-C)
|
||||
"color_issue_messages_if_supported" => true,
|
||||
// If true, missing properties will be created when
|
||||
@@ -94,8 +96,6 @@ return [
|
||||
"exclude_analysis_directory_list" => [
|
||||
'www/vendor',
|
||||
'www/tests',
|
||||
'www/lib/Smarty',
|
||||
'www/lib/smarty-4.1.0',
|
||||
'www/templates_c',
|
||||
'www/log',
|
||||
'www/tmp',
|
||||
@@ -116,8 +116,6 @@ return [
|
||||
// ignore the old qq tests
|
||||
'www/admin/qq_file_upload_front.php',
|
||||
'www/admin/qq_file_upload_ajax.php',
|
||||
// symlink ignore
|
||||
'www/lib/smarty-4.1.0/libs/Smarty.class.php'
|
||||
],
|
||||
|
||||
// what not to show as problem
|
||||
@@ -130,7 +128,12 @@ return [
|
||||
'PhanWriteOnlyPublicProperty',
|
||||
'PhanUnreferencedConstant',
|
||||
'PhanWriteOnlyPublicProperty',
|
||||
'PhanReadOnlyPublicProperty'
|
||||
'PhanReadOnlyPublicProperty',
|
||||
// start ignore annotations
|
||||
'PhanUnextractableAnnotationElementName',
|
||||
'PhanUnextractableAnnotationSuffix',
|
||||
// enum problems in comments
|
||||
'PhanCommentObjectInClassConstantType'
|
||||
],
|
||||
|
||||
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
|
||||
|
||||
169
4dev/bin/mo_to_js.sh
Executable file
169
4dev/bin/mo_to_js.sh
Executable file
@@ -0,0 +1,169 @@
|
||||
#!/bin/bash
|
||||
|
||||
# read source mo files and writes target js files in object form
|
||||
|
||||
# check for ARG 1 is "mv"
|
||||
# then move the files directly and don't do manual check (don't create temp files)
|
||||
FILE_MOVE=0;
|
||||
if [ "${1}" = "mv" ]; then
|
||||
echo "*** Direct write ***";
|
||||
FILE_MOVE=1;
|
||||
fi;
|
||||
|
||||
target='';
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
# Assume script is in 4dev/bin
|
||||
base_folder="${BASE_FOLDER}../../www/";
|
||||
po_folder='../4dev/locale/'
|
||||
mo_folder='includes/locale/';
|
||||
target_folder='';
|
||||
template_file_stump='##SUFFIX##translate-##LANGUAGE##.TMP.js';
|
||||
# for output file names
|
||||
source_list=(iw);
|
||||
language_list=(en ja);
|
||||
# set target names
|
||||
if [ "${target}" == '' ]; then
|
||||
echo "*** Non smarty ***";
|
||||
TEXTDOMAINDIR=${base_folder}${mo_folder}.
|
||||
# default is admin
|
||||
TEXTDOMAIN=admin;
|
||||
fi;
|
||||
js_folder="layout/${TEXTDOMAIN}/javascript/";
|
||||
|
||||
error=0;
|
||||
# this checks if the TEXTDOMAIN target actually exists
|
||||
if [ ! -d "${base_folder}${js_folder}" ]; then
|
||||
echo "Cannot find target javascript folder ${base_folder}${js_folder}";
|
||||
error=1;
|
||||
else
|
||||
target_folder="${base_folder}${js_folder}";
|
||||
fi;
|
||||
|
||||
if [ ${error} -eq 1 ]; then
|
||||
exit;
|
||||
fi;
|
||||
|
||||
# locale gettext po to mo translator master
|
||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
||||
file=$(basename $file .po);
|
||||
echo "Translate language ${file}";
|
||||
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
|
||||
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
|
||||
fi;
|
||||
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}${po_folder}${locale}-${domain}.po;
|
||||
done;
|
||||
|
||||
rx_msgid_empty="^msgid \"\"";
|
||||
rx_msgid="^msgid \"";
|
||||
rx_msgstr="^msgstr \""
|
||||
|
||||
# quick copy string at the end
|
||||
quick_copy='';
|
||||
|
||||
for language in ${language_list[*]}; do
|
||||
# I don't know which one must be set, but I think at least LANGUAGE
|
||||
case ${language} in
|
||||
ja)
|
||||
LANG=ja_JP.UTF-8;
|
||||
ENCODING=UTF-8;
|
||||
LANGUAGE=ja;
|
||||
;;
|
||||
en)
|
||||
# was en_JP.UTF-8
|
||||
LANG=en_US.UTF-8;
|
||||
ENCODING=UTF-8;
|
||||
LANGUAGE=en;
|
||||
;;
|
||||
esac;
|
||||
# write only one for language and then symlink files
|
||||
template_file=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##//" | sed -e "s/##LANGUAGE##/${LANG}/");
|
||||
original_file=$(echo ${template_file} | sed -e 's/\.TMP//g');
|
||||
if [ "${FILE_MOVE}" -eq 0 ]; then
|
||||
file=${target_folder}${template_file};
|
||||
else
|
||||
file=${target_folder}${original_file};
|
||||
fi;
|
||||
echo "===> Write translation file ${file}";
|
||||
echo ". = normal, : = escape, x = skip";
|
||||
# init line [aka don't touch this file]
|
||||
echo "// AUTO FILL, changes will be overwritten" > $file;
|
||||
echo "// source: ${suffix}, language: ${language}" >> $file;
|
||||
echo "// Translation strings in the format" >> $file;
|
||||
echo "// \"Original\":\"Translated\""$'\n' >> $file;
|
||||
echo "var i18n = {" >> $file;
|
||||
# translations stuff
|
||||
# read the po file
|
||||
pos=0; # do we add a , for the next line
|
||||
cat "${base_folder}${po_folder}${language}-${TEXTDOMAIN}.po" |
|
||||
while read str; do
|
||||
# echo "S: ${str}";
|
||||
# skip empty
|
||||
if [[ "${str}" =~ ${rx_msgid_empty} ]]; then
|
||||
# skip on empty
|
||||
echo -n "x";
|
||||
# msgid is left, msgstr is right
|
||||
elif [[ "${str}" =~ ${rx_msgid} ]]; then
|
||||
echo -n ".";
|
||||
# open left side
|
||||
# TODO: how to handle multi line strings: or don't use them
|
||||
# extract from between ""
|
||||
str_source=$(echo "${str}" | sed -e "s/^msgid \"//" | sed -e "s/\"$//");
|
||||
# close right side, if not last add ,
|
||||
if [ "${pos}" -eq 1 ]; then
|
||||
echo -n "," >> $file;
|
||||
fi;
|
||||
# all " inside string need to be escaped
|
||||
str_source=$(echo "${str_source}" | sed -e 's/"/\\"/g');
|
||||
# fix with proper layout
|
||||
echo -n "\"$str_source\":\"$(TEXTDOMAINDIR=${TEXTDOMAINDIR} LANGUAGE=${language} LANG=${LANG} gettext ${TEXTDOMAIN} "${str_source}")\"" >> $file;
|
||||
pos=1;
|
||||
elif [[ "${str}" =~ ${rx_msgstr} ]]; then
|
||||
# open right side (ignore)
|
||||
echo -n "";
|
||||
else
|
||||
# general ignore (anything between or comments)
|
||||
echo -n "";
|
||||
fi;
|
||||
done;
|
||||
|
||||
echo "" >> $file;
|
||||
echo "};" >> $file;
|
||||
echo " [DONE]";
|
||||
|
||||
# on no move
|
||||
if [ "${FILE_MOVE}" -eq 0 ]; then
|
||||
echo "===> Confirm all changes in ${file} and then move data to original";
|
||||
echo "";
|
||||
quick_copy=${quick_copy}"mv ${template_file} ${original_file}"$'\n';
|
||||
fi;
|
||||
|
||||
# symlink to master file
|
||||
for suffix in ${source_list[*]}; do
|
||||
# symlink with full lang name
|
||||
symlink_file[0]=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##/${suffix}_/" | sed -e "s/##LANGUAGE##/${LANG}/" | sed -e 's/\.TMP//g');
|
||||
# create second one with lang (no country) + encoding
|
||||
symlink_file[1]=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##/${suffix}_/" | sed -e "s/##LANGUAGE##/${LANGUAGE}\.${ENCODING}/" | sed -e 's/\.TMP//g');
|
||||
for template_file in ${symlink_file[@]}; do
|
||||
# if this is not symlink, create them
|
||||
if [ ! -h "${template_file}" ]; then
|
||||
echo "Create symlink: ${template_file}";
|
||||
# symlik to original
|
||||
cd "${target_folder}";
|
||||
ln -sf "${original_file}" "${template_file}";
|
||||
cd - >/dev/null;
|
||||
fi;
|
||||
done;
|
||||
done;
|
||||
done;
|
||||
|
||||
if [ "${FILE_MOVE}" -eq 0 ]; then
|
||||
echo "";
|
||||
echo "-- IN FOLDER: ${target_folder}";
|
||||
echo "-- START: copy lines below to copy created over original --";
|
||||
echo "${quick_copy}";
|
||||
echo "-- END ----------------------------------------------------";
|
||||
fi;
|
||||
|
||||
# __END__
|
||||
@@ -1,9 +1,11 @@
|
||||
#!/bin/env bash
|
||||
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# -c phpunit.xml
|
||||
# --testdox
|
||||
# call with "t" to give verbose testdox output
|
||||
# SUPPORTED: https://www.php.net/supported-versions.php
|
||||
# call with 7.3, 7.4, 8.0, 8.1 to force a certain php version
|
||||
# call with php version number to force a certain php version
|
||||
|
||||
opt_testdox="";
|
||||
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
||||
@@ -13,18 +15,20 @@ php_bin="";
|
||||
if [ ! -z "${1}" ]; then
|
||||
case "${1}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
|
||||
case "${2}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
|
||||
22
4dev/composer/sync-to-composer-all-folder.sh
Executable file
22
4dev/composer/sync-to-composer-all-folder.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/env bash
|
||||
|
||||
# syncs
|
||||
# 4dev/tests/
|
||||
# www/lib/CoreLibs/
|
||||
#
|
||||
# to the composer corelibs all repo
|
||||
|
||||
GO="${1}";
|
||||
DRY_RUN="";
|
||||
if [ "${GO}" != "go" ]; then
|
||||
DRY_RUN="-n ";
|
||||
fi;
|
||||
|
||||
BASE="/storage/var/www/html/developers/clemens/core_data/";
|
||||
SOURCE="${BASE}php_libraries/trunk/"
|
||||
TARGET="${BASE}composer-packages/CoreLibs-Composer-All/"
|
||||
|
||||
rsync ${DRY_RUN}-Plzvrupt --stats --delete ${SOURCE}4dev/tests/ ${TARGET}test/phpunit/
|
||||
rsync ${DRY_RUN}-Plzvrupt --stats --delete ${SOURCE}www/lib/CoreLibs/ ${TARGET}src/
|
||||
|
||||
# __END__
|
||||
@@ -3,26 +3,26 @@
|
||||
CREATE OR REPLACE FUNCTION set_edit_access_uid() RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
myrec RECORD;
|
||||
v_uid VARCHAR;
|
||||
myrec RECORD;
|
||||
v_uid VARCHAR;
|
||||
BEGIN
|
||||
-- skip if NEW.name is not set
|
||||
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
||||
-- use NEW.name as base, remove all spaces
|
||||
-- name data is already unique, so we do not need to worry about this here
|
||||
v_uid := REPLACE(NEW.name, ' ', '');
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
-- always set
|
||||
NEW.uid := v_uid;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- check if not set, then set
|
||||
SELECT INTO myrec t.* FROM edit_access t WHERE edit_access_id = NEW.edit_access_id;
|
||||
IF FOUND THEN
|
||||
NEW.uid := v_uid;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
-- skip if NEW.name is not set
|
||||
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
||||
-- use NEW.name as base, remove all spaces
|
||||
-- name data is already unique, so we do not need to worry about this here
|
||||
v_uid := REPLACE(NEW.name, ' ', '');
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
-- always set
|
||||
NEW.uid := v_uid;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- check if not set, then set
|
||||
SELECT INTO myrec t.* FROM edit_access t WHERE edit_access_id = NEW.edit_access_id;
|
||||
IF FOUND THEN
|
||||
NEW.uid := v_uid;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -3,26 +3,26 @@
|
||||
CREATE OR REPLACE FUNCTION set_edit_group_uid() RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
myrec RECORD;
|
||||
v_uid VARCHAR;
|
||||
myrec RECORD;
|
||||
v_uid VARCHAR;
|
||||
BEGIN
|
||||
-- skip if NEW.name is not set
|
||||
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
||||
-- use NEW.name as base, remove all spaces
|
||||
-- name data is already unique, so we do not need to worry about this here
|
||||
v_uid := REPLACE(NEW.name, ' ', '');
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
-- always set
|
||||
NEW.uid := v_uid;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- check if not set, then set
|
||||
SELECT INTO myrec t.* FROM edit_group t WHERE edit_group_id = NEW.edit_group_id;
|
||||
IF FOUND THEN
|
||||
NEW.uid := v_uid;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
-- skip if NEW.name is not set
|
||||
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
||||
-- use NEW.name as base, remove all spaces
|
||||
-- name data is already unique, so we do not need to worry about this here
|
||||
v_uid := REPLACE(NEW.name, ' ', '');
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
-- always set
|
||||
NEW.uid := v_uid;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- check if not set, then set
|
||||
SELECT INTO myrec t.* FROM edit_group t WHERE edit_group_id = NEW.edit_group_id;
|
||||
IF FOUND THEN
|
||||
NEW.uid := v_uid;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -9,142 +9,142 @@ CREATE OR REPLACE FUNCTION edit_log_insert_trigger ()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
start_date DATE := '2010-01-01';
|
||||
end_date DATE;
|
||||
timeformat TEXT := 'YYYY';
|
||||
selector TEXT := 'year';
|
||||
base_table TEXT := 'edit_log';
|
||||
_interval INTERVAL := '1 ' || selector;
|
||||
_interval_next INTERVAL := '2 ' || selector;
|
||||
table_name TEXT;
|
||||
-- compare date column
|
||||
compare_date DATE := NEW.event_date;
|
||||
compare_date_name TEXT := 'event_date';
|
||||
-- the create commands
|
||||
command_create_table TEXT := 'CREATE TABLE IF NOT EXISTS {TABLE_NAME} (CHECK({COMPARE_DATE_NAME} >= {START_DATE} AND {COMPARE_DATE_NAME} < {END_DATE})) INHERITS ({BASE_NAME})';
|
||||
command_create_primary_key TEXT := 'ALTER TABLE {TABLE_NAME} ADD PRIMARY KEY ({BASE_TABLE}_id)';
|
||||
command_create_foreign_key_1 TEXT := 'ALTER TABLE {TABLE_NAME} ADD CONSTRAINT {TABLE_NAME}_euid_fkey FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL';
|
||||
command_create_trigger_1 TEXT = 'CREATE TRIGGER trg_{TABLE_NAME} BEFORE INSERT OR UPDATE ON {TABLE_NAME} FOR EACH ROW EXECUTE PROCEDURE set_edit_generic()';
|
||||
start_date DATE := '2010-01-01';
|
||||
end_date DATE;
|
||||
timeformat TEXT := 'YYYY';
|
||||
selector TEXT := 'year';
|
||||
base_table TEXT := 'edit_log';
|
||||
_interval INTERVAL := '1 ' || selector;
|
||||
_interval_next INTERVAL := '2 ' || selector;
|
||||
table_name TEXT;
|
||||
-- compare date column
|
||||
compare_date DATE := NEW.event_date;
|
||||
compare_date_name TEXT := 'event_date';
|
||||
-- the create commands
|
||||
command_create_table TEXT := 'CREATE TABLE IF NOT EXISTS {TABLE_NAME} (CHECK({COMPARE_DATE_NAME} >= {START_DATE} AND {COMPARE_DATE_NAME} < {END_DATE})) INHERITS ({BASE_NAME})';
|
||||
command_create_primary_key TEXT := 'ALTER TABLE {TABLE_NAME} ADD PRIMARY KEY ({BASE_TABLE}_id)';
|
||||
command_create_foreign_key_1 TEXT := 'ALTER TABLE {TABLE_NAME} ADD CONSTRAINT {TABLE_NAME}_euid_fkey FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL';
|
||||
command_create_trigger_1 TEXT = 'CREATE TRIGGER trg_{TABLE_NAME} BEFORE INSERT OR UPDATE ON {TABLE_NAME} FOR EACH ROW EXECUTE PROCEDURE set_edit_generic()';
|
||||
BEGIN
|
||||
-- we are in valid start time area
|
||||
IF (NEW.event_date >= start_date) THEN
|
||||
-- current table name
|
||||
table_name := base_table || '_' || to_char(NEW.event_date, timeformat);
|
||||
BEGIN
|
||||
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
|
||||
-- if insert failed because of missing table, create new below
|
||||
EXCEPTION
|
||||
WHEN undefined_table THEN
|
||||
-- another block, so in case the creation fails here too
|
||||
BEGIN
|
||||
-- create new table here + all indexes
|
||||
start_date := date_trunc(selector, NEW.event_date);
|
||||
end_date := date_trunc(selector, NEW.event_date + _interval);
|
||||
-- creat table
|
||||
EXECUTE format(REPLACE( -- end date
|
||||
REPLACE( -- start date
|
||||
REPLACE( -- compare date name
|
||||
REPLACE( -- base name (inherit)
|
||||
REPLACE( -- table name
|
||||
command_create_table,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_NAME}',
|
||||
base_table
|
||||
),
|
||||
'{COMPARE_DATE_NAME}',
|
||||
compare_date_name
|
||||
),
|
||||
'{START_DATE}',
|
||||
quote_literal(start_date)
|
||||
),
|
||||
'{END_DATE}',
|
||||
quote_literal(end_date)
|
||||
));
|
||||
-- create all indexes and triggers
|
||||
EXECUTE format(REPLACE(
|
||||
REPLACE(
|
||||
command_create_primary_key,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_TABLE}',
|
||||
base_table
|
||||
));
|
||||
-- FK constraints
|
||||
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
|
||||
-- generic trigger
|
||||
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
|
||||
-- we are in valid start time area
|
||||
IF (NEW.event_date >= start_date) THEN
|
||||
-- current table name
|
||||
table_name := base_table || '_' || to_char(NEW.event_date, timeformat);
|
||||
BEGIN
|
||||
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
|
||||
-- if insert failed because of missing table, create new below
|
||||
EXCEPTION
|
||||
WHEN undefined_table THEN
|
||||
-- another block, so in case the creation fails here too
|
||||
BEGIN
|
||||
-- create new table here + all indexes
|
||||
start_date := date_trunc(selector, NEW.event_date);
|
||||
end_date := date_trunc(selector, NEW.event_date + _interval);
|
||||
-- creat table
|
||||
EXECUTE format(REPLACE( -- end date
|
||||
REPLACE( -- start date
|
||||
REPLACE( -- compare date name
|
||||
REPLACE( -- base name (inherit)
|
||||
REPLACE( -- table name
|
||||
command_create_table,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_NAME}',
|
||||
base_table
|
||||
),
|
||||
'{COMPARE_DATE_NAME}',
|
||||
compare_date_name
|
||||
),
|
||||
'{START_DATE}',
|
||||
quote_literal(start_date)
|
||||
),
|
||||
'{END_DATE}',
|
||||
quote_literal(end_date)
|
||||
));
|
||||
-- create all indexes and triggers
|
||||
EXECUTE format(REPLACE(
|
||||
REPLACE(
|
||||
command_create_primary_key,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_TABLE}',
|
||||
base_table
|
||||
));
|
||||
-- FK constraints
|
||||
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
|
||||
-- generic trigger
|
||||
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
|
||||
|
||||
-- insert try again
|
||||
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
-- if this faled, throw it into the overflow table (so we don't loose anything)
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END;
|
||||
-- other errors, insert into overlow
|
||||
WHEN OTHERS THEN
|
||||
-- if this faled, throw it into the overflow table (so we don't loose anything)
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END;
|
||||
-- main insert run done, check if we have to create next months table
|
||||
BEGIN
|
||||
-- check if next month table exists
|
||||
table_name := base_table || '_' || to_char((SELECT NEW.event_date + _interval)::DATE, timeformat);
|
||||
-- RAISE NOTICE 'SEARCH NEXT: %', table_name;
|
||||
IF (SELECT to_regclass(table_name)) IS NULL THEN
|
||||
-- move inner interval same
|
||||
start_date := date_trunc(selector, NEW.event_date + _interval);
|
||||
end_date := date_trunc(selector, NEW.event_date + _interval_next);
|
||||
-- RAISE NOTICE 'CREATE NEXT: %', table_name;
|
||||
-- create table
|
||||
EXECUTE format(REPLACE( -- end date
|
||||
REPLACE( -- start date
|
||||
REPLACE( -- compare date name
|
||||
REPLACE( -- base name (inherit)
|
||||
REPLACE( -- table name
|
||||
command_create_table,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_NAME}',
|
||||
base_table
|
||||
),
|
||||
'{COMPARE_DATE_NAME}',
|
||||
compare_date_name
|
||||
),
|
||||
'{START_DATE}',
|
||||
quote_literal(start_date)
|
||||
),
|
||||
'{END_DATE}',
|
||||
quote_literal(end_date)
|
||||
));
|
||||
-- create all indexes and triggers
|
||||
EXECUTE format(REPLACE(
|
||||
REPLACE(
|
||||
command_create_primary_key,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_TABLE}',
|
||||
base_table
|
||||
));
|
||||
-- FK constraints
|
||||
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
|
||||
-- generic trigger
|
||||
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
RAISE NOTICE 'Failed to create next table: %', table_name;
|
||||
END;
|
||||
ELSE
|
||||
-- if outside valid date, insert into overflow
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END IF;
|
||||
RETURN NULL;
|
||||
-- insert try again
|
||||
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
-- if this faled, throw it into the overflow table (so we don't loose anything)
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END;
|
||||
-- other errors, insert into overlow
|
||||
WHEN OTHERS THEN
|
||||
-- if this faled, throw it into the overflow table (so we don't loose anything)
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END;
|
||||
-- main insert run done, check if we have to create next months table
|
||||
BEGIN
|
||||
-- check if next month table exists
|
||||
table_name := base_table || '_' || to_char((SELECT NEW.event_date + _interval)::DATE, timeformat);
|
||||
-- RAISE NOTICE 'SEARCH NEXT: %', table_name;
|
||||
IF (SELECT to_regclass(table_name)) IS NULL THEN
|
||||
-- move inner interval same
|
||||
start_date := date_trunc(selector, NEW.event_date + _interval);
|
||||
end_date := date_trunc(selector, NEW.event_date + _interval_next);
|
||||
-- RAISE NOTICE 'CREATE NEXT: %', table_name;
|
||||
-- create table
|
||||
EXECUTE format(REPLACE( -- end date
|
||||
REPLACE( -- start date
|
||||
REPLACE( -- compare date name
|
||||
REPLACE( -- base name (inherit)
|
||||
REPLACE( -- table name
|
||||
command_create_table,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_NAME}',
|
||||
base_table
|
||||
),
|
||||
'{COMPARE_DATE_NAME}',
|
||||
compare_date_name
|
||||
),
|
||||
'{START_DATE}',
|
||||
quote_literal(start_date)
|
||||
),
|
||||
'{END_DATE}',
|
||||
quote_literal(end_date)
|
||||
));
|
||||
-- create all indexes and triggers
|
||||
EXECUTE format(REPLACE(
|
||||
REPLACE(
|
||||
command_create_primary_key,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_TABLE}',
|
||||
base_table
|
||||
));
|
||||
-- FK constraints
|
||||
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
|
||||
-- generic trigger
|
||||
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
RAISE NOTICE 'Failed to create next table: %', table_name;
|
||||
END;
|
||||
ELSE
|
||||
-- if outside valid date, insert into overflow
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END IF;
|
||||
RETURN NULL;
|
||||
END
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -5,22 +5,22 @@ CREATE OR REPLACE FUNCTION set_login_user_id_set_date()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
BEGIN
|
||||
-- if new is not null/empty
|
||||
-- and old one is null or old one different new one
|
||||
-- set NOW()
|
||||
-- if new one is NULL
|
||||
-- set NULL
|
||||
IF
|
||||
NEW.login_user_id IS NOT NULL AND NEW.login_user_id <> '' AND
|
||||
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
||||
THEN
|
||||
NEW.login_user_id_set_date = NOW();
|
||||
NEW.login_user_id_last_revalidate = NOW();
|
||||
ELSIF NEW.login_user_id IS NULL OR NEW.login_user_id = '' THEN
|
||||
NEW.login_user_id_set_date = NULL;
|
||||
NEW.login_user_id_last_revalidate = NULL;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
-- if new is not null/empty
|
||||
-- and old one is null or old one different new one
|
||||
-- set NOW()
|
||||
-- if new one is NULL
|
||||
-- set NULL
|
||||
IF
|
||||
NEW.login_user_id IS NOT NULL AND NEW.login_user_id <> '' AND
|
||||
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
||||
THEN
|
||||
NEW.login_user_id_set_date = NOW();
|
||||
NEW.login_user_id_last_revalidate = NOW();
|
||||
ELSIF NEW.login_user_id IS NULL OR NEW.login_user_id = '' THEN
|
||||
NEW.login_user_id_set_date = NULL;
|
||||
NEW.login_user_id_last_revalidate = NULL;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -4,15 +4,15 @@ CREATE FUNCTION random_string(randomLength int)
|
||||
RETURNS text AS
|
||||
$$
|
||||
SELECT array_to_string(
|
||||
ARRAY(
|
||||
SELECT substring(
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
|
||||
trunc(random() * 62)::int + 1,
|
||||
1
|
||||
)
|
||||
FROM generate_series(1, randomLength) AS gs(x)
|
||||
),
|
||||
''
|
||||
ARRAY(
|
||||
SELECT substring(
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
|
||||
trunc(random() * 62)::int + 1,
|
||||
1
|
||||
)
|
||||
FROM generate_series(1, randomLength) AS gs(x)
|
||||
),
|
||||
''
|
||||
)
|
||||
$$
|
||||
LANGUAGE SQL
|
||||
|
||||
@@ -4,12 +4,12 @@ CREATE OR REPLACE FUNCTION set_date()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -4,15 +4,15 @@ CREATE OR REPLACE FUNCTION set_edit_generic()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
random_length INT = 12; -- that should be long enough
|
||||
random_length INT = 25; -- that should be long enough
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
NEW.cuid := random_string(random_length);
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
NEW.cuid := random_string(random_length);
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -5,17 +5,17 @@ CREATE OR REPLACE FUNCTION set_generic()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
random_length INT = 32; -- long for massive data
|
||||
random_length INT = 32; -- long for massive data
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
IF NEW.uid IS NULL THEN
|
||||
NEW.uid := random_string(random_length);
|
||||
END IF;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
IF NEW.uid IS NULL THEN
|
||||
NEW.uid := random_string(random_length);
|
||||
END IF;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -4,12 +4,12 @@ CREATE OR REPLACE FUNCTION set_uid()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
random_length INT = 32; -- that should be long enough
|
||||
random_length INT = 32; -- that should be long enough
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.uid := random_string(random_length);
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.uid := random_string(random_length);
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
-- RETURNS TRIGGER AS
|
||||
-- $$
|
||||
-- BEGIN
|
||||
-- IF TG_OP = 'INSERT' THEN
|
||||
-- NEW.date_created := clock_timestamp();
|
||||
-- NEW.user_created := current_user;
|
||||
-- ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- NEW.date_updated := clock_timestamp();
|
||||
-- NEW.user_updated := current_user;
|
||||
-- END IF;
|
||||
-- RETURN NEW;
|
||||
-- IF TG_OP = 'INSERT' THEN
|
||||
-- NEW.date_created := clock_timestamp();
|
||||
-- NEW.user_created := current_user;
|
||||
-- ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- NEW.date_updated := clock_timestamp();
|
||||
-- NEW.user_updated := current_user;
|
||||
-- END IF;
|
||||
-- RETURN NEW;
|
||||
-- END;
|
||||
-- $$
|
||||
-- LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
-- DROP TABLE edit_access;
|
||||
CREATE TABLE edit_access (
|
||||
edit_access_id SERIAL PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
protected SMALLINT DEFAULT 0,
|
||||
deleted SMALLINT DEFAULT 0,
|
||||
uid VARCHAR,
|
||||
name VARCHAR UNIQUE,
|
||||
description VARCHAR,
|
||||
color VARCHAR,
|
||||
additional_acl JSONB
|
||||
edit_access_id SERIAL PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
protected SMALLINT DEFAULT 0,
|
||||
deleted SMALLINT DEFAULT 0,
|
||||
uid VARCHAR,
|
||||
name VARCHAR UNIQUE,
|
||||
description VARCHAR,
|
||||
color VARCHAR,
|
||||
additional_acl JSONB
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
-- DROP TABLE edit_access_data;
|
||||
CREATE TABLE edit_access_data (
|
||||
edit_access_data_id SERIAL PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
value VARCHAR
|
||||
edit_access_data_id SERIAL PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
value VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
-- create a unique index for each attached data block for each edit access can
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
-- DROP TABLE edit_access_right;
|
||||
CREATE TABLE edit_access_right (
|
||||
edit_access_right_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
level SMALLINT,
|
||||
type VARCHAR,
|
||||
UNIQUE (level,type)
|
||||
edit_access_right_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
level SMALLINT,
|
||||
type VARCHAR,
|
||||
UNIQUE (level,type)
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
-- DROP TABLE edit_access_user;
|
||||
CREATE TABLE edit_access_user (
|
||||
edit_access_user_id SERIAL PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_user_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_default SMALLINT DEFAULT 0,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0
|
||||
edit_access_user_id SERIAL PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_user_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_default SMALLINT DEFAULT 0,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_generic;
|
||||
CREATE TABLE edit_generic (
|
||||
cuid VARCHAR,
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE
|
||||
cuid VARCHAR,
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE
|
||||
);
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
-- DROP TABLE edit_group;
|
||||
CREATE TABLE edit_group (
|
||||
edit_group_id SERIAL PRIMARY KEY,
|
||||
edit_scheme_id INT,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
deleted SMALLINT DEFAULT 0,
|
||||
uid VARCHAR,
|
||||
name VARCHAR,
|
||||
additional_acl JSONB
|
||||
edit_group_id SERIAL PRIMARY KEY,
|
||||
edit_scheme_id INT,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
deleted SMALLINT DEFAULT 0,
|
||||
uid VARCHAR,
|
||||
name VARCHAR,
|
||||
additional_acl JSONB
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
-- DROP TABLE edit_language;
|
||||
CREATE TABLE edit_language (
|
||||
edit_language_id SERIAL PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
lang_default SMALLINT NOT NULL DEFAULT 0,
|
||||
long_name VARCHAR,
|
||||
short_name VARCHAR, -- en_US, en or en_US@latin without encoding
|
||||
iso_name VARCHAR, -- should actually be encoding
|
||||
order_number INT
|
||||
edit_language_id SERIAL PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
lang_default SMALLINT NOT NULL DEFAULT 0,
|
||||
long_name VARCHAR,
|
||||
short_name VARCHAR, -- en_US, en or en_US@latin without encoding
|
||||
iso_name VARCHAR, -- should actually be encoding
|
||||
order_number INT
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,35 +7,35 @@
|
||||
|
||||
-- DROP TABLE edit_log;
|
||||
CREATE TABLE edit_log (
|
||||
edit_log_id SERIAL PRIMARY KEY,
|
||||
euid INT, -- this is a foreign key, but I don't nedd to reference to it
|
||||
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
username VARCHAR,
|
||||
password VARCHAR,
|
||||
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
ip VARCHAR,
|
||||
error TEXT,
|
||||
event TEXT,
|
||||
data_binary BYTEA,
|
||||
data TEXT,
|
||||
page VARCHAR,
|
||||
action VARCHAR,
|
||||
action_id VARCHAR,
|
||||
action_yes VARCHAR,
|
||||
action_flag VARCHAR,
|
||||
action_menu VARCHAR,
|
||||
action_loaded VARCHAR,
|
||||
action_value VARCHAR,
|
||||
action_type VARCHAR,
|
||||
action_error VARCHAR,
|
||||
user_agent VARCHAR,
|
||||
referer VARCHAR,
|
||||
script_name VARCHAR,
|
||||
query_string VARCHAR,
|
||||
server_name VARCHAR,
|
||||
http_host VARCHAR,
|
||||
http_accept VARCHAR,
|
||||
http_accept_charset VARCHAR,
|
||||
http_accept_encoding VARCHAR,
|
||||
session_id VARCHAR
|
||||
edit_log_id SERIAL PRIMARY KEY,
|
||||
euid INT, -- this is a foreign key, but I don't nedd to reference to it
|
||||
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
username VARCHAR,
|
||||
password VARCHAR,
|
||||
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
ip VARCHAR,
|
||||
error TEXT,
|
||||
event TEXT,
|
||||
data_binary BYTEA,
|
||||
data TEXT,
|
||||
page VARCHAR,
|
||||
action VARCHAR,
|
||||
action_id VARCHAR,
|
||||
action_yes VARCHAR,
|
||||
action_flag VARCHAR,
|
||||
action_menu VARCHAR,
|
||||
action_loaded VARCHAR,
|
||||
action_value VARCHAR,
|
||||
action_type VARCHAR,
|
||||
action_error VARCHAR,
|
||||
user_agent VARCHAR,
|
||||
referer VARCHAR,
|
||||
script_name VARCHAR,
|
||||
query_string VARCHAR,
|
||||
server_name VARCHAR,
|
||||
http_host VARCHAR,
|
||||
http_accept VARCHAR,
|
||||
http_accept_charset VARCHAR,
|
||||
http_accept_encoding VARCHAR,
|
||||
session_id VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
-- DROP TABLE edit_menu_group;
|
||||
CREATE TABLE edit_menu_group (
|
||||
edit_menu_group_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
flag VARCHAR,
|
||||
order_number INT NOT NULL
|
||||
edit_menu_group_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
flag VARCHAR,
|
||||
order_number INT NOT NULL
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@
|
||||
|
||||
-- DROP TABLE edit_page;
|
||||
CREATE TABLE edit_page (
|
||||
edit_page_id SERIAL PRIMARY KEY,
|
||||
content_alias_edit_page_id INT, -- alias for page content, if the page content is defined on a different page, ege for ajax backend pages
|
||||
FOREIGN KEY (content_alias_edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
filename VARCHAR,
|
||||
name VARCHAR UNIQUE,
|
||||
order_number INT NOT NULL,
|
||||
online SMALLINT NOT NULL DEFAULT 0,
|
||||
menu SMALLINT NOT NULL DEFAULT 0,
|
||||
popup SMALLINT NOT NULL DEFAULT 0,
|
||||
popup_x SMALLINT,
|
||||
popup_y SMALLINT,
|
||||
hostname VARCHAR
|
||||
edit_page_id SERIAL PRIMARY KEY,
|
||||
content_alias_edit_page_id INT, -- alias for page content, if the page content is defined on a different page, ege for ajax backend pages
|
||||
FOREIGN KEY (content_alias_edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
filename VARCHAR,
|
||||
name VARCHAR UNIQUE,
|
||||
order_number INT NOT NULL,
|
||||
online SMALLINT NOT NULL DEFAULT 0,
|
||||
menu SMALLINT NOT NULL DEFAULT 0,
|
||||
popup SMALLINT NOT NULL DEFAULT 0,
|
||||
popup_x SMALLINT,
|
||||
popup_y SMALLINT,
|
||||
hostname VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
-- DROP TABLE edit_page_access;
|
||||
CREATE TABLE edit_page_access (
|
||||
edit_page_access_id SERIAL PRIMARY KEY,
|
||||
edit_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0
|
||||
edit_page_access_id SERIAL PRIMARY KEY,
|
||||
edit_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
-- DROP TABLE edit_page_content;
|
||||
CREATE TABLE edit_page_content (
|
||||
edit_page_content_id SERIAL PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
uid VARCHAR UNIQUE,
|
||||
name VARCHAR,
|
||||
order_number INT NOT NULL,
|
||||
online SMALLINT NOT NULL DEFAULT 0
|
||||
edit_page_content_id SERIAL PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
uid VARCHAR UNIQUE,
|
||||
name VARCHAR,
|
||||
order_number INT NOT NULL,
|
||||
online SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
-- DROP TABLE edit_page_menu_group;
|
||||
CREATE TABLE edit_page_menu_group (
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_menu_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_menu_group_id) REFERENCES edit_menu_group (edit_menu_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_menu_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_menu_group_id) REFERENCES edit_menu_group (edit_menu_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
-- DROP TABLE edit_page_visible_group;
|
||||
CREATE TABLE edit_page_visible_group (
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_visible_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_visible_group_id) REFERENCES edit_visible_group (edit_visible_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_visible_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_visible_group_id) REFERENCES edit_visible_group (edit_visible_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
-- DROP TABLE edit_query_string;
|
||||
CREATE TABLE edit_query_string (
|
||||
edit_query_string_id SERIAL PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
value VARCHAR,
|
||||
dynamic SMALLINT NOT NULL DEFAULT 0
|
||||
edit_query_string_id SERIAL PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
value VARCHAR,
|
||||
dynamic SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
-- DROP TABLE edit_scheme;
|
||||
CREATE TABLE edit_scheme (
|
||||
edit_scheme_id SERIAL PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
header_color VARCHAR,
|
||||
css_file VARCHAR,
|
||||
template VARCHAR
|
||||
edit_scheme_id SERIAL PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
header_color VARCHAR,
|
||||
css_file VARCHAR,
|
||||
template VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
|
||||
-- DROP TABLE temp_files;
|
||||
CREATE TABLE temp_files (
|
||||
filename VARCHAR,
|
||||
folder VARCHAR
|
||||
filename VARCHAR,
|
||||
folder VARCHAR
|
||||
);
|
||||
|
||||
@@ -7,63 +7,63 @@
|
||||
|
||||
-- DROP TABLE edit_user;
|
||||
CREATE TABLE edit_user (
|
||||
edit_user_id SERIAL PRIMARY KEY,
|
||||
connect_edit_user_id INT, -- possible reference to other user
|
||||
FOREIGN KEY (connect_edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_language_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_language_id) REFERENCES edit_language (edit_language_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_scheme_id INT,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
-- username/password
|
||||
username VARCHAR UNIQUE,
|
||||
password VARCHAR,
|
||||
-- name block
|
||||
first_name VARCHAR,
|
||||
last_name VARCHAR,
|
||||
first_name_furigana VARCHAR,
|
||||
last_name_furigana VARCHAR,
|
||||
-- email
|
||||
email VARCHAR,
|
||||
-- eanbled/deleted flag
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
deleted SMALLINT NOT NULL DEFAULT 0,
|
||||
-- general flags
|
||||
strict SMALLINT DEFAULT 0,
|
||||
locked SMALLINT DEFAULT 0,
|
||||
protected SMALLINT NOT NULL DEFAULT 0,
|
||||
-- legacy, debug flags
|
||||
debug SMALLINT NOT NULL DEFAULT 0,
|
||||
db_debug SMALLINT NOT NULL DEFAULT 0,
|
||||
-- is admin user
|
||||
admin SMALLINT NOT NULL DEFAULT 0,
|
||||
-- last login log
|
||||
last_login TIMESTAMP WITHOUT TIME ZONE,
|
||||
-- login error
|
||||
login_error_count INT DEFAULT 0,
|
||||
login_error_date_last TIMESTAMP WITHOUT TIME ZONE,
|
||||
login_error_date_first TIMESTAMP WITHOUT TIME ZONE,
|
||||
-- time locked
|
||||
lock_until TIMESTAMP WITHOUT TIME ZONE,
|
||||
lock_after TIMESTAMP WITHOUT TIME ZONE,
|
||||
-- password change
|
||||
password_change_date TIMESTAMP WITHOUT TIME ZONE, -- only when password is first set or changed
|
||||
password_change_interval INTERVAL, -- null if no change is needed, or d/m/y time interval
|
||||
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
|
||||
password_reset_uid VARCHAR, -- the uid to access the password reset page
|
||||
-- _GET login id for direct login
|
||||
login_user_id VARCHAR UNIQUE, -- the loginUserId, at least 32 chars
|
||||
login_user_id_set_date TIMESTAMP WITHOUT TIME ZONE, -- when above uid was set
|
||||
login_user_id_last_revalidate TIMESTAMP WITHOUT TIME ZONE, -- when the last login was done with user name and password
|
||||
login_user_id_valid_from TIMESTAMP WITHOUT TIME ZONE, -- if set, from when the above uid is valid
|
||||
login_user_id_valid_until TIMESTAMP WITHOUT TIME ZONE, -- if set, until when the above uid is valid
|
||||
login_user_id_revalidate_after INTERVAL, -- user must login to revalidated loginUserId after set days, 0 for forever
|
||||
login_user_id_locked SMALLINT DEFAULT 0, -- lock for loginUserId, but still allow normal login
|
||||
-- additional ACL json block
|
||||
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
||||
edit_user_id SERIAL PRIMARY KEY,
|
||||
connect_edit_user_id INT, -- possible reference to other user
|
||||
FOREIGN KEY (connect_edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_language_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_language_id) REFERENCES edit_language (edit_language_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_scheme_id INT,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
-- username/password
|
||||
username VARCHAR UNIQUE,
|
||||
password VARCHAR,
|
||||
-- name block
|
||||
first_name VARCHAR,
|
||||
last_name VARCHAR,
|
||||
first_name_furigana VARCHAR,
|
||||
last_name_furigana VARCHAR,
|
||||
-- email
|
||||
email VARCHAR,
|
||||
-- eanbled/deleted flag
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
deleted SMALLINT NOT NULL DEFAULT 0,
|
||||
-- general flags
|
||||
strict SMALLINT DEFAULT 0,
|
||||
locked SMALLINT DEFAULT 0,
|
||||
protected SMALLINT NOT NULL DEFAULT 0,
|
||||
-- legacy, debug flags
|
||||
debug SMALLINT NOT NULL DEFAULT 0,
|
||||
db_debug SMALLINT NOT NULL DEFAULT 0,
|
||||
-- is admin user
|
||||
admin SMALLINT NOT NULL DEFAULT 0,
|
||||
-- last login log
|
||||
last_login TIMESTAMP WITHOUT TIME ZONE,
|
||||
-- login error
|
||||
login_error_count INT DEFAULT 0,
|
||||
login_error_date_last TIMESTAMP WITHOUT TIME ZONE,
|
||||
login_error_date_first TIMESTAMP WITHOUT TIME ZONE,
|
||||
-- time locked
|
||||
lock_until TIMESTAMP WITHOUT TIME ZONE,
|
||||
lock_after TIMESTAMP WITHOUT TIME ZONE,
|
||||
-- password change
|
||||
password_change_date TIMESTAMP WITHOUT TIME ZONE, -- only when password is first set or changed
|
||||
password_change_interval INTERVAL, -- null if no change is needed, or d/m/y time interval
|
||||
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
|
||||
password_reset_uid VARCHAR, -- the uid to access the password reset page
|
||||
-- _GET login id for direct login
|
||||
login_user_id VARCHAR UNIQUE, -- the loginUserId, at least 32 chars
|
||||
login_user_id_set_date TIMESTAMP WITHOUT TIME ZONE, -- when above uid was set
|
||||
login_user_id_last_revalidate TIMESTAMP WITHOUT TIME ZONE, -- when the last login was done with user name and password
|
||||
login_user_id_valid_from TIMESTAMP WITHOUT TIME ZONE, -- if set, from when the above uid is valid
|
||||
login_user_id_valid_until TIMESTAMP WITHOUT TIME ZONE, -- if set, until when the above uid is valid
|
||||
login_user_id_revalidate_after INTERVAL, -- user must login to revalidated loginUserId after set days, 0 for forever
|
||||
login_user_id_locked SMALLINT DEFAULT 0, -- lock for loginUserId, but still allow normal login
|
||||
-- additional ACL json block
|
||||
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
-- create unique index
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_visible_group;
|
||||
CREATE TABLE edit_visible_group (
|
||||
edit_visible_group_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
flag VARCHAR
|
||||
edit_visible_group_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
flag VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE generic;
|
||||
CREATE TABLE generic (
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE,
|
||||
uid VARCHAR
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE,
|
||||
uid VARCHAR
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# create path
|
||||
path=$(pwd)"/"$0;
|
||||
@@ -10,6 +10,11 @@ TARGET_HOST_WEB="<user>@<host>";
|
||||
TMP_DIR=$LOCAL_BASE_DIR"/4dev/tmp/";
|
||||
tmpf_web=$TMP_DIR"sync.exclude.tmp";
|
||||
|
||||
if [ ! -d "$LOCAL_BASE_DIR" ]; then
|
||||
echo "Folder: $LOCAL_BASE_DIR not found";
|
||||
exit;
|
||||
fi;
|
||||
|
||||
# if vendor be sure group folder is +x
|
||||
chmod -R ug+rX ${LOCAL_DIR}/vender/
|
||||
|
||||
@@ -18,6 +23,7 @@ rm -f $tmpf_web;
|
||||
echo ".*.swp" >> $tmpf_web;
|
||||
echo "._*" >> $tmpf_web;
|
||||
echo ".DS_Store" >> $tmpf_web;
|
||||
echo ".user.ini" >> $tmpf_web;
|
||||
echo ".svn" >> $tmpf_web;
|
||||
echo ".svnignore" >> $tmpf_web;
|
||||
echo ".git" >> $tmpf_web;
|
||||
|
||||
40
4dev/tests/AAASetupData/CoreLibsAAASetupDataTest.php
Normal file
40
4dev/tests/AAASetupData/CoreLibsAAASetupDataTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test base setup
|
||||
* @testdox AAASetupData\AAASetupDataTest just setup BASE
|
||||
*/
|
||||
final class CoreLibsAAASetupDataTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Covers nothing
|
||||
*
|
||||
* @testdox Just setup BASE
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetupData(): void
|
||||
{
|
||||
if (!defined('BASE')) {
|
||||
define(
|
||||
'BASE',
|
||||
str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR,
|
||||
BASE,
|
||||
'BASE Path set check'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
1
4dev/tests/AAASetupData/includes
Symbolic link
1
4dev/tests/AAASetupData/includes
Symbolic link
@@ -0,0 +1 @@
|
||||
../Language/includes/
|
||||
1
4dev/tests/AAASetupData/log
Symbolic link
1
4dev/tests/AAASetupData/log
Symbolic link
@@ -0,0 +1 @@
|
||||
../Debug/log/
|
||||
@@ -7,6 +7,14 @@ namespace tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
/*
|
||||
Not yet covered tests:
|
||||
- loginGetLocale
|
||||
- loginGetHeaderColor
|
||||
- loginGetPages
|
||||
- loginGetEuid
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for ACL\Login
|
||||
* @coversDefaultClass \CoreLibs\ACL\Login
|
||||
@@ -60,13 +68,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
|
||||
// logger is always needed
|
||||
// define basic connection set valid and one invalid
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
self::$log = new \CoreLibs\Logging\Logging([
|
||||
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-ACL-Login-Test',
|
||||
'debug_all' => true,
|
||||
'echo_all' => false,
|
||||
'print_all' => true,
|
||||
'log_file_id' => 'CoreLibs-ACL-Login-Test',
|
||||
]);
|
||||
// test database we need to connect do, if not possible this test is skipped
|
||||
self::$db = new \CoreLibs\DB\IO(
|
||||
@@ -120,8 +125,6 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
// define('LOGIN_DB_SCHEMA', '');
|
||||
|
||||
// SHOULD SET
|
||||
// PASSWORD_MIN_LENGTH (d9)
|
||||
// PASSWORD_MAX_LENGTH (d255)
|
||||
// DEFAULT_ACL_LEVEL (d80)
|
||||
|
||||
// OPT:
|
||||
@@ -164,8 +167,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
// change_password, pw_username, pw_old_password, pw_new_password,
|
||||
// pw_new_password_confirm
|
||||
// 3[session]: override session set
|
||||
// 4[error] : expected error code, 0 for all ok, 3000 for login page view
|
||||
// note that 1000 (no db), 2000 (no session) must be tested too
|
||||
// 4[error] : expected error code, 0 for all ok, 100 for login page view
|
||||
// note that 1000 (no db), 2000 (no session), 3000 (options set error)
|
||||
// must be tested too
|
||||
// <1000 info, >=1000 critical error
|
||||
// 5[return] : expected return array, eg login_error code,
|
||||
// or other info data to match
|
||||
$tests = [
|
||||
@@ -177,7 +182,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -195,7 +200,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -218,7 +223,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -261,6 +266,8 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'GROUP_ACL_LEVEL' => -1,
|
||||
'PAGES_ACL_LEVEL' => [],
|
||||
'USER_ACL_LEVEL' => -1,
|
||||
'USER_ADDITIONAL_ACL' => [],
|
||||
'GROUP_ADDITIONAL_ACL' => [],
|
||||
'UNIT_UID' => [
|
||||
'AdminAccess' => 1,
|
||||
],
|
||||
@@ -274,6 +281,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'data' => [
|
||||
'test' => 'value',
|
||||
],
|
||||
'additional_acl' => []
|
||||
],
|
||||
],
|
||||
// 'UNIT_DEFAULT' => '',
|
||||
@@ -302,7 +310,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => '',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -323,7 +331,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -344,7 +352,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => '',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -365,7 +373,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1010,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -389,7 +397,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
// default password is plain text
|
||||
'login_error' => 1012,
|
||||
@@ -415,7 +423,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 106,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -440,7 +448,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 104,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -465,7 +473,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 105,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -514,7 +522,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -568,7 +576,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -594,7 +602,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -619,7 +627,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 108,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -755,7 +763,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1010,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -847,7 +855,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1101,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -903,7 +911,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -959,7 +967,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -986,7 +994,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -1106,13 +1114,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate', 'loginReadPageName', 'loginPrintLogin'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1206,7 +1229,11 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->loginSetMaxLoginErrorCount($mock_settings['max_login_error_count']);
|
||||
// temporary wrong password
|
||||
$_POST['login_password'] = 'wrong';
|
||||
for ($run = 1, $max_run = $login_mock->loginGetMaxLoginErrorCount(); $run <= $max_run; $run++) {
|
||||
for (
|
||||
$run = 1, $max_run = $login_mock->loginGetMaxLoginErrorCount();
|
||||
$run <= $max_run;
|
||||
$run++
|
||||
) {
|
||||
try {
|
||||
$login_mock->loginMainCall();
|
||||
} catch (\Exception $e) {
|
||||
@@ -1454,10 +1481,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
// print "AJAX: " . $login_mock->loginGetAjaxFlag() . "\n";
|
||||
// print "AJAX GLOBAL: " . ($GLOBALS['AJAX_PAGE'] ?? '{f}') . "\n";
|
||||
// print "Login error expext: " . ($expected['login_error'] ?? '{0}') . "\n";
|
||||
// if this is 3000, then we do further error checks
|
||||
// if this is 100, then we do further error checks
|
||||
if (
|
||||
$e->getCode() == 3000 ||
|
||||
!empty($_POST['login_exit']) && $_POST['login_exit'] == 3000
|
||||
$e->getCode() == 100 ||
|
||||
!empty($_POST['login_exit']) && $_POST['login_exit'] == 100
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$expected['login_error'],
|
||||
@@ -1729,7 +1756,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
20
|
||||
],
|
||||
'invalud search' => [
|
||||
'invalid search' => [
|
||||
12,
|
||||
'foo',
|
||||
[],
|
||||
@@ -1774,13 +1801,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
);
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1873,13 +1915,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
);
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1946,13 +2003,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
);
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -2027,13 +2099,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
);
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
1
4dev/tests/ACL/includes
Symbolic link
1
4dev/tests/ACL/includes
Symbolic link
@@ -0,0 +1 @@
|
||||
../AAASetupData/includes
|
||||
47
4dev/tests/Admin/CoreLibsAdminEditPageTest.php
Normal file
47
4dev/tests/Admin/CoreLibsAdminEditPageTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Admin\EditPage
|
||||
* @coversDefaultClass \CoreLibs\Admin\EditPage
|
||||
* @testdox \CoreLibs\Admin\EditPage method tests
|
||||
*/
|
||||
final class CoreLibsAdminEditPageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
if (!extension_loaded('pgsql')) {
|
||||
$this->markTestSkipped(
|
||||
'The PgSQL extension is not available.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Admin\EditPage Class tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminEditPage()
|
||||
{
|
||||
/* $this->assertTrue(true, 'ACL Login Tests not implemented');
|
||||
$this->markTestIncomplete(
|
||||
'ACL\Login Tests have not yet been implemented'
|
||||
); */
|
||||
$this->markTestSkipped('No implementation for Admin\EditPage at the moment');
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
334
4dev/tests/Check/CoreLibsCheckColorsTest.php
Normal file
334
4dev/tests/Check/CoreLibsCheckColorsTest.php
Normal file
@@ -0,0 +1,334 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\Colors
|
||||
* @coversDefaultClass \CoreLibs\Check\Colors
|
||||
* @testdox \CoreLibs\Check\Colors method tests
|
||||
*/
|
||||
final class CoreLibsCheckColorsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function validateColorProvider(): array
|
||||
{
|
||||
/*
|
||||
0: input color string
|
||||
1: flag (or flags to set)
|
||||
2: expected result (bool)
|
||||
*/
|
||||
return [
|
||||
// * hex
|
||||
'valid hex rgb, flag ALL (default)' => [
|
||||
'#ab12cd',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb, flag ALL' => [
|
||||
'#ab12cd',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb, flag HEX_RGB' => [
|
||||
'#ab12cd',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb, wrong flag' => [
|
||||
'#ab12cd',
|
||||
\CoreLibs\Check\Colors::RGB,
|
||||
false,
|
||||
],
|
||||
// error
|
||||
'invalid hex rgb A' => [
|
||||
'#ab12zz',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid hex rgb B' => [
|
||||
'#ZyQfo',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
// other valid hex checks
|
||||
'valid hex rgb, alt A' => [
|
||||
'#AB12cd',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * hax alpha
|
||||
'valid hex rgb alpha, flag ALL (default)' => [
|
||||
'#ab12cd12',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb alpha, flag ALL' => [
|
||||
'#ab12cd12',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb alpha, flag HEX_RGBA' => [
|
||||
'#ab12cd12',
|
||||
\CoreLibs\Check\Colors::HEX_RGBA,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb alpha, wrong flag' => [
|
||||
'#ab12cd12',
|
||||
\CoreLibs\Check\Colors::RGB,
|
||||
false,
|
||||
],
|
||||
// error
|
||||
'invalid hex rgb alpha A' => [
|
||||
'#ab12dd1',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid hex rgb alpha B' => [
|
||||
'#ab12ddzz',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'valid hex rgb alpha, alt A' => [
|
||||
'#ab12cdEE',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * rgb
|
||||
'valid rgb, flag ALL (default)' => [
|
||||
'rgb(255, 10, 20)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid rgb, flag ALL' => [
|
||||
'rgb(255, 10, 20)',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid rgb, flag RGB' => [
|
||||
'rgb(255, 10, 20)',
|
||||
\CoreLibs\Check\Colors::RGB,
|
||||
true,
|
||||
],
|
||||
'valid rgb, wrong flag' => [
|
||||
'rgb(255, 10, 20)',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
false,
|
||||
],
|
||||
// error
|
||||
'invalid rgb A' => [
|
||||
'rgb(356, 10, 20)',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
// other valid rgb conbinations
|
||||
'valid rgb, alt A (percent)' => [
|
||||
'rgb(100%, 10%, 20%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// TODO check all % and non percent combinations
|
||||
'valid rgb, alt B (percent, mix)' => [
|
||||
'rgb(100%, 10, 40)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * rgb alpha
|
||||
'valid rgba, flag ALL (default)' => [
|
||||
'rgba(255, 10, 20, 0.5)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid rgba, flag ALL' => [
|
||||
'rgba(255, 10, 20, 0.5)',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid rgba, flag RGB' => [
|
||||
'rgba(255, 10, 20, 0.5)',
|
||||
\CoreLibs\Check\Colors::RGBA,
|
||||
true,
|
||||
],
|
||||
'valid rgba, wrong flag' => [
|
||||
'rgba(255, 10, 20, 0.5)',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
false,
|
||||
],
|
||||
// error
|
||||
'invalid rgba A' => [
|
||||
'rgba(356, 10, 20, 0.5)',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
// other valid rgba combinations
|
||||
'valid rgba, alt A (percent)' => [
|
||||
'rgba(100%, 10%, 20%, 0.5)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// TODO check all % and non percent combinations
|
||||
'valid rgba, alt B (percent, mix)' => [
|
||||
'rgba(100%, 10, 40, 0.5)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// TODO check all % and non percent combinations with percent transparent
|
||||
'valid rgba, alt C (percent transparent)' => [
|
||||
'rgba(100%, 10%, 20%, 50%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
/*
|
||||
// hsl
|
||||
'hsl(100, 50%, 60%)',
|
||||
'hsl(100, 50.5%, 60.5%)',
|
||||
'hsla(100, 50%, 60%)',
|
||||
'hsla(100, 50.5%, 60.5%)',
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
'hsla(100, 50.5%, 60.5%, 0.5)',
|
||||
'hsla(100, 50%, 60%, 50%)',
|
||||
'hsla(100, 50.5%, 60.5%, 50%)',
|
||||
*/
|
||||
// * hsl
|
||||
'valid hsl, flag ALL (default)' => [
|
||||
'hsl(100, 50%, 60%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hsl, flag ALL' => [
|
||||
'hsl(100, 50%, 60%)',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid hsl, flag RGB' => [
|
||||
'hsl(100, 50%, 60%)',
|
||||
\CoreLibs\Check\Colors::HSL,
|
||||
true,
|
||||
],
|
||||
'valid hsl, wrong flag' => [
|
||||
'hsl(100, 50%, 60%)',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
false,
|
||||
],
|
||||
'invalid hsl A' => [
|
||||
'hsl(500, 50%, 60%)',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'valid hsl, alt A' => [
|
||||
'hsl(100, 50.5%, 60.5%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * hsl alpha
|
||||
'valid hsla, flag ALL (default)' => [
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hsla, flag ALL' => [
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid hsla, flag RGB' => [
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
\CoreLibs\Check\Colors::HSLA,
|
||||
true,
|
||||
],
|
||||
'valid hsla, wrong flag' => [
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
false,
|
||||
],
|
||||
'invalid hsla A' => [
|
||||
'hsla(500, 50%, 60%, 0.5)',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'valid hsla, alt A (percent alpha' => [
|
||||
'hsla(100, 50%, 60%, 50%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hsla, alt A (percent alpha' => [
|
||||
'hsla(100, 50.5%, 60.5%, 50%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * combined flag checks
|
||||
'valid rgb, flag RGB|RGBA' => [
|
||||
'rgb(100%, 10%, 20%)',
|
||||
\CoreLibs\Check\Colors::RGB | \CoreLibs\Check\Colors::RGBA,
|
||||
true,
|
||||
],
|
||||
// TODO other combined flag checks all combinations
|
||||
// * invalid string
|
||||
'invalid string A' => [
|
||||
'invalid string',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid string B' => [
|
||||
'(hsla(100, 100, 100))',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid string C' => [
|
||||
'hsla(100, 100, 100',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::validateColor
|
||||
* @dataProvider validateColorProvider
|
||||
* @testdox validateColor $input with flags $flags be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param int|null $flags
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateColor(string $input, ?int $flags, bool $expected)
|
||||
{
|
||||
if ($flags === null) {
|
||||
$result = \CoreLibs\Check\Colors::validateColor($input);
|
||||
} else {
|
||||
$result = \CoreLibs\Check\Colors::validateColor($input, $flags);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::validateColor
|
||||
* @testWith [99]
|
||||
* @testdox Check Exception throw for $flag
|
||||
*
|
||||
* @param int $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateColorException(int $flag): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
\CoreLibs\Check\Colors::validateColor('#ffffff', $flag);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -31,6 +31,7 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
4,
|
||||
'b',
|
||||
'c' => 'test',
|
||||
'single' => 'single',
|
||||
'same' => 'same',
|
||||
'deep' => [
|
||||
'sub' => [
|
||||
@@ -107,6 +108,13 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
*/
|
||||
public function arraySearchRecursiveAllProvider(): array
|
||||
{
|
||||
/*
|
||||
0: $needle,
|
||||
1: array $input,
|
||||
2: ?string $key_search_for,
|
||||
3: bool $flag,
|
||||
4: array $expected
|
||||
*/
|
||||
return [
|
||||
'find value' => [
|
||||
0 => 'bar',
|
||||
@@ -172,6 +180,13 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
*/
|
||||
public function arraySearchSimpleProvider(): array
|
||||
{
|
||||
/*
|
||||
0: array $input,
|
||||
1: $key,
|
||||
2: $value,
|
||||
3: bool $flag,
|
||||
4: bool $expected
|
||||
*/
|
||||
return [
|
||||
'key/value exist' => [
|
||||
0 => self::$array,
|
||||
@@ -274,6 +289,188 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arraySearchKeyProvider(): array
|
||||
{
|
||||
/*
|
||||
0: search in array
|
||||
1: search keys
|
||||
2: flat flag
|
||||
3: prefix flag
|
||||
4: expected array
|
||||
*/
|
||||
return [
|
||||
// single
|
||||
'find single, standard' => [
|
||||
0 => self::$array,
|
||||
1 => ['single'],
|
||||
2 => null,
|
||||
3 => null,
|
||||
4 => [
|
||||
0 => [
|
||||
'value' => 'single',
|
||||
'path' => ['single'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'find single, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['single'],
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'single' => [
|
||||
0 => [
|
||||
'value' => 'single',
|
||||
'path' => ['single'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'find single, flat' => [
|
||||
0 => self::$array,
|
||||
1 => ['single'],
|
||||
2 => true,
|
||||
3 => null,
|
||||
4 => [
|
||||
'single',
|
||||
],
|
||||
],
|
||||
'find single, flat, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['single'],
|
||||
2 => true,
|
||||
3 => true,
|
||||
4 => [
|
||||
'single' => [
|
||||
'single',
|
||||
],
|
||||
],
|
||||
],
|
||||
// not found
|
||||
'not found, standard' => [
|
||||
0 => self::$array,
|
||||
1 => ['NOT FOUND'],
|
||||
2 => null,
|
||||
3 => null,
|
||||
4 => [],
|
||||
],
|
||||
'not found, standard, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['NOT FOUND'],
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'NOT FOUND' => [],
|
||||
],
|
||||
],
|
||||
'not found, flat' => [
|
||||
0 => self::$array,
|
||||
1 => ['NOT FOUND'],
|
||||
2 => true,
|
||||
3 => null,
|
||||
4 => [],
|
||||
],
|
||||
'not found, flat, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['NOT FOUND'],
|
||||
2 => true,
|
||||
3 => true,
|
||||
4 => [
|
||||
'NOT FOUND' => [],
|
||||
],
|
||||
],
|
||||
// multi
|
||||
'multiple found, standard' => [
|
||||
0 => self::$array,
|
||||
1 => ['same'],
|
||||
2 => null,
|
||||
3 => null,
|
||||
4 => [
|
||||
[
|
||||
'value' => 'same',
|
||||
'path' => ['a', 'same', ],
|
||||
],
|
||||
[
|
||||
'value' => 'same',
|
||||
'path' => ['same', ],
|
||||
],
|
||||
[
|
||||
'value' => 'same',
|
||||
'path' => ['deep', 'sub', 'same', ],
|
||||
],
|
||||
]
|
||||
],
|
||||
'multiple found, flat' => [
|
||||
0 => self::$array,
|
||||
1 => ['same'],
|
||||
2 => true,
|
||||
3 => null,
|
||||
4 => ['same', 'same', 'same', ],
|
||||
],
|
||||
// search with multiple
|
||||
'search multiple, standard' => [
|
||||
0 => self::$array,
|
||||
1 => ['single', 'nested'],
|
||||
2 => null,
|
||||
3 => null,
|
||||
4 => [
|
||||
[
|
||||
'value' => 'single',
|
||||
'path' => ['single'],
|
||||
],
|
||||
[
|
||||
'value' => 'bar',
|
||||
'path' => ['deep', 'sub', 'nested', ],
|
||||
],
|
||||
],
|
||||
],
|
||||
'search multiple, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['single', 'nested'],
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'single' => [
|
||||
[
|
||||
'value' => 'single',
|
||||
'path' => ['single'],
|
||||
],
|
||||
],
|
||||
'nested' => [
|
||||
[
|
||||
'value' => 'bar',
|
||||
'path' => ['deep', 'sub', 'nested', ],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'search multiple, flat' => [
|
||||
0 => self::$array,
|
||||
1 => ['single', 'nested'],
|
||||
2 => true,
|
||||
3 => null,
|
||||
4 => [
|
||||
'single', 'bar',
|
||||
],
|
||||
],
|
||||
'search multiple, flat, prefix' => [
|
||||
0 => self::$array,
|
||||
1 => ['single', 'nested'],
|
||||
2 => true,
|
||||
3 => true,
|
||||
4 => [
|
||||
'single' => ['single', ],
|
||||
'nested' => ['bar', ],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* provides array listing for the merge test
|
||||
*
|
||||
@@ -321,17 +518,20 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
return [
|
||||
// error <2 arguments
|
||||
'too view arguments' => [
|
||||
'ArgumentCountError',
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1]
|
||||
],
|
||||
// error <2 arrays
|
||||
'only one array' => [
|
||||
'ArgumentCountError',
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1],
|
||||
true,
|
||||
],
|
||||
// error element is not array
|
||||
'non array between array' => [
|
||||
'TypeError',
|
||||
'arrayMergeRecursive encountered a non array argument',
|
||||
[1],
|
||||
'string',
|
||||
@@ -665,7 +865,7 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
*
|
||||
* @param array $input
|
||||
* @param string|int $key
|
||||
* @param string|int $value
|
||||
* @param string|int|bool $value
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
@@ -677,6 +877,44 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers::arraySearchKey
|
||||
* @dataProvider arraySearchKeyProvider
|
||||
* @testdox arraySearchKey Search array with keys and flat: $flat, prefix: $prefix [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $needles
|
||||
* @param bool|null $flat
|
||||
* @param bool|null $prefix
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySearchKey(
|
||||
array $input,
|
||||
array $needles,
|
||||
?bool $flat,
|
||||
?bool $prefix,
|
||||
array $expected
|
||||
): void {
|
||||
if ($flat === null && $prefix === null) {
|
||||
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles);
|
||||
} elseif ($flat === null) {
|
||||
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, prefix: $prefix);
|
||||
} elseif ($prefix === null) {
|
||||
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, flat: $flat);
|
||||
} else {
|
||||
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, $flat, $prefix);
|
||||
}
|
||||
// print "E: " . print_r($expected, true) . "\n";
|
||||
// print "R: " . print_r($result, true) . "\n";
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -712,12 +950,25 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
*/
|
||||
public function testArrayMergeRecursiveWarningA(): void
|
||||
{
|
||||
// set_error_handler(
|
||||
// static function (int $errno, string $errstr): never {
|
||||
// throw new Exception($errstr, $errno);
|
||||
// },
|
||||
// E_USER_WARNING
|
||||
// );
|
||||
|
||||
$arrays = func_get_args();
|
||||
// first is expected warning
|
||||
$exception = array_shift($arrays);
|
||||
$warning = array_shift($arrays);
|
||||
$this->expectWarning();
|
||||
$this->expectWarningMessage($warning);
|
||||
|
||||
// phpunit 10.0 compatible
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionMessage($warning);
|
||||
|
||||
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
|
||||
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,45 +309,73 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'2020-12-12',
|
||||
'2021-12-12',
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'dates equal' => [
|
||||
'2020-12-12',
|
||||
'2020-12-12',
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'second date smaller' => [
|
||||
'2021-12-12',
|
||||
'2020-12-12',
|
||||
1
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'dates equal with different time' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 13:13:13',
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'invalid dates --' => [
|
||||
'--',
|
||||
'--',
|
||||
false
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
1,
|
||||
],
|
||||
'empty dates' => [
|
||||
'',
|
||||
'',
|
||||
false
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
1
|
||||
],
|
||||
'invalid dates' => [
|
||||
'not a date',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
2
|
||||
],
|
||||
'invalid end date' => [
|
||||
'1990-01-01',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
3
|
||||
],
|
||||
'out of bound dates' => [
|
||||
'1900-1-1',
|
||||
'9999-12-31',
|
||||
-1
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function dateTimeCompareProvider(): array
|
||||
{
|
||||
return [
|
||||
@@ -355,51 +383,85 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
'2020-12-12',
|
||||
'2021-12-12',
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'dates equal no timestamp' => [
|
||||
'2020-12-12',
|
||||
'2020-12-12',
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'second date smaller no timestamp' => [
|
||||
'2021-12-12',
|
||||
'2020-12-12',
|
||||
1
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'date equal first time smaller' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 13:13:13',
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'date equal time equal' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 12:12:12',
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'date equal second time smaller' => [
|
||||
'2020-12-12 13:13:13',
|
||||
'2020-12-12 12:12:12',
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
'valid date invalid time' => [
|
||||
'2020-12-12 13:99:13',
|
||||
'2020-12-12 12:12:99',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
2
|
||||
],
|
||||
'valid date invalid end time' => [
|
||||
'2020-12-12 13:12:13',
|
||||
'2020-12-12 12:12:99',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
3
|
||||
],
|
||||
'invalid datetimes --' => [
|
||||
'--',
|
||||
'--',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
1
|
||||
],
|
||||
'empty datetimess' => [
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
1
|
||||
],
|
||||
'invalid datetimes' => [
|
||||
'invalid date times' => [
|
||||
'not a date',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
2
|
||||
],
|
||||
'invalid end date time' => [
|
||||
'1990-01-01 12:12:12',
|
||||
'not a date either',
|
||||
false,
|
||||
'UnexpectedValueException',
|
||||
3
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -458,6 +520,47 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dateRangeHasWeekendProvider(): array
|
||||
{
|
||||
return [
|
||||
'no weekend' => [
|
||||
'2023-07-03',
|
||||
'2023-07-04',
|
||||
false
|
||||
],
|
||||
'start weekend sat' => [
|
||||
'2023-07-01',
|
||||
'2023-07-04',
|
||||
true
|
||||
],
|
||||
'start weekend sun' => [
|
||||
'2023-07-02',
|
||||
'2023-07-04',
|
||||
true
|
||||
],
|
||||
'end weekend sat' => [
|
||||
'2023-07-03',
|
||||
'2023-07-08',
|
||||
true
|
||||
],
|
||||
'end weekend sun' => [
|
||||
'2023-07-03',
|
||||
'2023-07-09',
|
||||
true
|
||||
],
|
||||
'long period > 6 days' => [
|
||||
'2023-07-03',
|
||||
'2023-07-27',
|
||||
true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* date string convert test
|
||||
*
|
||||
@@ -573,10 +676,21 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
* @param string $input_a
|
||||
* @param string $input_b
|
||||
* @param int|bool $expected
|
||||
* @param string|null $exception
|
||||
* @param int|null $exception_code
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareDate(string $input_a, string $input_b, $expected): void
|
||||
{
|
||||
public function testCompareDate(
|
||||
string $input_a,
|
||||
string $input_b,
|
||||
int|bool $expected,
|
||||
?string $exception,
|
||||
?int $exception_code
|
||||
): void {
|
||||
if ($expected === false) {
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionCode($exception_code);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::compareDate($input_a, $input_b)
|
||||
@@ -593,10 +707,21 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
* @param string $input_a
|
||||
* @param string $input_b
|
||||
* @param int|bool $expected
|
||||
* @param string|null $exception
|
||||
* @param int|null $exception_code
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareDateTime(string $input_a, string $input_b, $expected): void
|
||||
{
|
||||
public function testCompareDateTime(
|
||||
string $input_a,
|
||||
string $input_b,
|
||||
int|bool $expected,
|
||||
?string $exception,
|
||||
?int $exception_code
|
||||
): void {
|
||||
if ($expected === false) {
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionCode($exception_code);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
||||
@@ -780,6 +905,29 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::dateRangeHasWeekend
|
||||
* @dataProvider dateRangeHasWeekendProvider
|
||||
* @testdox dateRangeHasWeekend $start_date and $end_date are expected weekend $expected [$_dataName]
|
||||
*
|
||||
* @param string $start_date
|
||||
* @param string $end_date
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testDateRangeHasWeekend(
|
||||
string $start_date,
|
||||
string $end_date,
|
||||
bool $expected
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::dateRangeHasWeekend($start_date, $end_date)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -16,7 +16,6 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsConvertByteTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -24,7 +23,31 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
*/
|
||||
public function byteProvider(): array
|
||||
{
|
||||
/*
|
||||
* 0: input string
|
||||
* 1: default flags
|
||||
* 2: BYTE_FORMAT_SI
|
||||
* 3: BYTE_FORMAT_NOSPACE
|
||||
* 4: BYTE_FORMAT_ADJUST
|
||||
* 5: BYTE_FORMAT_SI | BYTE_FORMAT_NOSPACE
|
||||
*/
|
||||
return [
|
||||
'string number' => [
|
||||
0 => '1024',
|
||||
1 => '1 KB',
|
||||
2 => '1.02 KiB',
|
||||
3 => '1KB',
|
||||
4 => '1.00 KB',
|
||||
5 => '1.02KiB',
|
||||
],
|
||||
'invalud string number' => [
|
||||
0 => '1024 MB',
|
||||
1 => '1024 MB',
|
||||
2 => '1024 MB',
|
||||
3 => '1024 MB',
|
||||
4 => '1024 MB',
|
||||
5 => '1024 MB',
|
||||
],
|
||||
'negative number' => [
|
||||
0 => -123123123,
|
||||
1 => '-117.42 MB',
|
||||
@@ -217,6 +240,41 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
\CoreLibs\Convert\Byte::stringByteFormat($input, \CoreLibs\Convert\Byte::BYTE_FORMAT_SI)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptions tests
|
||||
*
|
||||
* @covers ::humanReadableByteFormat
|
||||
* @testWith [99]
|
||||
* @testdox Test exception for humanReadableByteFormat with flag $flag
|
||||
*
|
||||
* @param int $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testHumanReadableByteFormatException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat(12, $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptions tests
|
||||
* can only be 4, try 1,2 and over
|
||||
*
|
||||
* @covers ::stringByteFormat
|
||||
* @testWith [1]
|
||||
* [2]
|
||||
* [99]
|
||||
* @testdox Test exception for stringByteFormat with flag $flag
|
||||
*
|
||||
* @param int $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testStringByteFormatException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
\CoreLibs\Convert\Byte::stringByteFormat(12, $flag);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
503
4dev/tests/Convert/CoreLibsConvertColorsTest.php
Normal file
503
4dev/tests/Convert/CoreLibsConvertColorsTest.php
Normal file
@@ -0,0 +1,503 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Colors
|
||||
* @coversDefaultClass \CoreLibs\Convert\Colors
|
||||
* @testdox \CoreLibs\Convert\Colors method tests
|
||||
*/
|
||||
final class CoreLibsConvertColorsTest extends TestCase
|
||||
{
|
||||
// convert list
|
||||
public static $colors = [];
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hexColorProvider(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
0 => 10,
|
||||
1 => 100,
|
||||
2 => 200,
|
||||
3 => '#0a64c8',
|
||||
4 => '0a64c8'
|
||||
],
|
||||
'gray' => [
|
||||
0 => 12,
|
||||
1 => 12,
|
||||
2 => 12,
|
||||
3 => '#0c0c0c',
|
||||
4 => '0c0c0c',
|
||||
],
|
||||
'black' => [
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
2 => 0,
|
||||
3 => '#000000',
|
||||
4 => '000000',
|
||||
],
|
||||
'white' => [
|
||||
0 => 255,
|
||||
1 => 255,
|
||||
2 => 255,
|
||||
3 => '#ffffff',
|
||||
4 => 'ffffff',
|
||||
],
|
||||
'invalid color red & green' => [
|
||||
0 => -12,
|
||||
1 => 300,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color red ' => [
|
||||
0 => -12,
|
||||
1 => 12,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color green ' => [
|
||||
0 => 12,
|
||||
1 => -12,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color blue ' => [
|
||||
0 => 12,
|
||||
1 => 12,
|
||||
2 => -12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hex2rgbColorProvider(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
0 => '#0a64c8',
|
||||
1 => ['r' => 10, 'g' => 100, 'b' => 200],
|
||||
2 => '10,100,200',
|
||||
3 => ';',
|
||||
4 => '10;100;200',
|
||||
],
|
||||
'gray, long' => [
|
||||
0 => '0c0c0c',
|
||||
1 => ['r' => 12, 'g' => 12, 'b' => 12],
|
||||
2 => '12,12,12',
|
||||
3 => ';',
|
||||
4 => '12;12;12',
|
||||
],
|
||||
'gray, short' => [
|
||||
0 => 'ccc',
|
||||
1 => ['r' => 204, 'g' => 204, 'b' => 204],
|
||||
2 => '204,204,204',
|
||||
3 => ';',
|
||||
4 => '204;204;204',
|
||||
],
|
||||
'hex string with #' => [
|
||||
0 => '#0c0c0c',
|
||||
1 => ['r' => 12, 'g' => 12, 'b' => 12],
|
||||
2 => '12,12,12',
|
||||
3 => ';',
|
||||
4 => '12;12;12',
|
||||
],
|
||||
'a too long hex string' => [
|
||||
0 => '#0c0c0c0c',
|
||||
1 => false,
|
||||
2 => false,
|
||||
3 => ';',
|
||||
4 => false,
|
||||
],
|
||||
'a too short hex string' => [
|
||||
0 => '0c0c',
|
||||
1 => false,
|
||||
2 => false,
|
||||
3 => ';',
|
||||
4 => false,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hslAndhsbList(): array
|
||||
{
|
||||
// if hsb_from or hsl_from is set, this will be used in hsb/hsl convert
|
||||
// hsb_rgb is used for adjusted rgb valus due to round error to in
|
||||
return [
|
||||
'valid gray' => [
|
||||
'rgb' => [12, 12, 12],
|
||||
'hsb' => [0, 0, 5],
|
||||
'hsb_rgb' => [13, 13, 13], // should be rgb, but rounding in this
|
||||
'hsl' => [0.0, 0.0, 4.7],
|
||||
'valid' => true,
|
||||
],
|
||||
'valid color' => [
|
||||
'rgb' => [10, 100, 200],
|
||||
'hsb' => [212, 95, 78.0],
|
||||
'hsb_rgb' => [10, 98, 199], // should be rgb, but rounding error
|
||||
'hsl' => [211.6, 90.5, 41.2],
|
||||
'valid' => true,
|
||||
],
|
||||
// hsg/hsl with 360 which is seen as 0
|
||||
'valid color hue 360' => [
|
||||
'rgb' => [200, 10, 10],
|
||||
'hsb' => [0, 95, 78.0],
|
||||
'hsb_from' => [360, 95, 78.0],
|
||||
'hsb_rgb' => [199, 10, 10], // should be rgb, but rounding error
|
||||
'hsl' => [0.0, 90.5, 41.2],
|
||||
'hsl_from' => [360.0, 90.5, 41.2],
|
||||
'valid' => true,
|
||||
],
|
||||
// invalid values
|
||||
'invalid color r/h/h low' => [
|
||||
'rgb' => [-1, 12, 12],
|
||||
'hsb' => [-1, 50, 50],
|
||||
'hsl' => [-1, 50, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color r/h/h high' => [
|
||||
'rgb' => [256, 12, 12],
|
||||
'hsb' => [361, 50, 50],
|
||||
'hsl' => [361, 50, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color g/s/s low' => [
|
||||
'rgb' => [12, -1, 12],
|
||||
'hsb' => [1, -1, 50],
|
||||
'hsl' => [1, -1, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color g/s/s high' => [
|
||||
'rgb' => [12, 256, 12],
|
||||
'hsb' => [1, 101, 50],
|
||||
'hsl' => [1, 101, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color b/b/l low' => [
|
||||
'rgb' => [12, 12, -1],
|
||||
'hsb' => [1, 50, -1],
|
||||
'hsl' => [1, 50, -1],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color b/b/l high' => [
|
||||
'rgb' => [12, 12, 256],
|
||||
'hsb' => [1, 50, 101],
|
||||
'hsl' => [1, 50, 101],
|
||||
'valid' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hsbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', rgb to hsb'] = [
|
||||
0 => $values['rgb'][0],
|
||||
1 => $values['rgb'][1],
|
||||
2 => $values['rgb'][2],
|
||||
3 => $values['valid'] ? $values['hsb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsb2rgbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', hsb to rgb'] = [
|
||||
0 => $values['hsb_from'][0] ?? $values['hsb'][0],
|
||||
1 => $values['hsb_from'][1] ?? $values['hsb'][1],
|
||||
2 => $values['hsb_from'][2] ?? $values['hsb'][2],
|
||||
3 => $values['valid'] ? $values['hsb_rgb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hslColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', rgb to hsl'] = [
|
||||
0 => $values['rgb'][0],
|
||||
1 => $values['rgb'][1],
|
||||
2 => $values['rgb'][2],
|
||||
3 => $values['valid'] ? $values['hsl'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsl2rgbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', hsl to rgb'] = [
|
||||
0 => $values['hsl_from'][0] ?? $values['hsl'][0],
|
||||
1 => $values['hsl_from'][1] ?? $values['hsl'][1],
|
||||
2 => $values['hsl_from'][2] ?? $values['hsl'][2],
|
||||
3 => $values['valid'] ? $values['rgb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* TODO: add cross convert check
|
||||
*
|
||||
* @covers ::rgb2hex
|
||||
* @dataProvider rgb2hexColorProvider
|
||||
* @testdox rgb2hex $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input_r
|
||||
* @param int $input_g
|
||||
* @param int $input_b
|
||||
* @param string|bool $expected_hash
|
||||
* @param string|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hex(
|
||||
int $input_r,
|
||||
int $input_g,
|
||||
int $input_b,
|
||||
string|bool $expected_hash,
|
||||
string|bool $expected
|
||||
) {
|
||||
// if expected hash is or expected is false, we need to check for
|
||||
// LengthException
|
||||
if ($expected_hash === false || $expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
}
|
||||
// with #
|
||||
$this->assertEquals(
|
||||
$expected_hash,
|
||||
\CoreLibs\Convert\Colors::rgb2hex($input_r, $input_g, $input_b)
|
||||
);
|
||||
// without #
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hex($input_r, $input_g, $input_b, false)
|
||||
);
|
||||
// cross convert must match
|
||||
// $rgb = \CoreLibs\Convert\Colors::hex2rgb($expected_hash);
|
||||
// if ($rgb === false) {
|
||||
// $rgb = [
|
||||
// 'r' => $input_r,
|
||||
// 'g' => $input_g,
|
||||
// 'b' => $input_b,
|
||||
// ];
|
||||
// }
|
||||
// $this->assertEquals(
|
||||
// $expected_hash,
|
||||
// \CoreLibs\Convert\Colors::rgb2hex($rgb['r'], $rgb['g'], $rgb['b'])
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hex2rgb
|
||||
* @dataProvider hex2rgbColorProvider
|
||||
* @testdox hex2rgb $input will be $expected, $expected_str str[,], $expected_str_sep str[$separator] [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param array|bool $expected
|
||||
* @param string|bool $expected_str
|
||||
* @param string $separator
|
||||
* @param string|bool $expected_str_sep
|
||||
* @return void
|
||||
*/
|
||||
public function testHex2rgb(
|
||||
string $input,
|
||||
array|bool $expected,
|
||||
string|bool $expected_str,
|
||||
string $separator,
|
||||
string|bool $expected_str_sep
|
||||
): void {
|
||||
if ($expected === false || $expected_str === false || $expected_str_sep === false) {
|
||||
$hex_string = preg_replace("/[^0-9A-Fa-f]/", '', $input);
|
||||
if (!is_string($hex_string)) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
} else {
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
}
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_str,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input, true)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_str_sep,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input, true, $separator)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsb
|
||||
* @dataProvider rgb2hsbColorProvider
|
||||
* @testdox rgb2hsb $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
* @param integer $input_g
|
||||
* @param integer $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hsb(int $input_r, int $input_g, int $input_b, array|bool $expected): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsb($input_r, $input_g, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsb2rgb
|
||||
* @dataProvider hsb2rgbColorProvider
|
||||
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param float $input_h
|
||||
* @param float $input_s
|
||||
* @param float $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, array|bool $expected): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
$expected = [];
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsb2rgb($input_h, $input_s, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsl
|
||||
* @dataProvider rgb2hslColorProvider
|
||||
* @testdox rgb2hsl $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
* @param integer $input_g
|
||||
* @param integer $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hsl(int $input_r, int $input_g, int $input_b, array|bool $expected): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsl($input_r, $input_g, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsl2rgb
|
||||
* @dataProvider hsl2rgbColorProvider
|
||||
* @testdox hsl2rgb $input_h,$input_s,$input_l will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer|float $input_h
|
||||
* @param integer $input_s
|
||||
* @param integer $input_l
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsl2rgb(int|float $input_h, float $input_s, float $input_l, array|bool $expected): void
|
||||
{
|
||||
if ($expected === false) {
|
||||
$this->expectException(\LengthException::class);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsl2rgb($input_h, $input_s, $input_l)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* edge case check hsl/hsb and hue 360 (= 0)
|
||||
*
|
||||
* @covers ::hsl2rgb
|
||||
* @covers ::hsb2rgb
|
||||
* @testdox hsl2rgb/hsb2rgb hue 360 valid check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHslHsb360hue(): void
|
||||
{
|
||||
$this->assertIsArray(
|
||||
\CoreLibs\Convert\Colors::hsl2rgb(360.0, 90.5, 41.2),
|
||||
'HSL to RGB with 360 hue'
|
||||
);
|
||||
$this->assertIsArray(
|
||||
\CoreLibs\Convert\Colors::hsb2rgb(360, 95, 78.0),
|
||||
'HSB to RGB with 360 hue'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -16,7 +16,7 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
/**
|
||||
* test list for json convert tests
|
||||
*
|
||||
* @return array
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function jsonProvider(): array
|
||||
{
|
||||
@@ -54,10 +54,36 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function jsonArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid json' => [
|
||||
[
|
||||
'm' => 2,
|
||||
'f' => 'sub_2'
|
||||
],
|
||||
'{"m":2,"f":"sub_2"}',
|
||||
],
|
||||
'empty json array' => [
|
||||
[],
|
||||
'[]'
|
||||
],
|
||||
'empty json hash' => [
|
||||
['' => ''],
|
||||
'{"":""}'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* json error list
|
||||
*
|
||||
* @return array JSON error list
|
||||
* @return array<mixed> JSON error list
|
||||
*/
|
||||
public function jsonErrorProvider(): array
|
||||
{
|
||||
@@ -127,7 +153,7 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param bool $flag
|
||||
* @param array $expected
|
||||
* @param array<mixed> $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonConvertToArray(?string $input, bool $flag, array $expected): void
|
||||
@@ -146,7 +172,8 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
* @testdox jsonGetLastError $input will be $expected_i/$expected_s [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected
|
||||
* @param int $expected_i
|
||||
* @param string $expected_s
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonGetLastError(?string $input, int $expected_i, string $expected_s): void
|
||||
@@ -161,6 +188,25 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
\CoreLibs\Convert\Json::jsonGetLastError(true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::jsonConvertArrayTo
|
||||
* @dataProvider jsonArrayProvider
|
||||
* @testdox jsonConvertArrayTo $input (Override: $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param array<mixed> $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonConvertArrayto(array $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Json::jsonConvertArrayTo($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
657
4dev/tests/Convert/CoreLibsConvertSetVarTypeNullTest.php
Normal file
657
4dev/tests/Convert/CoreLibsConvertSetVarTypeNullTest.php
Normal file
@@ -0,0 +1,657 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Convert\SetVarTypeNull;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Strings
|
||||
* @coversDefaultClass \CoreLibs\Convert\SetVarTypeNull
|
||||
* @testdox \CoreLibs\Convert\SetVarTypeNull method tests
|
||||
*/
|
||||
final class CoreLibsConvertSetVarTypeNullTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'empty string' => [
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'filled string' => [
|
||||
'string',
|
||||
null,
|
||||
'string'
|
||||
],
|
||||
'valid string, override set' => [
|
||||
'string',
|
||||
'override',
|
||||
'string'
|
||||
],
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
'1'
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'1'
|
||||
],
|
||||
'array, override set' => [
|
||||
[1, 2],
|
||||
null,
|
||||
null
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setStr
|
||||
* @dataProvider varSetTypeStringProvider
|
||||
* @testdox setStr $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string|null $default
|
||||
* @param string|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetString(mixed $input, ?string $default, ?string $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setStr($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsString($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'empty string' => [
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'filled string' => [
|
||||
'string',
|
||||
null,
|
||||
'string'
|
||||
],
|
||||
'valid string, override set' => [
|
||||
'string',
|
||||
'override',
|
||||
'string'
|
||||
],
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
'1'
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'1'
|
||||
],
|
||||
'float, no override' => [
|
||||
1.5,
|
||||
null,
|
||||
'1.5'
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
'function',
|
||||
'function'
|
||||
],
|
||||
'function, no override' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
null,
|
||||
null
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
'hex',
|
||||
'85'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeStr
|
||||
* @dataProvider varMakeTypeStringProvider
|
||||
* @testdox makeStr $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string|null $default
|
||||
* @param string|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeString(mixed $input, ?string $default, ?string $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::makeStr($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsString($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeIntProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
-1,
|
||||
1
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
null
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setInt
|
||||
* @dataProvider varSetTypeIntProvider
|
||||
* @testdox setInt $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param int|null $default
|
||||
* @param int|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetInt(mixed $input, ?int $default, ?int $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setInt($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsInt($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeIntProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
-1,
|
||||
1
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
-1,
|
||||
0
|
||||
],
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
'function, no override ' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
null,
|
||||
null
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
-1,
|
||||
85
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeInt
|
||||
* @dataProvider varMakeTypeIntProvider
|
||||
* @testdox makeInt $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param int|null $default
|
||||
* @param int|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeInt(mixed $input, ?int $default, ?int $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::makeInt($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsInt($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeFloatProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1.5
|
||||
],
|
||||
'float, override set' => [
|
||||
1.5,
|
||||
-1.5,
|
||||
1.5
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
null
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
1.5,
|
||||
1.5
|
||||
],
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1.0
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setFloat
|
||||
* @dataProvider varSetTypeFloatProvider
|
||||
* @testdox setFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetFloat(mixed $input, ?float $default, ?float $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setFloat($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsFloat($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeFloatProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1.5
|
||||
],
|
||||
'float, override set' => [
|
||||
1.5,
|
||||
-1.5,
|
||||
1.5
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0.0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
1.5,
|
||||
0.0
|
||||
],
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1.0
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
-1.0,
|
||||
-1.0
|
||||
],
|
||||
// all the strange things here
|
||||
'function, no override' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
null,
|
||||
null
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
-1,
|
||||
85.0
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeFloat
|
||||
* @dataProvider varMakeTypeFloatProvider
|
||||
* @testdox makeFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeFloat(mixed $input, ?float $default, ?float $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::makeFloat($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsFloat($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeArrayProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'array, empty' => [
|
||||
[],
|
||||
null,
|
||||
[]
|
||||
],
|
||||
'array, filled' => [
|
||||
['array'],
|
||||
null,
|
||||
['array']
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
null
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
['string'],
|
||||
['string']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setArray
|
||||
* @dataProvider varSetTypeArrayProvider
|
||||
* @testdox setArray $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param array|null $default
|
||||
* @param array|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetArray(mixed $input, ?array $default, ?array $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setArray($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsArray($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeBoolProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'bool true' => [
|
||||
true,
|
||||
null,
|
||||
true
|
||||
],
|
||||
'bool false' => [
|
||||
false,
|
||||
null,
|
||||
false
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
null
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
true,
|
||||
true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setBool
|
||||
* @dataProvider varSetTypeBoolProvider
|
||||
* @testdox setBool $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $default
|
||||
* @param bool|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetBool(mixed $input, ?bool $default, ?bool $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setBool($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsBool($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeBoolProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 2: expected
|
||||
return [
|
||||
'true' => [
|
||||
true,
|
||||
true
|
||||
],
|
||||
'false' => [
|
||||
false,
|
||||
false
|
||||
],
|
||||
'string on' => [
|
||||
'on',
|
||||
true
|
||||
],
|
||||
'string off' => [
|
||||
'off',
|
||||
false
|
||||
],
|
||||
'invalid string' => [
|
||||
'sulzenbacher',
|
||||
null,
|
||||
],
|
||||
'invalid string, override' => [
|
||||
'sulzenbacher',
|
||||
null,
|
||||
],
|
||||
'array to default' => [
|
||||
[],
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setBool
|
||||
* @dataProvider varMakeTypeBoolProvider
|
||||
* @testdox setBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $default
|
||||
* @param bool|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeBool(mixed $input, ?bool $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::makeBool($input);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsBool($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
637
4dev/tests/Convert/CoreLibsConvertSetVarTypeTest.php
Normal file
637
4dev/tests/Convert/CoreLibsConvertSetVarTypeTest.php
Normal file
@@ -0,0 +1,637 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Convert\SetVarType;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Strings
|
||||
* @coversDefaultClass \CoreLibs\Convert\SetVarType
|
||||
* @testdox \CoreLibs\Convert\SetVarType method tests
|
||||
*/
|
||||
final class CoreLibsConvertSetVarTypeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'empty string' => [
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'filled string' => [
|
||||
'string',
|
||||
null,
|
||||
'string'
|
||||
],
|
||||
'valid string, override set' => [
|
||||
'string',
|
||||
'override',
|
||||
'string'
|
||||
],
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
'1'
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'1'
|
||||
],
|
||||
'array, override set' => [
|
||||
[1, 2],
|
||||
'not int',
|
||||
'not int'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setStr
|
||||
* @dataProvider varSetTypeStringProvider
|
||||
* @testdox setStr $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string|null $default
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetString(mixed $input, ?string $default, string $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setStr($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setStr($input, $default);
|
||||
}
|
||||
$this->assertIsString($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'empty string' => [
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'filled string' => [
|
||||
'string',
|
||||
null,
|
||||
'string'
|
||||
],
|
||||
'valid string, override set' => [
|
||||
'string',
|
||||
'override',
|
||||
'string'
|
||||
],
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
'1'
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'1'
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
'function',
|
||||
'function'
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
'hex',
|
||||
'85'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeStr
|
||||
* @dataProvider varMakeTypeStringProvider
|
||||
* @testdox makeStr $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string|null $default
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeString(mixed $input, ?string $default, string $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::makeStr($input);
|
||||
} else {
|
||||
$set_var = SetVarType::makeStr($input, $default);
|
||||
}
|
||||
$this->assertIsString($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeIntProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
-1,
|
||||
1
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setInt
|
||||
* @dataProvider varSetTypeIntProvider
|
||||
* @testdox setInt $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param int|null $default
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetInt(mixed $input, ?int $default, int $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setInt($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setInt($input, $default);
|
||||
}
|
||||
$this->assertIsInt($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeIntProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
-1,
|
||||
1
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
-1,
|
||||
0
|
||||
],
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
-1,
|
||||
85
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeInt
|
||||
* @dataProvider varMakeTypeIntProvider
|
||||
* @testdox makeInt $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param int|null $default
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeInt(mixed $input, ?int $default, int $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::makeInt($input);
|
||||
} else {
|
||||
$set_var = SetVarType::makeInt($input, $default);
|
||||
}
|
||||
$this->assertIsInt($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeFloatProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1.5
|
||||
],
|
||||
'float, override set' => [
|
||||
1.5,
|
||||
-1.5,
|
||||
1.5
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0.0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
1.5,
|
||||
1.5
|
||||
],
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1.0
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setFloat
|
||||
* @dataProvider varSetTypeFloatProvider
|
||||
* @testdox setFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetFloat(mixed $input, ?float $default, float $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setFloat($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setFloat($input, $default);
|
||||
}
|
||||
$this->assertIsFloat($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeFloatProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1.5
|
||||
],
|
||||
'float, override set' => [
|
||||
1.5,
|
||||
-1.5,
|
||||
1.5
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0.0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
1.5,
|
||||
0.0
|
||||
],
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1.0
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
-1.0,
|
||||
-1.0
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
-1,
|
||||
85.0
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeFloat
|
||||
* @dataProvider varMakeTypeFloatProvider
|
||||
* @testdox makeFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeFloat(mixed $input, ?float $default, float $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::makeFloat($input);
|
||||
} else {
|
||||
$set_var = SetVarType::makeFloat($input, $default);
|
||||
}
|
||||
$this->assertIsFloat($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeArrayProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'array, empty' => [
|
||||
[],
|
||||
null,
|
||||
[]
|
||||
],
|
||||
'array, filled' => [
|
||||
['array'],
|
||||
null,
|
||||
['array']
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
[]
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
['string'],
|
||||
['string']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setArray
|
||||
* @dataProvider varSetTypeArrayProvider
|
||||
* @testdox setArray $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param array|null $default
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetArray(mixed $input, ?array $default, array $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setArray($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setArray($input, $default);
|
||||
}
|
||||
$this->assertIsArray($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeBoolProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'bool true' => [
|
||||
true,
|
||||
null,
|
||||
true
|
||||
],
|
||||
'bool false' => [
|
||||
false,
|
||||
null,
|
||||
false
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
false
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
true,
|
||||
true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setBool
|
||||
* @dataProvider varSetTypeBoolProvider
|
||||
* @testdox setBool $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $default
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetBool(mixed $input, ?bool $default, bool $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setBool($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setBool($input, $default);
|
||||
}
|
||||
$this->assertIsBool($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeBoolProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 2: expected
|
||||
return [
|
||||
'true' => [
|
||||
true,
|
||||
null,
|
||||
true
|
||||
],
|
||||
'false' => [
|
||||
false,
|
||||
null,
|
||||
false
|
||||
],
|
||||
'string on' => [
|
||||
'on',
|
||||
null,
|
||||
true
|
||||
],
|
||||
'string off' => [
|
||||
'off',
|
||||
null,
|
||||
false
|
||||
],
|
||||
'invalid string' => [
|
||||
'sulzenbacher',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid string, override' => [
|
||||
'sulzenbacher',
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'array to default' => [
|
||||
[],
|
||||
null,
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setBool
|
||||
* @dataProvider varMakeTypeBoolProvider
|
||||
* @testdox setBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $default
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeBool(mixed $input, ?bool $default, bool $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::makeBool($input);
|
||||
} else {
|
||||
$set_var = SetVarType::makeBool($input, $default);
|
||||
}
|
||||
$this->assertIsBool($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\Password
|
||||
* @coversDefaultClass \CoreLibs\Check\Password
|
||||
* @testdox \CoreLibs\Check\Password method tests
|
||||
*/
|
||||
final class CoreLibsCheckPasswordTest extends TestCase
|
||||
{
|
||||
public function passwordProvider(): array
|
||||
{
|
||||
return [
|
||||
'matching password' => ['test', 'test', true],
|
||||
'not matching password' => ['test', 'not_test', false],
|
||||
];
|
||||
}
|
||||
|
||||
public function passwordRehashProvider(): array
|
||||
{
|
||||
return [
|
||||
'no rehash needed' => ['$2y$10$EgWJ2WE73DWi.hIyFRCdpejLXTvHbmTK3LEOclO1tAvXAXUNuUS4W', false],
|
||||
'rehash needed' => ['9c42a1346e333a770904b2a2b37fa7d3', true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::passwordVerify
|
||||
* @covers ::passwordSet
|
||||
* @dataProvider passwordProvider
|
||||
* @testdox passwordSet $input compare to $input_hash: passwordVerify $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $input_hash
|
||||
* @param boolean $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPasswordSetVerify(string $input, string $input_hash, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Password::passwordVerify($input, \CoreLibs\Check\Password::passwordSet($input_hash))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::passwordRehashCheck
|
||||
* @dataProvider passwordRehashProvider
|
||||
* @testdox passwordRehashCheck $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param boolean $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPasswordRehashCheck(string $input, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Password::passwordRehashCheck($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,387 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Colors
|
||||
* @coversDefaultClass \CoreLibs\Convert\Colors
|
||||
* @testdox \CoreLibs\Convert\Colors method tests
|
||||
*/
|
||||
final class CoreLibsConvertColorsTest extends TestCase
|
||||
{
|
||||
// convert list
|
||||
public static $colors = [];
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hexColorProvider(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
0 => 10,
|
||||
1 => 100,
|
||||
2 => 200,
|
||||
3 => '#0a64c8',
|
||||
4 => '0a64c8'
|
||||
],
|
||||
'gray' => [
|
||||
0 => 12,
|
||||
1 => 12,
|
||||
2 => 12,
|
||||
3 => '#0c0c0c',
|
||||
4 => '0c0c0c',
|
||||
],
|
||||
'black' => [
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
2 => 0,
|
||||
3 => '#000000',
|
||||
4 => '000000',
|
||||
],
|
||||
'white' => [
|
||||
0 => 255,
|
||||
1 => 255,
|
||||
2 => 255,
|
||||
3 => '#ffffff',
|
||||
4 => 'ffffff',
|
||||
],
|
||||
'invalid color red & green' => [
|
||||
0 => -12,
|
||||
1 => 300,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hex2rgbColorProvider(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
0 => '#0a64c8',
|
||||
1 => ['r' => 10, 'g' => 100, 'b' => 200],
|
||||
2 => '10,100,200',
|
||||
3 => ';',
|
||||
4 => '10;100;200',
|
||||
],
|
||||
'gray, long' => [
|
||||
0 => '0c0c0c',
|
||||
1 => ['r' => 12, 'g' => 12, 'b' => 12],
|
||||
2 => '12,12,12',
|
||||
3 => ';',
|
||||
4 => '12;12;12',
|
||||
],
|
||||
'gray, short' => [
|
||||
0 => 'ccc',
|
||||
1 => ['r' => 204, 'g' => 204, 'b' => 204],
|
||||
2 => '204,204,204',
|
||||
3 => ';',
|
||||
4 => '204;204;204',
|
||||
],
|
||||
'hex string with #' => [
|
||||
0 => '#0c0c0c',
|
||||
1 => ['r' => 12, 'g' => 12, 'b' => 12],
|
||||
2 => '12,12,12',
|
||||
3 => ';',
|
||||
4 => '12;12;12',
|
||||
],
|
||||
'a too long hex string' => [
|
||||
0 => '#0c0c0c0c',
|
||||
1 => false,
|
||||
2 => false,
|
||||
3 => ';',
|
||||
4 => false,
|
||||
],
|
||||
'a too short hex string' => [
|
||||
0 => '0c0c',
|
||||
1 => false,
|
||||
2 => false,
|
||||
3 => ';',
|
||||
4 => false,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hslAndhsbList(): array
|
||||
{
|
||||
return [
|
||||
'valid gray' => [
|
||||
'rgb' => [12, 12, 12],
|
||||
'hsb' => [0, 0, 5],
|
||||
'hsb_rgb' => [13, 13, 13], // should be rgb, but rounding in this
|
||||
'hsl' => [0.0, 0.0, 4.7],
|
||||
'valid' => true,
|
||||
],
|
||||
'valid color' => [
|
||||
'rgb' => [10, 100, 200],
|
||||
'hsb' => [212, 95, 78.0],
|
||||
'hsb_rgb' => [10, 98, 199], // should be rgb, but rounding error
|
||||
'hsl' => [211.6, 90.5, 41.2],
|
||||
'valid' => true,
|
||||
],
|
||||
// invalid values
|
||||
'invalid color' => [
|
||||
'rgb' => [-12, 300, 12],
|
||||
'hsb' => [-12, 300, 12],
|
||||
'hsl' => [-12, 300, 12],
|
||||
'valid' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hsbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', rgb to hsb'] = [
|
||||
0 => $values['rgb'][0],
|
||||
1 => $values['rgb'][1],
|
||||
2 => $values['rgb'][2],
|
||||
3 => $values['valid'] ? $values['hsb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsb2rgbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', hsb to rgb'] = [
|
||||
0 => $values['hsb'][0],
|
||||
1 => $values['hsb'][1],
|
||||
2 => $values['hsb'][2],
|
||||
3 => $values['valid'] ? $values['hsb_rgb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hslColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', rgb to hsl'] = [
|
||||
0 => $values['rgb'][0],
|
||||
1 => $values['rgb'][1],
|
||||
2 => $values['rgb'][2],
|
||||
3 => $values['valid'] ? $values['hsl'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsl2rgbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', hsl to rgb'] = [
|
||||
0 => $values['hsl'][0],
|
||||
1 => $values['hsl'][1],
|
||||
2 => $values['hsl'][2],
|
||||
3 => $values['valid'] ? $values['rgb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* TODO: add cross convert check
|
||||
*
|
||||
* @covers ::rgb2hex
|
||||
* @dataProvider rgb2hexColorProvider
|
||||
* @testdox rgb2hex $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input_r
|
||||
* @param int $input_g
|
||||
* @param int $input_b
|
||||
* @param string|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hex(int $input_r, int $input_g, int $input_b, $expected_hash, $expected)
|
||||
{
|
||||
// with #
|
||||
$this->assertEquals(
|
||||
$expected_hash,
|
||||
\CoreLibs\Convert\Colors::rgb2hex($input_r, $input_g, $input_b)
|
||||
);
|
||||
// without #
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hex($input_r, $input_g, $input_b, false)
|
||||
);
|
||||
// cross convert must match
|
||||
// $rgb = \CoreLibs\Convert\Colors::hex2rgb($expected_hash);
|
||||
// if ($rgb === false) {
|
||||
// $rgb = [
|
||||
// 'r' => $input_r,
|
||||
// 'g' => $input_g,
|
||||
// 'b' => $input_b,
|
||||
// ];
|
||||
// }
|
||||
// $this->assertEquals(
|
||||
// $expected_hash,
|
||||
// \CoreLibs\Convert\Colors::rgb2hex($rgb['r'], $rgb['g'], $rgb['b'])
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hex2rgb
|
||||
* @dataProvider hex2rgbColorProvider
|
||||
* @testdox hex2rgb $input will be $expected, $expected_str str[,], $expected_str_sep str[$separator] [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param array|bool $expected
|
||||
* @param string|bool $expected_str
|
||||
* @param string $separator
|
||||
* @param string|bool $expected_str_sep
|
||||
* @return void
|
||||
*/
|
||||
public function testHex2rgb(
|
||||
string $input,
|
||||
$expected,
|
||||
$expected_str,
|
||||
string $separator,
|
||||
$expected_str_sep
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_str,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input, true)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_str_sep,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input, true, $separator)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsb
|
||||
* @dataProvider rgb2hsbColorProvider
|
||||
* @testdox rgb2hsb $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
* @param integer $input_g
|
||||
* @param integer $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hsb(int $input_r, int $input_g, int $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsb($input_r, $input_g, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsb2rgb
|
||||
* @dataProvider hsb2rgbColorProvider
|
||||
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param float $input_h
|
||||
* @param float $input_s
|
||||
* @param float $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsb2rgb($input_h, $input_s, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsl
|
||||
* @dataProvider rgb2hslColorProvider
|
||||
* @testdox rgb2hsl $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
* @param integer $input_g
|
||||
* @param integer $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hsl(int $input_r, int $input_g, int $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsl($input_r, $input_g, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsl2rgb
|
||||
* @dataProvider hsl2rgbColorProvider
|
||||
* @testdox hsl2rgb $input_h,$input_s,$input_l will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer|float $input_h
|
||||
* @param integer $input_s
|
||||
* @param integer $input_l
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsl2rgb($input_h, float $input_s, float $input_l, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsl2rgb($input_h, $input_s, $input_l)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,186 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\Uids
|
||||
* @coversDefaultClass \CoreLibs\Create\Uids
|
||||
* @testdox \CoreLibs\Create\Uids method tests
|
||||
*/
|
||||
final class CoreLibsCreateUidsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function uniqIdProvider(): array
|
||||
{
|
||||
return [
|
||||
'md5 hash' => [
|
||||
0 => 'md5',
|
||||
1 => 32,
|
||||
],
|
||||
'sha256 hash' => [
|
||||
0 => 'sha256',
|
||||
1 => 64
|
||||
],
|
||||
'ripemd160 hash' => [
|
||||
0 => 'ripemd160',
|
||||
1 => 40
|
||||
],
|
||||
'adler32 hash' => [
|
||||
0 => 'adler32',
|
||||
1 => 8
|
||||
],
|
||||
'not in list hash but valid' => [
|
||||
0 => 'sha3-512',
|
||||
1 => strlen(hash('sha3-512', 'A'))
|
||||
],
|
||||
'default hash not set' => [
|
||||
0 => null,
|
||||
1 => 64,
|
||||
],
|
||||
'invalid name' => [
|
||||
0 => 'iamnotavalidhash',
|
||||
1 => 64,
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_HASH => [
|
||||
0 => \CoreLibs\Create\Uids::DEFAULT_HASH,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::DEFAULT_HASH, 'A'))
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_LONG,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A'))
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_SHORT => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_SHORT,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A'))
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function uniqIdLongProvider(): array
|
||||
{
|
||||
return [
|
||||
'uniq id long: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||
strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A'))
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* must match 7e78fe0d-59b8-4637-af7f-e88d221a7d1e
|
||||
*
|
||||
* @covers ::uuidv4
|
||||
* @testdox uuidv4 check that return is matching regex [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUuidv4(): void
|
||||
{
|
||||
$uuid = \CoreLibs\Create\Uids::uuidv4();
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/',
|
||||
$uuid
|
||||
);
|
||||
// $this->assertStringMatchesFormat(
|
||||
// '%4s%4s-%4s-%4s-%4s-%4s%4s%4s',
|
||||
// $uuid
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::uniqId
|
||||
* @dataProvider uniqIdProvider
|
||||
* @testdox uniqId $input will be length $expected [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqId(?string $input, int $expected): void
|
||||
{
|
||||
if ($input === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId())
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId($input))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Because we set a constant here, we can only run one test
|
||||
* so we test invalid one to force check
|
||||
*
|
||||
* @covers ::uniqId
|
||||
* @#dataProvider uniqIdProvider
|
||||
* @testWith ["invalidhash", 64]
|
||||
* @testdox uniqId use DEFAULT_HASH set $input with length $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUnidIdDefaultHash(string $input, int $expected): void
|
||||
{
|
||||
define('DEFAULT_HASH', $input);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short id, always 8 in length
|
||||
*
|
||||
* @covers ::uniqIdShort
|
||||
* @testWith [8]
|
||||
* @testdox uniqIdShort will be length $expected [$_dataName]
|
||||
*
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqIdShort(int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqIdShort())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Long Id, length can change
|
||||
*
|
||||
* @covers ::uniqIdLong
|
||||
* @dataProvider uniqIdLongProvider
|
||||
* @testdox uniqIdLong will be length $expected [$_dataName]
|
||||
*
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqIdLong(int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqIdLong())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,990 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
// TODO: setLogPer test log file written matches pattern
|
||||
|
||||
/**
|
||||
* Test class for Debug\Logging
|
||||
* @coversDefaultClass \CoreLibs\Debug\Logging
|
||||
* @testdox \CoreLibs\Debug\Logging method tests
|
||||
*/
|
||||
final class CoreLibsDebugLoggingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* test set for options BASIC
|
||||
*
|
||||
* 0: options
|
||||
* - null for NOT set
|
||||
* 1: expected
|
||||
* 2: override
|
||||
* override:
|
||||
* - constant for COSNTANTS
|
||||
* - global for _GLOBALS
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function optionsProvider(): array
|
||||
{
|
||||
return [
|
||||
'log folder set' => [
|
||||
[
|
||||
'log_folder' => '/tmp'
|
||||
],
|
||||
[
|
||||
'log_folder' => '/tmp/',
|
||||
'debug_all' => false,
|
||||
'print_all' => false,
|
||||
],
|
||||
[]
|
||||
],
|
||||
'nothing set' => [
|
||||
null,
|
||||
[
|
||||
'log_folder' => getcwd() . DIRECTORY_SEPARATOR,
|
||||
'debug_all' => false,
|
||||
'print_all' => false,
|
||||
],
|
||||
[]
|
||||
],
|
||||
'no options set, constant set' => [
|
||||
null,
|
||||
[
|
||||
'log_folder' => str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR . 'log/',
|
||||
'debug_all' => false,
|
||||
'print_all' => false,
|
||||
],
|
||||
[
|
||||
'constant' => [
|
||||
'BASE' => str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR,
|
||||
'LOG' => 'log/'
|
||||
]
|
||||
]
|
||||
],
|
||||
'standard test set' => [
|
||||
[
|
||||
'log_folder' => '/tmp',
|
||||
'debug_all' => true,
|
||||
'print_all' => true,
|
||||
],
|
||||
[
|
||||
'log_folder' => '/tmp/',
|
||||
'debug_all' => true,
|
||||
'print_all' => true,
|
||||
],
|
||||
[]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* init logging class
|
||||
*
|
||||
* @dataProvider optionsProvider
|
||||
* @testdox init test [$_dataName]
|
||||
*
|
||||
* @param array|null $options
|
||||
* @param array $expected
|
||||
* @param array $override
|
||||
* @return void
|
||||
*/
|
||||
public function testClassInit(?array $options, array $expected, array $override): void
|
||||
{
|
||||
if (!empty($override['constant'])) {
|
||||
foreach ($override['constant'] as $var => $value) {
|
||||
define($var, $value);
|
||||
}
|
||||
}
|
||||
if ($options === null) {
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
} else {
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
}
|
||||
// check that settings match
|
||||
$this->assertEquals(
|
||||
$expected['log_folder'],
|
||||
$log->getSetting('log_folder')
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected['debug_all'],
|
||||
$log->getSetting('debug_output_all')
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected['print_all'],
|
||||
$log->getSetting('print_output_all')
|
||||
);
|
||||
// print "LOG: " . $log->getSetting('log_folder') . "\n";
|
||||
// print "DEBUG: " . $log->getSetting('debug_output_all') . "\n";
|
||||
// print "PRINT: " . $log->getSetting('print_output_all') . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* adds log ID settings based on basic options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function logIdOptionsProvider(): array
|
||||
{
|
||||
// 0: options
|
||||
// 1: expected
|
||||
// 2: override
|
||||
return [
|
||||
'no log id set' => [
|
||||
null,
|
||||
[
|
||||
'log_file_id' => ''
|
||||
],
|
||||
[]
|
||||
],
|
||||
// set log id manually afterwards
|
||||
'set log id manually' => [
|
||||
null,
|
||||
[
|
||||
'log_file_id' => '',
|
||||
'set_log_file_id' => 'abc123',
|
||||
],
|
||||
[
|
||||
// set post launch
|
||||
'values' => [
|
||||
'log_file_id' => 'abc123'
|
||||
]
|
||||
]
|
||||
],
|
||||
// set log id from options
|
||||
'set log id via options' => [
|
||||
[
|
||||
'file_id' => 'abc456',
|
||||
],
|
||||
[
|
||||
'log_file_id' => 'abc456'
|
||||
],
|
||||
[]
|
||||
],
|
||||
// set log id from GLOBALS [DEPRECATED]
|
||||
'set log id via globals' => [
|
||||
null,
|
||||
[
|
||||
'log_file_id' => 'def123'
|
||||
],
|
||||
[
|
||||
'globals' => [
|
||||
'LOG_FILE_ID' => 'def123'
|
||||
]
|
||||
]
|
||||
],
|
||||
// set log id from CONSTANT [DEPRECATED]
|
||||
'set log id via constant' => [
|
||||
null,
|
||||
[
|
||||
'log_file_id' => 'ghi123'
|
||||
],
|
||||
[
|
||||
// reset global
|
||||
'globals' => [
|
||||
'LOG_FILE_ID' => null
|
||||
],
|
||||
'constant' => [
|
||||
'LOG_FILE_ID' => 'ghi123'
|
||||
]
|
||||
]
|
||||
],
|
||||
// invalid, keep previous set
|
||||
'invalid log id' => [
|
||||
[
|
||||
'file_id' => 'jkl456'
|
||||
],
|
||||
[
|
||||
'log_file_id' => 'jkl456',
|
||||
'set_log_file_id' => 'jkl456',
|
||||
],
|
||||
[
|
||||
'values' => [
|
||||
'log_file_id' => './#'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test the setting and getting of LogId
|
||||
*
|
||||
* @covers ::setLogId
|
||||
* @dataProvider logIdOptionsProvider
|
||||
* @testdox log id set/get tests [$_dataName]
|
||||
*
|
||||
* @param array|null $options
|
||||
* @param array $expected
|
||||
* @param array $override
|
||||
* @return void
|
||||
*/
|
||||
public function testLogId(?array $options, array $expected, array $override): void
|
||||
{
|
||||
// we need to set with file_id option, globals LOG_FILE_ID, constant LOG_FILE_ID
|
||||
if (!empty($override['constant'])) {
|
||||
foreach ($override['constant'] as $var => $value) {
|
||||
define($var, $value);
|
||||
}
|
||||
}
|
||||
if (!empty($override['globals'])) {
|
||||
foreach ($override['globals'] as $var => $value) {
|
||||
$GLOBALS[$var] = $value;
|
||||
}
|
||||
}
|
||||
if ($options === null) {
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
} else {
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
}
|
||||
// check current
|
||||
$this->assertEquals(
|
||||
$log->getLogId(),
|
||||
$expected['log_file_id']
|
||||
);
|
||||
// we need to override now too
|
||||
if (!empty($override['values'])) {
|
||||
// check if we have values, set them post and assert
|
||||
$log->setLogId($override['values']['log_file_id']);
|
||||
$this->assertEquals(
|
||||
$log->getLogId(),
|
||||
$expected['set_log_file_id']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function logLevelAllProvider(): array
|
||||
{
|
||||
// 0: type
|
||||
// 1: flag
|
||||
// 2: expected set
|
||||
// 3: expected get
|
||||
return [
|
||||
'debug all true' => [
|
||||
'debug',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'echo all true' => [
|
||||
'echo',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'print all true' => [
|
||||
'print',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'set invalid level' => [
|
||||
'invalud',
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* check set/get for log level all flag
|
||||
*
|
||||
* @dataProvider logLevelAllProvider
|
||||
* @testdox set/get all log level $type with flag $flag [$_dataName]
|
||||
*
|
||||
* @param string $type
|
||||
* @param bool $flag
|
||||
* @param bool $expected_set
|
||||
* @param bool $expected_get
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetLogLevelAll(
|
||||
string $type,
|
||||
bool $flag,
|
||||
bool $expected_set,
|
||||
bool $expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
// set and check
|
||||
$this->assertEquals(
|
||||
$log->setLogLevelAll($type, $flag),
|
||||
$expected_set
|
||||
);
|
||||
// get and check
|
||||
$this->assertEquals(
|
||||
$log->getLogLevelAll($type),
|
||||
$expected_get
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function logLevelProvider(): array
|
||||
{
|
||||
// 0: type
|
||||
// 1: flag
|
||||
// 2: debug on (array)
|
||||
// 3: expected set
|
||||
// 4: level
|
||||
// 5: expected get
|
||||
return [
|
||||
'set debug on for level A,B,C and check full set' => [
|
||||
'debug',
|
||||
'on',
|
||||
['A', 'B', 'C'],
|
||||
true,
|
||||
null,
|
||||
[
|
||||
'A' => true,
|
||||
'B' => true,
|
||||
'C' => true,
|
||||
]
|
||||
],
|
||||
'set debug off for level A,B,C and check A' => [
|
||||
'debug',
|
||||
'off',
|
||||
['A', 'B', 'C'],
|
||||
true,
|
||||
'A',
|
||||
true,
|
||||
],
|
||||
// set one to false
|
||||
'set debug off for level A, B to false and check all' => [
|
||||
'debug',
|
||||
'off',
|
||||
['A', 'B' => false],
|
||||
true,
|
||||
null,
|
||||
[
|
||||
'A' => true,
|
||||
'B' => false,
|
||||
],
|
||||
],
|
||||
// set invalid type
|
||||
'set invalid level' => [
|
||||
'invalid',
|
||||
'',
|
||||
[],
|
||||
false,
|
||||
null,
|
||||
false
|
||||
],
|
||||
// set invalid flag
|
||||
'set invalid on flag' => [
|
||||
'print',
|
||||
'invalid',
|
||||
[],
|
||||
false,
|
||||
null,
|
||||
false
|
||||
],
|
||||
// missing debug array set
|
||||
'missing debug level array' => [
|
||||
'print',
|
||||
'off',
|
||||
[],
|
||||
false,
|
||||
null,
|
||||
[]
|
||||
],
|
||||
// set but check no existing
|
||||
'set level but check no exisitng' => [
|
||||
'print',
|
||||
'on',
|
||||
['A'],
|
||||
true,
|
||||
'C',
|
||||
false
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* checks setting for per log info level
|
||||
*
|
||||
* @covers ::setLogLevel
|
||||
* @dataProvider logLevelProvider
|
||||
* @testdox set/get log level $type to $flag check with $level [$_dataName]
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $flag
|
||||
* @param array $debug_on
|
||||
* @param bool $expected_set
|
||||
* @param string|null $level
|
||||
* @param bool|array<mixed> $expected_get
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetLogLevel(
|
||||
string $type,
|
||||
string $flag,
|
||||
array $debug_on,
|
||||
bool $expected_set,
|
||||
?string $level,
|
||||
$expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
// set
|
||||
$this->assertEquals(
|
||||
$log->setLogLevel($type, $flag, $debug_on),
|
||||
$expected_set
|
||||
);
|
||||
// get, if level is null compare to?
|
||||
$this->assertEquals(
|
||||
$log->getLogLevel($type, $flag, $level),
|
||||
$expected_get
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function logPerProvider(): array
|
||||
{
|
||||
// 0: type
|
||||
// 1: set
|
||||
// 2: expected set
|
||||
// 3: expected get
|
||||
return [
|
||||
'level set true' => [
|
||||
'level',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'class set true' => [
|
||||
'class',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'page set true' => [
|
||||
'page',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'run set true' => [
|
||||
'run',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'set invalid type' => [
|
||||
'invalid',
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* set and get per log
|
||||
* for level/class/page/run flags
|
||||
*
|
||||
* @covers ::setLogPer
|
||||
* @dataProvider logPerProvider
|
||||
* @testdox set/get log per $type with $set [$_dataName]
|
||||
*
|
||||
* @param string $type
|
||||
* @param boolean $set
|
||||
* @param boolean $expected_set
|
||||
* @param boolean $expected_get
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetLogPer(
|
||||
string $type,
|
||||
bool $set,
|
||||
bool $expected_set,
|
||||
bool $expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
// set and check
|
||||
$this->assertEquals(
|
||||
$log->setLogPer($type, $set),
|
||||
$expected_set
|
||||
);
|
||||
// get and check
|
||||
$this->assertEquals(
|
||||
$log->getLogPer($type),
|
||||
$expected_get
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* set the print log file date part
|
||||
*
|
||||
* @covers ::setGetLogPrintFileDate
|
||||
* @testWith [true, true, true]
|
||||
* [false, false, false]
|
||||
* @testdox set/get log file date to $input [$_dataName]
|
||||
*
|
||||
* @param boolean $input
|
||||
* @param boolean $expected_set
|
||||
* @param boolean $expected_get
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetLogPrintFileDate(bool $input, bool $expected_set, bool $expected_get): void
|
||||
{
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
// set and check
|
||||
$this->assertEquals(
|
||||
$log->setGetLogPrintFileDate($input),
|
||||
$expected_set
|
||||
);
|
||||
$this->assertEquals(
|
||||
$log->setGetLogPrintFileDate(),
|
||||
$expected_get
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prArProvider(): array
|
||||
{
|
||||
return [
|
||||
'simple array' => [
|
||||
[
|
||||
'A' => 'foobar'
|
||||
],
|
||||
"##HTMLPRE##Array\n(\n"
|
||||
. " [A] => foobar\n"
|
||||
. ")\n"
|
||||
. "##/HTMLPRE##"
|
||||
],
|
||||
'empty array' => [
|
||||
[],
|
||||
"##HTMLPRE##Array\n(\n"
|
||||
. ")\n"
|
||||
. "##/HTMLPRE##"
|
||||
],
|
||||
'nested array' => [
|
||||
[
|
||||
'A' => [
|
||||
'B' => 'bar'
|
||||
]
|
||||
],
|
||||
"##HTMLPRE##Array\n(\n"
|
||||
. " [A] => Array\n"
|
||||
. " (\n"
|
||||
. " [B] => bar\n"
|
||||
. " )\n"
|
||||
. "\n"
|
||||
. ")\n"
|
||||
. "##/HTMLPRE##"
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* convert array to string with ## pre replace space holders
|
||||
*
|
||||
* @covers ::prAr
|
||||
* @dataProvider prArProvider
|
||||
* @testdox check prAr array to string conversion [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrAr(array $input, string $expected): void
|
||||
{
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$this->assertEquals(
|
||||
$log->prAr($input),
|
||||
$expected
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prBlProvider(): array
|
||||
{
|
||||
// 0: input flag (bool)
|
||||
// 1: is true
|
||||
// 2: is flase
|
||||
// 3: epxected
|
||||
return [
|
||||
'true bool default' => [
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
'true'
|
||||
],
|
||||
'false bool default' => [
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
'false'
|
||||
],
|
||||
'true bool override' => [
|
||||
true,
|
||||
'ok',
|
||||
'not ok',
|
||||
'ok'
|
||||
],
|
||||
'false bool override' => [
|
||||
false,
|
||||
'ok',
|
||||
'not ok',
|
||||
'not ok'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* check bool to string converter
|
||||
*
|
||||
* @covers ::prBl
|
||||
* @dataProvider prBlProvider
|
||||
* @testdox check prBl $input ($true/$false) is expected $false [$_dataName]
|
||||
*
|
||||
* @param bool $input
|
||||
* @param string|null $true
|
||||
* @param string|null $false
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrBl(bool $input, ?string $true, ?string $false, string $expected): void
|
||||
{
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$return = '';
|
||||
if ($true === null && $false === null) {
|
||||
$return = $log->prBl($input);
|
||||
} elseif ($true !== null || $false !== null) {
|
||||
$return = $log->prBl($input, $true ?? '', $false ?? '');
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$return
|
||||
);
|
||||
}
|
||||
|
||||
// from here are complex debug tests
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* 0: array $options
|
||||
* 1: array $debug_msg
|
||||
* 2: boolean $expected_debug
|
||||
* 3: string $expected_file
|
||||
* 4: string $expected_string_start
|
||||
* 5: string $expected_string_contains
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function debugProvider(): array
|
||||
{
|
||||
// error message to pass in
|
||||
$error_msg['A'] = [
|
||||
'level' => 'A',
|
||||
'string' => 'error msg',
|
||||
'strip' => false,
|
||||
'prefix' => '',
|
||||
];
|
||||
// file content to check
|
||||
$file_msg['A'] = "{PHPUnit\TextUI\Command} <A> - error msg\n";
|
||||
// string messages to check
|
||||
$string_msg['A'] = [
|
||||
's' => '<div style="text-align: left; padding: 5px; font-size: 10px; '
|
||||
. 'font-family: sans-serif; border-top: 1px solid black; '
|
||||
. 'border-bottom: 1px solid black; margin: 10px 0 10px 0; '
|
||||
. 'background-color: white; color: black;">'
|
||||
. '<div style="font-size: 12px;">{<span style="font-style: '
|
||||
. 'italic; color: #928100;">PHPUnit\TextUI\Command</span>}'
|
||||
. '</div><div style="font-size: 12px;">[<span style="font-style: '
|
||||
. 'italic; color: #c56c00;">A</span>] </div><div>[<span '
|
||||
. 'style="font-weight: bold; color: #5e8600;">',
|
||||
'c' => 'PHPUnit\TextUI\Command</span>} - error msg</div><!--#BR#-->',
|
||||
];
|
||||
// array provider
|
||||
return [
|
||||
'A debug: on, print: on, echo: on' => [
|
||||
[
|
||||
'debug_all' => true,
|
||||
'print_all' => true,
|
||||
'echo_all' => true,
|
||||
],
|
||||
$error_msg['A'],
|
||||
true,
|
||||
$file_msg['A'],
|
||||
$string_msg['A']['s'],
|
||||
$string_msg['A']['c'],
|
||||
],
|
||||
'B debug: on, print: off, echo: on' => [
|
||||
[
|
||||
'debug_all' => true,
|
||||
'print_all' => false,
|
||||
'echo_all' => true,
|
||||
],
|
||||
$error_msg['A'],
|
||||
true,
|
||||
'',
|
||||
$string_msg['A']['s'],
|
||||
$string_msg['A']['c'],
|
||||
],
|
||||
'C debug: on, print: on, echo: off' => [
|
||||
[
|
||||
'debug_all' => true,
|
||||
'print_all' => true,
|
||||
'echo_all' => false,
|
||||
],
|
||||
$error_msg['A'],
|
||||
true,
|
||||
$file_msg['A'],
|
||||
'',
|
||||
'',
|
||||
],
|
||||
'D debug: on, print: off, echo: off' => [
|
||||
[
|
||||
'debug_all' => true,
|
||||
'print_all' => false,
|
||||
'echo_all' => false,
|
||||
],
|
||||
$error_msg['A'],
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
''
|
||||
],
|
||||
'E debug: off, print: off, echo: off' => [
|
||||
[
|
||||
'debug_all' => false,
|
||||
'print_all' => false,
|
||||
'echo_all' => false,
|
||||
],
|
||||
$error_msg['A'],
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
''
|
||||
]
|
||||
// TODO more tests with different error messages
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test debug flow
|
||||
*
|
||||
* @covers ::debug
|
||||
* @dataProvider debugProvider
|
||||
* @testdox check debug flow: $expected_debug [$_dataName]
|
||||
*
|
||||
* @param array $options
|
||||
* @param array $debug_msg
|
||||
* @param boolean $expected_debug
|
||||
* @param string $expected_file
|
||||
* @param string $expected_string_start
|
||||
* @param string $expected_string_contains
|
||||
* @return void
|
||||
*/
|
||||
public function testDebug(
|
||||
array $options,
|
||||
array $debug_msg,
|
||||
bool $expected_debug,
|
||||
string $expected_file,
|
||||
string $expected_string_start,
|
||||
string $expected_string_contains
|
||||
): void {
|
||||
// must run with below matrix
|
||||
// level | debug | print | echo | debug() | printErrorMsg() | file
|
||||
// A 1/1/1 | on | on | on | true | 'string' | on
|
||||
// B 1/0/1 | on | off | on | true | 'string' | off
|
||||
// C 1/1/0 | on | on | off | true | '' | on
|
||||
// D 1/0/0 | on | off | off | false | '' | off
|
||||
// E 0/1/1 | off | on | on | false | '' | off
|
||||
// F 0/0/1 | off | off | on | false | '' | off
|
||||
// G 0/1/0 | off | on | off | false | '' | off
|
||||
// H 0/0/0 | off | off | off | false | '' | off
|
||||
|
||||
|
||||
// * debug off
|
||||
// return false on debug(),
|
||||
// return false on writeErrorMsg()
|
||||
// empty string on printErrorMsg
|
||||
// * print off
|
||||
// return true on debug(),
|
||||
// return false on writeErrorMsg()
|
||||
// empty string on printErrorMsg
|
||||
// * echo off
|
||||
// return true on debug(),
|
||||
// empty string on printErrorMsg
|
||||
// fillxed error_msg array
|
||||
|
||||
// overwrite any previous set from test
|
||||
$options['file_id'] = 'TestDebug';
|
||||
// set log folder to temp
|
||||
$options['log_folder'] = '/tmp/';
|
||||
// remove any files named /tmp/error_log_TestDebug*.log
|
||||
array_map('unlink', glob($options['log_folder'] . 'error_msg_' . $options['file_id'] . '*.log'));
|
||||
// init logger
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
// * debug (A/B)
|
||||
// NULL check for strip/prefix
|
||||
$this->assertEquals(
|
||||
$log->debug(
|
||||
$debug_msg['level'],
|
||||
$debug_msg['string'],
|
||||
$debug_msg['strip'],
|
||||
$debug_msg['prefix'],
|
||||
),
|
||||
$expected_debug
|
||||
);
|
||||
// * if print check data in log file
|
||||
$log_file = $log->getLogFileName();
|
||||
if (!empty($options['debug_all']) && !empty($options['print_all'])) {
|
||||
// file name matching
|
||||
$this->assertStringStartsWith(
|
||||
$options['log_folder'] . 'error_msg_' . $options['file_id'],
|
||||
$log_file,
|
||||
);
|
||||
// cotents check
|
||||
if (!is_file($log_file)) {
|
||||
$this->fail('error msg file not found: ' . $log_file);
|
||||
} else {
|
||||
$log_data = file_get_contents($log_file);
|
||||
if ($log_data === null) {
|
||||
$this->fail('error msg file not readable or not data: ' . $log_file);
|
||||
}
|
||||
// file content matching
|
||||
$this->assertStringEndsWith(
|
||||
$expected_file,
|
||||
$log_data,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// there should be no file there
|
||||
$this->assertEquals(
|
||||
$log_file,
|
||||
''
|
||||
);
|
||||
}
|
||||
// ** ECHO ON
|
||||
$log_string = $log->printErrorMsg();
|
||||
// * print
|
||||
if (!empty($options['debug_all']) && !empty($options['echo_all'])) {
|
||||
// print $log->printErrorMsg() . "\n";
|
||||
// echo string must start with
|
||||
$this->assertStringStartsWith(
|
||||
$expected_string_start,
|
||||
$log_string
|
||||
);
|
||||
// echo string must containt
|
||||
$this->assertStringContainsString(
|
||||
$expected_string_contains,
|
||||
$log_string
|
||||
);
|
||||
// TODO: as printing directly is not really done anymore tests below are todo
|
||||
// * get error msg (getErrorMsg)
|
||||
// * merge error msg (mergeErrors)
|
||||
// * print merged (printErrorMsg)
|
||||
// * reset A (resetErrorMsg)
|
||||
// * reset ALL (resetErrorMsg)
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$log_string,
|
||||
''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: setLogUniqueId/getLogUniqueId
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function logUniqueIdProvider(): array
|
||||
{
|
||||
return [
|
||||
'option set' => [
|
||||
'option' => true,
|
||||
'override' => false,
|
||||
],
|
||||
'direct set' => [
|
||||
'option' => false,
|
||||
'override' => false,
|
||||
],
|
||||
'override set' => [
|
||||
'option' => false,
|
||||
'override' => true,
|
||||
],
|
||||
'option and override set' => [
|
||||
'option' => false,
|
||||
'override' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLogUniqueId
|
||||
* @covers ::getLogUniqueId
|
||||
* @dataProvider logUniqueIdProvider
|
||||
* @testdox per run log id set test: option: $option, override: $override [$_dataName]
|
||||
*
|
||||
* @param bool $option
|
||||
* @param bool $override
|
||||
* @return void
|
||||
*/
|
||||
public function testLogUniqueId(bool $option, bool $override): void
|
||||
{
|
||||
if ($option === true) {
|
||||
$log = new \CoreLibs\Debug\Logging(['per_run' => $option]);
|
||||
} else {
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$log->setLogUniqueId();
|
||||
}
|
||||
$per_run_id = $log->getLogUniqueId();
|
||||
$this->assertMatchesRegularExpression(
|
||||
"/^\d{4}-\d{2}-\d{2}_\d{6}_U_[a-z0-9]{8}$/",
|
||||
$per_run_id,
|
||||
'assert per log run id 1st'
|
||||
);
|
||||
if ($override === true) {
|
||||
$log->setLogUniqueId(true);
|
||||
$per_run_id_2nd = $log->getLogUniqueId();
|
||||
$this->assertMatchesRegularExpression(
|
||||
"/^\d{4}-\d{2}-\d{2}_\d{6}_U_[a-z0-9]{8}$/",
|
||||
$per_run_id_2nd,
|
||||
'assert per log run id 2nd'
|
||||
);
|
||||
$this->assertNotEquals(
|
||||
$per_run_id,
|
||||
$per_run_id_2nd,
|
||||
'1st and 2nd don\'t match'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,464 +0,0 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Debug\Support
|
||||
* @coversDefaultClass \CoreLibs\Debug\Support
|
||||
* @testdox \CoreLibs\Debug\Support method tests
|
||||
*/
|
||||
final class CoreLibsDebugSupportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printTimeProvider(): array
|
||||
{
|
||||
return [
|
||||
'default microtime' => [
|
||||
0 => null,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{8}$/",
|
||||
],
|
||||
'microtime -1' => [
|
||||
0 => -1,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{8}$/",
|
||||
],
|
||||
'microtime 0' => [
|
||||
0 => 0,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/",
|
||||
],
|
||||
'microtime 4' => [
|
||||
0 => 4,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{4}$/",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty array' => [
|
||||
0 => [],
|
||||
1 => "<pre>Array\n(\n)\n</pre>"
|
||||
],
|
||||
'simple array' => [
|
||||
0 => ['a', 'b'],
|
||||
1 => "<pre>Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n</pre>"
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printBoolProvider(): array
|
||||
{
|
||||
return [
|
||||
'true input default' => [
|
||||
0 => true,
|
||||
1 => [],
|
||||
2 => 'true'
|
||||
],
|
||||
'false input default' => [
|
||||
0 => false,
|
||||
1 => [],
|
||||
2 => 'false'
|
||||
],
|
||||
'false input param name' => [
|
||||
0 => false,
|
||||
1 => [
|
||||
'name' => 'param test'
|
||||
],
|
||||
2 => '<b>param test</b>: false'
|
||||
],
|
||||
'true input param name, true override' => [
|
||||
0 => true,
|
||||
1 => [
|
||||
'name' => 'param test',
|
||||
'true' => 'ok'
|
||||
],
|
||||
2 => '<b>param test</b>: ok'
|
||||
],
|
||||
'false input param name, true override, false override' => [
|
||||
0 => false,
|
||||
1 => [
|
||||
'name' => 'param test',
|
||||
'true' => 'ok',
|
||||
'false' => 'not',
|
||||
],
|
||||
2 => '<b>param test</b>: not'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printToStringProvider(): array
|
||||
{
|
||||
return [
|
||||
'string' => [
|
||||
'a string',
|
||||
null,
|
||||
'a string',
|
||||
],
|
||||
'string with html chars, encode' => [
|
||||
'a string with <> &',
|
||||
true,
|
||||
'a string with <> &',
|
||||
],
|
||||
'string with html chars' => [
|
||||
'a string with <> &',
|
||||
null,
|
||||
'a string with <> &',
|
||||
],
|
||||
'a number' => [
|
||||
1234,
|
||||
null,
|
||||
'1234',
|
||||
],
|
||||
'a float number' => [
|
||||
1234.5678,
|
||||
null,
|
||||
'1234.5678',
|
||||
],
|
||||
'bool true' => [
|
||||
true,
|
||||
null,
|
||||
'TRUE',
|
||||
],
|
||||
'bool false' => [
|
||||
false,
|
||||
null,
|
||||
'FALSE',
|
||||
],
|
||||
'an array default' => [
|
||||
['a', 'b'],
|
||||
null,
|
||||
"<pre>Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n</pre>",
|
||||
],
|
||||
'an array, no html' => [
|
||||
['a', 'b'],
|
||||
true,
|
||||
"##HTMLPRE##"
|
||||
. "Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n"
|
||||
. "##/HTMLPRE##",
|
||||
],
|
||||
// resource
|
||||
'a resource' => [
|
||||
tmpfile(),
|
||||
null,
|
||||
'/^Resource id #\d+$/',
|
||||
],
|
||||
// object
|
||||
'an object' => [
|
||||
new \CoreLibs\Debug\Support(),
|
||||
null,
|
||||
'CoreLibs\Debug\Support',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function debugStringProvider(): array
|
||||
{
|
||||
// 0: input string
|
||||
// 1: replace
|
||||
// 2: html flag
|
||||
// 3: expected
|
||||
return [
|
||||
'null string, default' => [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'-'
|
||||
],
|
||||
'empty string, ... replace' => [
|
||||
'',
|
||||
'...',
|
||||
null,
|
||||
'...'
|
||||
],
|
||||
'filled string' => [
|
||||
'some string',
|
||||
null,
|
||||
null,
|
||||
'some string'
|
||||
],
|
||||
'string with html chars, encode' => [
|
||||
'a string with <> &',
|
||||
'-',
|
||||
true,
|
||||
'a string with <> &',
|
||||
],
|
||||
'string with html chars' => [
|
||||
'a string with <> &',
|
||||
'-',
|
||||
null,
|
||||
'a string with <> &',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printTime
|
||||
* @dataProvider printTimeProvider
|
||||
* @testdox printTime test with $microtime and match to regex [$_dataName]
|
||||
*
|
||||
* @param int|null $mircrotime
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintTime(?int $microtime, string $regex): void
|
||||
{
|
||||
if ($microtime === null) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
\CoreLibs\Debug\Support::printTime()
|
||||
);
|
||||
} else {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
\CoreLibs\Debug\Support::printTime($microtime)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printAr
|
||||
* @cover ::printArray
|
||||
* @dataProvider printArrayProvider
|
||||
* @testdox printAr/printArray $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintAr(array $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printAr($input),
|
||||
'assert printAr'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printArray($input),
|
||||
'assert printArray'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printBool
|
||||
* @dataProvider printBoolProvider
|
||||
* @testdox printBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param bool $input
|
||||
* @param array $params
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintBool(bool $input, array $params, string $expected): void
|
||||
{
|
||||
if (
|
||||
isset($params['name']) &&
|
||||
isset($params['true']) &&
|
||||
isset($params['false'])
|
||||
) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true'],
|
||||
$params['false']
|
||||
);
|
||||
} elseif (isset($params['name']) && isset($params['true'])) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true']
|
||||
);
|
||||
} elseif (isset($params['name'])) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name']
|
||||
);
|
||||
} else {
|
||||
$string = \CoreLibs\Debug\Support::printBool($input);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$string,
|
||||
'assert printBool'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printToString
|
||||
* @dataProvider printToStringProvider
|
||||
* @testdox printToString $input with $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param boolean|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintToString($input, ?bool $flag, string $expected): void
|
||||
{
|
||||
if ($flag === null) {
|
||||
// if expected starts with / and ends with / then this is a regex compare
|
||||
if (substr($expected, 0, 1) == '/' && substr($expected, -1, 1) == '/') {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input, $flag)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethod
|
||||
* @testWith ["testGetCallerMethod"]
|
||||
* @testdox getCallerMethod check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethod(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerMethod()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethodList
|
||||
* @testWith [["main", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"],["main", "run", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"]]
|
||||
* @testdox getCallerMethodList check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethodList(array $expected, array $expected_group): void
|
||||
{
|
||||
$compare = \CoreLibs\Debug\Support::getCallerMethodList();
|
||||
// if we direct call we have 10, if we call as folder we get 11
|
||||
if (count($compare) == 10) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerMethodList(),
|
||||
'assert expected 10'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected_group,
|
||||
\CoreLibs\Debug\Support::getCallerMethodList(),
|
||||
'assert expected group'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerClass
|
||||
* @testWith ["PHPUnit\\TextUI\\Command"]
|
||||
* @testdox getCallerClass check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerClass(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerClass()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::debugString
|
||||
* @dataProvider debugStringProvider
|
||||
* @testdox debugString $input with replace $replace and html $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string|null $replace
|
||||
* @param bool|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testDebugString(?string $input, ?string $replace, ?bool $flag, string $expected): void
|
||||
{
|
||||
if ($replace === null && $flag === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input),
|
||||
'assert all default'
|
||||
);
|
||||
} elseif ($flag === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input, $replace),
|
||||
'assert flag default'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input, $replace, $flag),
|
||||
'assert all set'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,310 +0,0 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Language\GetLocale
|
||||
*
|
||||
* @coversDefaultClass \CoreLibs\Language\GetLocale
|
||||
* @testdox \CoreLibs\Language\GetLocale method tests
|
||||
*/
|
||||
final class CoreLibsLanguageGetLocaleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* set all constant variables that must be set before call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// default web page encoding setting
|
||||
if (!defined('DEFAULT_ENCODING')) {
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
}
|
||||
if (!defined('DEFAULT_LOCALE')) {
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
}
|
||||
// site
|
||||
if (!defined('SITE_ENCODING')) {
|
||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||
}
|
||||
if (!defined('SITE_LOCALE')) {
|
||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||
}
|
||||
// just set
|
||||
if (!defined('BASE')) {
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('INCLUDES')) {
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LANG')) {
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LOCALE')) {
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CONTENT_PATH')) {
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
// array session
|
||||
$_SESSION = [];
|
||||
global $_SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setLocaleProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: SESSION: DEFAULT_LOCALE
|
||||
// 5: SESSION: DEFAULT_CHARSET
|
||||
// 6: expected array
|
||||
'no params, all default constants' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
'no params, session charset and lang' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja_JP', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
'no params, session charset and lang short' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang (no sessions)
|
||||
'locale param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// different locale setting
|
||||
'locale complex param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja_JP.SJIS', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP.SJIS',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'SJIS',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// lang, domain, path (no override)
|
||||
'locale, domain and path, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', '', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// all params set (no override)
|
||||
'all parameter, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja', 'admin', 'UTF-8', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'long locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'de_CH.UTF-8@euro', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'de_CH.UTF-8@euro',
|
||||
'lang' => 'de_CH',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// TODO invalid params (bad path) (no override)
|
||||
// TODO param calls, but with override set
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLocale
|
||||
* @dataProvider setLocaleProvider
|
||||
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testsetLocale(
|
||||
?string $language,
|
||||
?string $domain,
|
||||
?string $encoding,
|
||||
?string $path,
|
||||
?string $SESSION_DEFAULT_LOCALE,
|
||||
?string $SESSION_DEFAULT_CHARSET,
|
||||
array $expected
|
||||
): void {
|
||||
$return_lang_settings = [];
|
||||
global $_SESSION;
|
||||
// set override
|
||||
if ($SESSION_DEFAULT_LOCALE !== null) {
|
||||
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
|
||||
}
|
||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
||||
}
|
||||
// function call
|
||||
if ($language === null && $domain === null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale();
|
||||
} elseif ($language !== null && $domain === null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language
|
||||
);
|
||||
} elseif ($language !== null && $domain !== null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain
|
||||
);
|
||||
} elseif ($language !== null && $domain !== null && $encoding !== null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding
|
||||
);
|
||||
} else {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding,
|
||||
$path
|
||||
);
|
||||
}
|
||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
||||
|
||||
foreach (
|
||||
[
|
||||
'locale', 'lang', 'domain', 'encoding', 'path'
|
||||
] as $key
|
||||
) {
|
||||
$value = $expected[$key];
|
||||
if (strpos($value, "/") === 0) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert regex failed for ' . $key
|
||||
);
|
||||
} else {
|
||||
// assert equal
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert equal failed for ' . $key
|
||||
);
|
||||
}
|
||||
}
|
||||
// unset all vars
|
||||
$_SESSION = [];
|
||||
unset($GLOBALS['OVERRIDE_LANG']);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -22,12 +22,9 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
self::$log = new \CoreLibs\Logging\Logging([
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-Create-Email-Test',
|
||||
'debug_all' => true,
|
||||
'echo_all' => false,
|
||||
'print_all' => true,
|
||||
'log_file_id' => 'CoreLibs-Create-Email-Test',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -113,7 +110,10 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
'日本語カタカナパ',
|
||||
'ISO-2022-JP',
|
||||
true,
|
||||
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8=?=" <test@test.com>'
|
||||
// was ok php 8.1
|
||||
// '"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8=?=" <test@test.com>'
|
||||
// below ok php 8.1.12, 2022/12/9
|
||||
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8/?=" <test@test.com>'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -124,6 +124,11 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
* @dataProvider encodeEmailNameProvider
|
||||
* @testdox encode email $email, name $name, encoding $encoding, folding $kv_folding will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $email
|
||||
* @param string|null $name
|
||||
* @param string|null $encoding
|
||||
* @param bool|null $kv_folding
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncodeEmailName(
|
||||
@@ -616,7 +621,7 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
// force new set for each run
|
||||
self::$log->setLogUniqueId(true);
|
||||
// set on of unique log id
|
||||
self::$log->setLogPer('run', true);
|
||||
self::$log->setLogFlag(\CoreLibs\Logging\Logger\Flag::per_run);
|
||||
// init logger
|
||||
$status = \CoreLibs\Create\Email::sendEmail(
|
||||
$subject,
|
||||
@@ -638,7 +643,9 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
// assert content: must load JSON from log file
|
||||
if ($status == 2) {
|
||||
// open file, get last entry with 'SEND EMAIL JSON' key
|
||||
$file = file_get_contents(self::$log->getLogFileName());
|
||||
$file = file_get_contents(
|
||||
self::$log->getLogFolder() . self::$log->getLogFile()
|
||||
);
|
||||
if ($file !== false) {
|
||||
// extract SEND EMAIL JSON line
|
||||
$found = preg_match_all("/^.* <SEND EMAIL JSON> - (.*)$/m", $file, $matches);
|
||||
@@ -30,8 +30,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
// setSessionName: true/false,
|
||||
// checkActiveSession: true/false, [1st call, 2nd call]
|
||||
// getSessionId: string or false
|
||||
// 3: exepcted name (session)
|
||||
// 4: expected error string
|
||||
// 3: exepcted name (session)]
|
||||
// 4: Exception thrown on error
|
||||
// 5: exception code, null for none
|
||||
// 6: expected error string
|
||||
return [
|
||||
'session parameter' => [
|
||||
'sessionNameParameter',
|
||||
@@ -44,7 +46,9 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameParameter',
|
||||
''
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
],
|
||||
'session globals' => [
|
||||
'sessionNameGlobals',
|
||||
@@ -57,7 +61,9 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameGlobals',
|
||||
''
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
],
|
||||
'session name default' => [
|
||||
'',
|
||||
@@ -70,7 +76,9 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
''
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
],
|
||||
// error checks
|
||||
// 1: we are in cli
|
||||
@@ -85,6 +93,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'RuntimeException',
|
||||
1,
|
||||
'[SESSION] No sessions in php cli'
|
||||
],
|
||||
// 2: session disabled
|
||||
@@ -99,6 +109,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'RuntimeException',
|
||||
2,
|
||||
'[SESSION] Sessions are disabled'
|
||||
],
|
||||
// 3: invalid session name: string
|
||||
@@ -113,6 +125,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'UnexpectedValueException',
|
||||
3,
|
||||
'[SESSION] Invalid session name: 1invalid$session#;'
|
||||
],
|
||||
// 3: invalid session name: only numbers
|
||||
@@ -127,6 +141,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'UnexpectedValueException',
|
||||
3,
|
||||
'[SESSION] Invalid session name: 123'
|
||||
],
|
||||
// 3: invalid session name: invalid name short
|
||||
@@ -143,6 +159,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'RuntimeException',
|
||||
4,
|
||||
'[SESSION] Failed to activate session'
|
||||
],
|
||||
// 5: get session id return false
|
||||
@@ -157,6 +175,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => false
|
||||
],
|
||||
'',
|
||||
'UnexpectedValueException',
|
||||
5,
|
||||
'[SESSION] getSessionId did not return a session id'
|
||||
],
|
||||
];
|
||||
@@ -173,6 +193,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
* @param string $type
|
||||
* @param array<mixed> $mock_data
|
||||
* @param string $expected
|
||||
* @param string|null $exception
|
||||
* @param string $expected_error
|
||||
* @return void
|
||||
*/
|
||||
@@ -181,6 +202,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
string $type,
|
||||
array $mock_data,
|
||||
string $expected,
|
||||
?string $exception,
|
||||
?int $exception_code,
|
||||
string $expected_error
|
||||
): void {
|
||||
// override expected
|
||||
@@ -224,6 +247,11 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
// regex for session id
|
||||
$ression_id_regex = "/^\w+$/";
|
||||
|
||||
if ($exception !== null) {
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionCode($exception_code);
|
||||
}
|
||||
|
||||
unset($GLOBALS['SET_SESSION_NAME']);
|
||||
$session_id = '';
|
||||
switch ($type) {
|
||||
@@ -253,13 +281,6 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
$expected,
|
||||
$session_mock->getSessionName()
|
||||
);
|
||||
} else {
|
||||
// false checks
|
||||
$this->assertEquals(
|
||||
$expected_error,
|
||||
$session_mock->getErrorStr(),
|
||||
'error assert'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
225
4dev/tests/Create/CoreLibsCreateUidsTest.php
Normal file
225
4dev/tests/Create/CoreLibsCreateUidsTest.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\Uids
|
||||
* @coversDefaultClass \CoreLibs\Create\Uids
|
||||
* @testdox \CoreLibs\Create\Uids method tests
|
||||
*/
|
||||
final class CoreLibsCreateUidsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function uniqIdProvider(): array
|
||||
{
|
||||
return [
|
||||
// number length
|
||||
'too short' => [
|
||||
0 => 1,
|
||||
1 => 4,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 10' => [
|
||||
0 => 10,
|
||||
1 => 10,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 9, auto length' => [
|
||||
0 => 9,
|
||||
1 => 8,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 9, force length' => [
|
||||
0 => 9,
|
||||
1 => 9,
|
||||
2 => true,
|
||||
],
|
||||
'very long: 512' => [
|
||||
0 => 512,
|
||||
1 => 512,
|
||||
2 => null
|
||||
],
|
||||
// below is all legacy
|
||||
'md5 hash' => [
|
||||
0 => 'md5',
|
||||
1 => 32,
|
||||
2 => null
|
||||
],
|
||||
'sha256 hash' => [
|
||||
0 => 'sha256',
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'ripemd160 hash' => [
|
||||
0 => 'ripemd160',
|
||||
1 => 40,
|
||||
2 => null
|
||||
],
|
||||
'adler32 hash' => [
|
||||
0 => 'adler32',
|
||||
1 => 8,
|
||||
2 => null
|
||||
],
|
||||
'not in list, set default length' => [
|
||||
0 => 'sha3-512',
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'default hash not set' => [
|
||||
0 => null,
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'invalid name' => [
|
||||
0 => 'iamnotavalidhash',
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
// auto calls
|
||||
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH => [
|
||||
0 => \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH,
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_LONG,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A')),
|
||||
2 => null
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_SHORT => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_SHORT,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A')),
|
||||
2 => null
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function uniqIdLongProvider(): array
|
||||
{
|
||||
return [
|
||||
'uniq id long: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||
strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A'))
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* must match 7e78fe0d-59b8-4637-af7f-e88d221a7d1e
|
||||
*
|
||||
* @covers ::uuidv4
|
||||
* @testdox uuidv4 check that return is matching regex [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUuidv4(): void
|
||||
{
|
||||
$uuid = \CoreLibs\Create\Uids::uuidv4();
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/',
|
||||
$uuid
|
||||
);
|
||||
// $this->assertStringMatchesFormat(
|
||||
// '%4s%4s-%4s-%4s-%4s-%4s%4s%4s',
|
||||
// $uuid
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::uniqId
|
||||
* @dataProvider uniqIdProvider
|
||||
* @testdox uniqId $input will be length $expected (Force $flag) [$_dataName]
|
||||
*
|
||||
* @param int|string|null $input
|
||||
* @param string $expected
|
||||
* @param bool|null $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqId(int|string|null $input, int $expected, ?bool $flag): void
|
||||
{
|
||||
if ($input === null) {
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId());
|
||||
} elseif ($flag === null) {
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input));
|
||||
} else {
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input, $flag));
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$uniq_id_length
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Because we set a constant here, we can only run one test
|
||||
* so we test invalid one to force check
|
||||
*
|
||||
* @covers ::uniqId
|
||||
* @#dataProvider uniqIdProvider
|
||||
* @testWith ["invalidhash", 64]
|
||||
* @testdox uniqId use DEFAULT_HASH set $input with length $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUnidIdDefaultHash(string $input, int $expected): void
|
||||
{
|
||||
define('DEFAULT_HASH', $input);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short id, always 8 in length
|
||||
*
|
||||
* @covers ::uniqIdShort
|
||||
* @testWith [8]
|
||||
* @testdox uniqIdShort will be length $expected [$_dataName]
|
||||
*
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqIdShort(int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqIdShort())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Long Id, length can change
|
||||
*
|
||||
* @covers ::uniqIdLong
|
||||
* @dataProvider uniqIdLongProvider
|
||||
* @testdox uniqIdLong will be length $expected [$_dataName]
|
||||
*
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqIdLong(int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqIdLong())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
5224
4dev/tests/DB/CoreLibsDBIOTest.php
Normal file
5224
4dev/tests/DB/CoreLibsDBIOTest.php
Normal file
File diff suppressed because it is too large
Load Diff
1085
4dev/tests/Debug/CoreLibsDebugLoggingLegacyTest.php
Normal file
1085
4dev/tests/Debug/CoreLibsDebugLoggingLegacyTest.php
Normal file
File diff suppressed because it is too large
Load Diff
697
4dev/tests/Debug/CoreLibsDebugSupportTest.php
Normal file
697
4dev/tests/Debug/CoreLibsDebugSupportTest.php
Normal file
@@ -0,0 +1,697 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Debug\Support;
|
||||
|
||||
/**
|
||||
* Test class for Debug\Support
|
||||
* @coversDefaultClass \CoreLibs\Debug\Support
|
||||
* @testdox \CoreLibs\Debug\Support method tests
|
||||
*/
|
||||
final class CoreLibsDebugSupportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printTimeProvider(): array
|
||||
{
|
||||
return [
|
||||
'default microtime' => [
|
||||
0 => null,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{8}$/",
|
||||
],
|
||||
'microtime -1' => [
|
||||
0 => -1,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{8}$/",
|
||||
],
|
||||
'microtime 0' => [
|
||||
0 => 0,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/",
|
||||
],
|
||||
'microtime 4' => [
|
||||
0 => 4,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{4}$/",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printTime
|
||||
* @dataProvider printTimeProvider
|
||||
* @testdox printTime test with $microtime and match to regex [$_dataName]
|
||||
*
|
||||
* @param int|null $mircrotime
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintTime(?int $microtime, string $regex): void
|
||||
{
|
||||
if ($microtime === null) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
Support::printTime()
|
||||
);
|
||||
} else {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
Support::printTime($microtime)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty array' => [
|
||||
0 => [],
|
||||
1 => "<pre>Array\n(\n)\n</pre>",
|
||||
2 => "Array\n(\n)\n",
|
||||
],
|
||||
'simple array' => [
|
||||
0 => ['a', 'b'],
|
||||
1 => "<pre>Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n</pre>",
|
||||
2 => "Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printAr
|
||||
* @cover ::printArray
|
||||
* @dataProvider printArrayProvider
|
||||
* @testdox printAr/printArray $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $expected
|
||||
* @param string $expected_strip
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintAr(array $input, string $expected, string $expected_strip): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::printAr($input),
|
||||
'assert printAr'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::printArray($input),
|
||||
'assert printArray'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_strip,
|
||||
Support::prAr($input),
|
||||
'assert prAr'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printBoolProvider(): array
|
||||
{
|
||||
return [
|
||||
'true input default' => [
|
||||
0 => true,
|
||||
1 => [],
|
||||
2 => 'true',
|
||||
3 => 'true',
|
||||
],
|
||||
'false input default' => [
|
||||
0 => false,
|
||||
1 => [],
|
||||
2 => 'false',
|
||||
3 => 'false'
|
||||
],
|
||||
'false input param name' => [
|
||||
0 => false,
|
||||
1 => [
|
||||
'name' => 'param test'
|
||||
],
|
||||
2 => '<b>param test</b>: false',
|
||||
3 => 'false'
|
||||
],
|
||||
'true input param name, true override' => [
|
||||
0 => true,
|
||||
1 => [
|
||||
'name' => 'param test',
|
||||
'true' => 'ok',
|
||||
],
|
||||
2 => '<b>param test</b>: ok',
|
||||
3 => 'ok',
|
||||
],
|
||||
'false input param name, true override, false override' => [
|
||||
0 => false,
|
||||
1 => [
|
||||
'name' => 'param test',
|
||||
'true' => 'ok',
|
||||
'false' => 'not',
|
||||
],
|
||||
2 => '<b>param test</b>: not',
|
||||
3 => 'not'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printBool
|
||||
* @dataProvider printBoolProvider
|
||||
* @testdox printBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param bool $input
|
||||
* @param array $params
|
||||
* @param string $expected
|
||||
* @param string $expected_strip
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintBool(bool $input, array $params, string $expected, string $expected_strip): void
|
||||
{
|
||||
if (
|
||||
isset($params['name']) &&
|
||||
isset($params['true']) &&
|
||||
isset($params['false'])
|
||||
) {
|
||||
$string = Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true'],
|
||||
$params['false']
|
||||
);
|
||||
$string_strip = Support::prBl(
|
||||
$input,
|
||||
$params['true'],
|
||||
$params['false']
|
||||
);
|
||||
} elseif (isset($params['name']) && isset($params['true'])) {
|
||||
$string = Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true']
|
||||
);
|
||||
$string_strip = Support::prBl(
|
||||
$input,
|
||||
$params['true'],
|
||||
);
|
||||
} elseif (isset($params['name'])) {
|
||||
$string = Support::printBool(
|
||||
$input,
|
||||
$params['name']
|
||||
);
|
||||
$string_strip = Support::prBl(
|
||||
$input
|
||||
);
|
||||
} else {
|
||||
$string = Support::printBool($input);
|
||||
$string_strip = Support::prBl($input);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$string,
|
||||
'assert printBool'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_strip,
|
||||
$string_strip,
|
||||
'assert prBl'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printToStringProvider(): array
|
||||
{
|
||||
// 0: unput
|
||||
// 1: html flag (only for strings and arry)
|
||||
// 2: expected
|
||||
return [
|
||||
'null' => [
|
||||
null,
|
||||
null,
|
||||
'NULL',
|
||||
],
|
||||
'string' => [
|
||||
'a string',
|
||||
null,
|
||||
'a string',
|
||||
],
|
||||
'string with html chars, encode' => [
|
||||
'a string with <> &',
|
||||
true,
|
||||
'a string with <> &',
|
||||
],
|
||||
'string with html chars' => [
|
||||
'a string with <> &',
|
||||
null,
|
||||
'a string with <> &',
|
||||
],
|
||||
'a number' => [
|
||||
1234,
|
||||
null,
|
||||
'1234',
|
||||
],
|
||||
'a float number' => [
|
||||
1234.5678,
|
||||
null,
|
||||
'1234.5678',
|
||||
],
|
||||
'bool true' => [
|
||||
true,
|
||||
null,
|
||||
'TRUE',
|
||||
],
|
||||
'bool false' => [
|
||||
false,
|
||||
null,
|
||||
'FALSE',
|
||||
],
|
||||
'an array default' => [
|
||||
['a', 'b'],
|
||||
null,
|
||||
"<pre>Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n</pre>",
|
||||
],
|
||||
'an array, no html' => [
|
||||
['a', 'b'],
|
||||
true,
|
||||
"Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n",
|
||||
],
|
||||
// resource
|
||||
'a resource' => [
|
||||
tmpfile(),
|
||||
null,
|
||||
'/^Resource id #\d+$/',
|
||||
],
|
||||
// object
|
||||
'an object' => [
|
||||
new \CoreLibs\Debug\Support(),
|
||||
null,
|
||||
'CoreLibs\Debug\Support',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printToString
|
||||
* @dataProvider printToStringProvider
|
||||
* @testdox printToString $input with $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input anything
|
||||
* @param boolean|null $flag html flag, only for string and array
|
||||
* @param string $expected always string
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintToString(mixed $input, ?bool $flag, string $expected): void
|
||||
{
|
||||
if ($flag === null) {
|
||||
// if expected starts with / and ends with / then this is a regex compare
|
||||
if (
|
||||
substr($expected, 0, 1) == '/' &&
|
||||
substr($expected, -1, 1) == '/'
|
||||
) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected,
|
||||
Support::printToString($input)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::printToString($input)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::printToString($input, $flag)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerDumpExportVar(): array
|
||||
{
|
||||
return [
|
||||
'string' => [
|
||||
'input' => 'string',
|
||||
'flag' => null,
|
||||
'expected_dump' => 'string(6) "string"' . "\n",
|
||||
'expected_export' => "<pre>'string'</pre>",
|
||||
],
|
||||
'string, no html' => [
|
||||
'input' => 'string',
|
||||
'flag' => true,
|
||||
'expected_dump' => 'string(6) "string"' . "\n",
|
||||
'expected_export' => "'string'",
|
||||
],
|
||||
// int
|
||||
'int' => [
|
||||
'input' => 6,
|
||||
'flag' => null,
|
||||
'expected_dump' => 'int(6)' . "\n",
|
||||
'expected_export' => "<pre>6</pre>",
|
||||
],
|
||||
// float
|
||||
'float' => [
|
||||
'input' => 1.6,
|
||||
'flag' => null,
|
||||
'expected_dump' => 'float(1.6)' . "\n",
|
||||
'expected_export' => "<pre>1.6</pre>",
|
||||
],
|
||||
// bool
|
||||
'bool' => [
|
||||
'input' => true,
|
||||
'flag' => null,
|
||||
'expected_dump' => 'bool(true)' . "\n",
|
||||
'expected_export' => "<pre>true</pre>",
|
||||
],
|
||||
// array
|
||||
'array' => [
|
||||
'input' => ['string', true],
|
||||
'flag' => null,
|
||||
'expected_dump' => "array(2) {\n"
|
||||
. " [0]=>\n"
|
||||
. " string(6) \"string\"\n"
|
||||
. " [1]=>\n"
|
||||
. " bool(true)\n"
|
||||
. "}\n",
|
||||
'expected_export' => "<pre>array (\n"
|
||||
. " 0 => 'string',\n"
|
||||
. " 1 => true,\n"
|
||||
. ")</pre>",
|
||||
],
|
||||
// more
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::dumpVar
|
||||
* @cover ::exportVar
|
||||
* @dataProvider providerDumpExportVar
|
||||
* @testdox dump/exportVar $input with $flag will be $expected_dump / $expected_export [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $flag
|
||||
* @param string $expected_dump
|
||||
* @param string $expected_export
|
||||
* @return void
|
||||
*/
|
||||
public function testDumpExportVar(mixed $input, ?bool $flag, string $expected_dump, string $expected_export): void
|
||||
{
|
||||
if ($flag === null) {
|
||||
$dump = Support::dumpVar($input);
|
||||
$export = Support::exportVar($input);
|
||||
} else {
|
||||
$dump = Support::dumpVar($input, $flag);
|
||||
$export = Support::exportVar($input, $flag);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected_dump,
|
||||
$dump,
|
||||
'assert dumpVar'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_export,
|
||||
$export,
|
||||
'assert dumpVar'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerFileLine
|
||||
* @testWith ["vendor/phpunit/phpunit/src/Framework/TestCase.php:"]
|
||||
* @testdox getCallerFileLine check based on regex /[\w\-\/]/vendor/phpunit/phpunit/src/Framework/TestCase.php:\d+ [$_dataName]
|
||||
*
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerFileLine(): void
|
||||
{
|
||||
// regex prefix with path "/../" and then fixed vendor + \d+
|
||||
$regex = "/^\/[\w\-\/]+\/vendor\/phpunit\/phpunit\/src\/Framework\/TestCase.php:\d+$/";
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
Support::getCallerFileLine()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethod
|
||||
* @testWith ["testGetCallerMethod"]
|
||||
* @testdox getCallerMethod check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethod(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerMethod()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethodList
|
||||
* @testWith [["main", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"]]
|
||||
* @testdox getCallerMethodList check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethodList(array $expected): void
|
||||
{
|
||||
$compare = Support::getCallerMethodList();
|
||||
// 10: legact
|
||||
// 11: direct
|
||||
// 12: full call
|
||||
switch (count($compare)) {
|
||||
case 10:
|
||||
// add nothing
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerMethodList(),
|
||||
'assert expected 10'
|
||||
);
|
||||
break;
|
||||
case 11:
|
||||
// add one "run" before "runBare"
|
||||
// array_splice(
|
||||
// $expected,
|
||||
// 7,
|
||||
// 0,
|
||||
// ['run']
|
||||
// );
|
||||
array_splice(
|
||||
$expected,
|
||||
0,
|
||||
0,
|
||||
['include']
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerMethodList(),
|
||||
'assert expected 11'
|
||||
);
|
||||
break;
|
||||
case 12:
|
||||
// add two "run" before "runBare"
|
||||
array_splice(
|
||||
$expected,
|
||||
7,
|
||||
0,
|
||||
['run']
|
||||
);
|
||||
array_splice(
|
||||
$expected,
|
||||
0,
|
||||
0,
|
||||
['include']
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerMethodList(),
|
||||
'assert expected 12'
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test the lowest one (one above base)
|
||||
*
|
||||
* @cover ::getCallerClass
|
||||
* @testWith ["tests\\CoreLibsDebugSupportTest"]
|
||||
* @testdox getCallerClass check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerClass(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerClass()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test highest return (top level)
|
||||
*
|
||||
* @cover ::getCallerTopLevelClass
|
||||
* @testWith ["PHPUnit\\TextUI\\Command"]
|
||||
* @testdox getCallerTopLevelClass check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerTopLevelClass(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerTopLevelClass()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test highest return (top level)
|
||||
*
|
||||
* @cover ::getCallerClassMethod
|
||||
* @testWith ["tests\\CoreLibsDebugSupportTest->testGetCallerClassMethod"]
|
||||
* @testdox getCallerClassMethod check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerClassMethod(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::getCallerClassMethod()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function debugStringProvider(): array
|
||||
{
|
||||
// 0: input string
|
||||
// 1: replace
|
||||
// 2: html flag
|
||||
// 3: expected
|
||||
return [
|
||||
'null string, default' => [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'-'
|
||||
],
|
||||
'empty string, ... replace' => [
|
||||
'',
|
||||
'...',
|
||||
null,
|
||||
'...'
|
||||
],
|
||||
'filled string' => [
|
||||
'some string',
|
||||
null,
|
||||
null,
|
||||
'some string'
|
||||
],
|
||||
'string with html chars, encode' => [
|
||||
'a string with <> &',
|
||||
'-',
|
||||
true,
|
||||
'a string with <> &',
|
||||
],
|
||||
'string with html chars' => [
|
||||
'a string with <> &',
|
||||
'-',
|
||||
null,
|
||||
'a string with <> &',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::debugString
|
||||
* @dataProvider debugStringProvider
|
||||
* @testdox debugString $input with replace $replace and html $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string|null $replace
|
||||
* @param bool|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testDebugString(?string $input, ?string $replace, ?bool $flag, string $expected): void
|
||||
{
|
||||
if ($replace === null && $flag === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::debugString($input),
|
||||
'assert all default'
|
||||
);
|
||||
} elseif ($flag === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::debugString($input, $replace),
|
||||
'assert flag default'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
Support::debugString($input, $replace, $flag),
|
||||
'assert all set'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
3
4dev/tests/Debug/log/.gitignore
vendored
Normal file
3
4dev/tests/Debug/log/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*log
|
||||
*LOG
|
||||
!.gitignore
|
||||
@@ -77,21 +77,24 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
'file' => 'cannot_read.env',
|
||||
'status' => 2,
|
||||
'content' => [],
|
||||
'chmod' => '000',
|
||||
// 0000
|
||||
'chmod' => '100000',
|
||||
],
|
||||
'empty file' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'empty.env',
|
||||
'status' => 1,
|
||||
'content' => [],
|
||||
'chmod' => null,
|
||||
// 0664
|
||||
'chmod' => '100664',
|
||||
],
|
||||
'override all' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'test.env',
|
||||
'status' => 0,
|
||||
'content' => $dot_env_content,
|
||||
'chmod' => null,
|
||||
// 0664
|
||||
'chmod' => '100664',
|
||||
],
|
||||
'override directory' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
@@ -124,6 +127,16 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
array $expected_env,
|
||||
?string $chmod
|
||||
): void {
|
||||
if (
|
||||
!empty($chmod) &&
|
||||
$chmod == '100000' &&
|
||||
getmyuid() == 0
|
||||
) {
|
||||
$this->markTestSkipped(
|
||||
"Skip cannot read file test because run user is root"
|
||||
);
|
||||
return;
|
||||
}
|
||||
// if we have file + chmod set
|
||||
$old_chmod = null;
|
||||
if (
|
||||
@@ -134,6 +147,20 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
$old_chmod = fileperms($folder . DIRECTORY_SEPARATOR . $file);
|
||||
chmod($folder . DIRECTORY_SEPARATOR . $file, octdec($chmod));
|
||||
}
|
||||
$message = '\CoreLibs\Get\DotEnv is deprecated in favor for '
|
||||
. 'composer package gullevek\dotenv which is a copy of this';
|
||||
// convert E_USER_DEPRECATED to a exception
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// tests are never run -> deprecated
|
||||
if (is_file($folder . DIRECTORY_SEPARATOR . $file)) {
|
||||
chmod($folder . DIRECTORY_SEPARATOR . $file, 0664);
|
||||
}
|
||||
$this->expectExceptionMessage($message);
|
||||
if ($folder !== null && $file !== null) {
|
||||
$status = DotEnv::readEnvFile($folder, $file);
|
||||
} elseif ($folder !== null) {
|
||||
@@ -141,6 +168,7 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
} else {
|
||||
$status = DotEnv::readEnvFile();
|
||||
}
|
||||
restore_error_handler();
|
||||
$this->assertEquals(
|
||||
$status,
|
||||
$expected_status,
|
||||
@@ -153,8 +181,9 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
'Assert _ENV correct'
|
||||
);
|
||||
// if we have file and chmod unset
|
||||
if ($old_chmod !== null) {
|
||||
chmod($folder . DIRECTORY_SEPARATOR . $file, $old_chmod);
|
||||
print "Write mode: $old_chmod\n";
|
||||
if ($old_chmod !== null && $chmod == '100000') {
|
||||
chmod($folder . DIRECTORY_SEPARATOR . $file, 0664);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,17 +67,17 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
'original set' => [
|
||||
0 => null,
|
||||
1 => 'NOHOST',
|
||||
2 => 'NOPORT',
|
||||
2 => 0,
|
||||
],
|
||||
'override set no port' => [
|
||||
0 => 'foo.org',
|
||||
1 => 'foo.org',
|
||||
2 => '80'
|
||||
2 => 80
|
||||
],
|
||||
'override set with port' => [
|
||||
0 => 'foo.org:443',
|
||||
1 => 'foo.org',
|
||||
2 => '443'
|
||||
2 => 443
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -99,7 +99,7 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
1 => 'phpunit',
|
||||
2 => 'phpunit',
|
||||
// NOTE: this can change, so it is a regex check
|
||||
3 => "/^(\/?.*\/?)?www\/vendor\/bin\/phpunit$/",
|
||||
3 => "/^(\/?.*\/?)?vendor\/bin\/phpunit$/",
|
||||
],
|
||||
'some path with extension' => [
|
||||
0 => '/some/path/to/file.txt',
|
||||
@@ -138,10 +138,10 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected_host
|
||||
* @param string $expected_port
|
||||
* @param int $expected_port
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHostNanme(?string $input, string $expected_host, string $expected_port): void
|
||||
public function testGetHostNanme(?string $input, string $expected_host, int $expected_port): void
|
||||
{
|
||||
// print "HOSTNAME: " . $_SERVER['HTTP_HOST'] . "<br>";
|
||||
// print "SERVER: " . print_r($_SERVER, true) . "\n";
|
||||
568
4dev/tests/Language/CoreLibsLanguageGetLocaleTest.php
Normal file
568
4dev/tests/Language/CoreLibsLanguageGetLocaleTest.php
Normal file
@@ -0,0 +1,568 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Language\GetLocale
|
||||
*
|
||||
* @coversDefaultClass \CoreLibs\Language\GetLocale
|
||||
* @testdox \CoreLibs\Language\GetLocale method tests
|
||||
*/
|
||||
final class CoreLibsLanguageGetLocaleTest extends TestCase
|
||||
{
|
||||
public const SITE_ENCODING = 'UTF-8';
|
||||
public const SITE_LOCALE = 'en_US.UTF-8';
|
||||
public const SITE_DOMAIN = 'admin';
|
||||
public const LOCALE_PATH = __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* set all constant variables that must be set before call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// default web page encoding setting
|
||||
/* if (!defined('DEFAULT_ENCODING')) {
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
}
|
||||
if (!defined('DEFAULT_LOCALE')) {
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
}
|
||||
// site
|
||||
if (!defined('SITE_ENCODING')) {
|
||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||
}
|
||||
if (!defined('SITE_LOCALE')) {
|
||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||
} */
|
||||
// just set
|
||||
/* if (!defined('BASE')) {
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('INCLUDES')) {
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LANG')) {
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LOCALE')) {
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CONTENT_PATH')) {
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
} */
|
||||
// array session
|
||||
$_SESSION = [];
|
||||
global $_SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
/* public function setLocaleProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: SESSION: DEFAULT_LOCALE
|
||||
// 5: SESSION: DEFAULT_CHARSET
|
||||
// 6: expected array
|
||||
// 7: deprecation message
|
||||
'no params, all default constants' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $locale or unset SESSION locale is deprecated',
|
||||
],
|
||||
'no params, session charset and lang' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja_JP', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $domain is deprecated'
|
||||
],
|
||||
'no params, session charset and lang short' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $domain is deprecated',
|
||||
],
|
||||
// param lang (no sessions)
|
||||
'locale param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $domain is deprecated',
|
||||
],
|
||||
// different locale setting
|
||||
'locale complex param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja_JP.SJIS', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP.SJIS',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'SJIS',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $domain is deprecated',
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $path is deprecated',
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $path is deprecated'
|
||||
],
|
||||
// lang, domain, path (no override)
|
||||
'locale, domain and path, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', '', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
null
|
||||
],
|
||||
// all params set (no override)
|
||||
'all parameter, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja', 'admin', 'UTF-8', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
null
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'long locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'de_CH.UTF-8@euro', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'de_CH.UTF-8@euro',
|
||||
'lang' => 'de_CH',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
'setLocale: Unset $path is deprecated',
|
||||
],
|
||||
// TODO invalid params (bad path) (no override)
|
||||
// TODO param calls, but with override set
|
||||
];
|
||||
} */
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLocale
|
||||
* @dataProvider setLocaleProvider
|
||||
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
|
||||
*
|
||||
* @param string|null $language
|
||||
* @param string|null $domain
|
||||
* @param string|null $encoding
|
||||
* @param string|null $path
|
||||
* @param string|null $SESSION_DEFAULT_LOCALE
|
||||
* @param string|null $SESSION_DEFAULT_CHARSET
|
||||
* @param array<mixed> $expected
|
||||
* @param string|null $deprecation_message
|
||||
* @return void
|
||||
*/
|
||||
/* public function testsetLocale(
|
||||
?string $language,
|
||||
?string $domain,
|
||||
?string $encoding,
|
||||
?string $path,
|
||||
?string $SESSION_DEFAULT_LOCALE,
|
||||
?string $SESSION_DEFAULT_CHARSET,
|
||||
array $expected,
|
||||
?string $deprecation_message
|
||||
): void {
|
||||
$return_lang_settings = [];
|
||||
global $_SESSION;
|
||||
// set override
|
||||
if ($SESSION_DEFAULT_LOCALE !== null) {
|
||||
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
|
||||
}
|
||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
||||
}
|
||||
if ($deprecation_message !== null) {
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// catch this with the message
|
||||
$this->expectExceptionMessage($deprecation_message);
|
||||
}
|
||||
// function call
|
||||
if (
|
||||
$language === null && $domain === null &&
|
||||
$encoding === null && $path === null
|
||||
) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale();
|
||||
} elseif (
|
||||
$language !== null && $domain === null &&
|
||||
$encoding === null && $path === null
|
||||
) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language
|
||||
);
|
||||
} elseif (
|
||||
$language !== null && $domain !== null &&
|
||||
$encoding === null && $path === null
|
||||
) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain
|
||||
);
|
||||
} elseif (
|
||||
$language !== null && $domain !== null &&
|
||||
$encoding !== null && $path === null
|
||||
) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding
|
||||
);
|
||||
} else {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding,
|
||||
$path
|
||||
);
|
||||
}
|
||||
restore_error_handler();
|
||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
||||
|
||||
foreach (
|
||||
[
|
||||
'locale', 'lang', 'domain', 'encoding', 'path'
|
||||
] as $key
|
||||
) {
|
||||
$value = $expected[$key];
|
||||
if (strpos($value, "/") === 0) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert regex failed for ' . $key
|
||||
);
|
||||
} else {
|
||||
// assert equal
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert equal failed for ' . $key
|
||||
);
|
||||
}
|
||||
}
|
||||
// unset all vars
|
||||
$_SESSION = [];
|
||||
unset($GLOBALS['OVERRIDE_LANG']);
|
||||
} */
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function setLocaleFromSessionProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: SESSION: DEFAULT_LOCALE
|
||||
// 5: SESSION: DEFAULT_CHARSET
|
||||
// 5: SESSION: DEFAULT_DOMAIN
|
||||
// 6: SESSION: LOCALE_PATH
|
||||
// 6: expected array
|
||||
// 7: deprecation message
|
||||
'all session vars set' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'ja_JP.UTF-8', 'UTF-8', 'admin', __DIR__ . '/locale_other/',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP.UTF-8',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'no session set, only parameters' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
null, null, null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// special parse session check for locales
|
||||
'all session vars set, short lang' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'ja', 'UTF-8', 'admin', __DIR__ . '/locale_other/',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// lang with modifier
|
||||
// param lang and domain (no override)
|
||||
'long locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'de_CH.UTF-8@euro', 'admin', 'UTF-8', __DIR__ . '/includes/locale/',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'de_CH.UTF-8@euro',
|
||||
'lang' => 'de_CH',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// missing session values check
|
||||
// special parse session check for locales
|
||||
'session missing encoding, set from parameters' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'ja', null, 'admin', __DIR__ . '/locale_other/',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// null return check for invalid entries
|
||||
'no session set, only parameters, all invalid' => [
|
||||
// lang, domain, encoding, path
|
||||
'###', '&&&&', '$$$$', 'foo_bar_path',
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
null, null, null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => null,
|
||||
'lang' => null,
|
||||
'domain' => null,
|
||||
'encoding' => null,
|
||||
'path' => null,
|
||||
],
|
||||
],
|
||||
// invalid session names, fall backup
|
||||
'all session vars are invalid, fallback' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'###', '&&&&', '$$$$', 'foo_bar_path',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLocale
|
||||
* @dataProvider setLocaleFromSessionProvider
|
||||
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
|
||||
*
|
||||
* @param string| $language
|
||||
* @param string| $domain
|
||||
* @param string| $encoding
|
||||
* @param string| $path
|
||||
* @param string|null $SESSION_DEFAULT_LOCALE
|
||||
* @param string|null $SESSION_DEFAULT_CHARSET
|
||||
* @param string|null $SESSION_DEFAULT_DOMAIN
|
||||
* @param string|null $SESSION_LOCALE_PATH
|
||||
* @param array<mixed> $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testsetLocaleFromSession(
|
||||
string $language,
|
||||
string $domain,
|
||||
string $encoding,
|
||||
string $path,
|
||||
?string $SESSION_DEFAULT_LOCALE,
|
||||
?string $SESSION_DEFAULT_CHARSET,
|
||||
?string $SESSION_DEFAULT_DOMAIN,
|
||||
?string $SESSION_LOCALE_PATH,
|
||||
array $expected,
|
||||
): void {
|
||||
$return_lang_settings = [];
|
||||
global $_SESSION;
|
||||
// set override
|
||||
if ($SESSION_DEFAULT_LOCALE !== null) {
|
||||
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
|
||||
}
|
||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
||||
}
|
||||
if ($SESSION_DEFAULT_DOMAIN !== null) {
|
||||
$_SESSION['DEFAULT_DOMAIN'] = $SESSION_DEFAULT_DOMAIN;
|
||||
}
|
||||
if ($SESSION_LOCALE_PATH !== null) {
|
||||
$_SESSION['LOCALE_PATH'] = $SESSION_LOCALE_PATH;
|
||||
}
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocaleFromSession(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding,
|
||||
$path
|
||||
);
|
||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
||||
foreach (
|
||||
[
|
||||
'locale', 'lang', 'domain', 'encoding', 'path'
|
||||
] as $key
|
||||
) {
|
||||
$value = $expected[$key];
|
||||
if (
|
||||
!empty($value) &&
|
||||
strpos($value, "/") === 0
|
||||
) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
$return_lang_settings[$key] ?? '',
|
||||
'assert regex failed for ' . $key
|
||||
);
|
||||
} else {
|
||||
// assert equal
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert equal failed for ' . $key
|
||||
);
|
||||
}
|
||||
}
|
||||
// unset all vars
|
||||
$_SESSION = [];
|
||||
unset($GLOBALS['OVERRIDE_LANG']);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -22,37 +22,16 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// default web page encoding setting
|
||||
if (!defined('DEFAULT_ENCODING')) {
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
}
|
||||
if (!defined('DEFAULT_LOCALE')) {
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
}
|
||||
// site
|
||||
if (!defined('SITE_ENCODING')) {
|
||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||
}
|
||||
if (!defined('SITE_LOCALE')) {
|
||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||
}
|
||||
// just set
|
||||
// for deprecation test only, will be removed
|
||||
if (!defined('BASE')) {
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
define('BASE', str_replace(DIRECTORY_SEPARATOR . 'configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('INCLUDES')) {
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LANG')) {
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LOCALE')) {
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CONTENT_PATH')) {
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,77 +84,163 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 1: encoding
|
||||
// 2: domain
|
||||
// 3: path
|
||||
// 4: locale expected
|
||||
// 5: locale set expected
|
||||
// 6: domain exepcted
|
||||
// 7: context (null for none)
|
||||
// 8: test string in
|
||||
// 9: test translated
|
||||
// 6: lang expected
|
||||
// 7: lang short expected
|
||||
// 8: encoding expected
|
||||
// 9: domain exepcted
|
||||
// 10: context (null for none)
|
||||
// 11: test string in
|
||||
// 12: test translated
|
||||
// 13: deprecation message (until removed)
|
||||
// new style load
|
||||
'gettext load en' => [
|
||||
'en_US.UTF-8',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
//
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// 4, 5, 6, 7, 8, 9
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'en_US',
|
||||
'en',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
// 10
|
||||
null,
|
||||
// 11, 12
|
||||
'Original',
|
||||
'Translated frontend en_US',
|
||||
// 13
|
||||
null,
|
||||
],
|
||||
'gettext load en' => [
|
||||
'en_US.UTF-8',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'en_US',
|
||||
'en',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
//
|
||||
'context',
|
||||
//
|
||||
'Original',
|
||||
'Original context frontend en_US',
|
||||
//
|
||||
null,
|
||||
],
|
||||
'gettext load ja' => [
|
||||
'ja_JP.UTF-8',
|
||||
'UTF-8',
|
||||
'admin',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
//
|
||||
'ja_JP.UTF-8',
|
||||
'ja_JP',
|
||||
'ja_JP',
|
||||
'ja',
|
||||
'UTF-8',
|
||||
'admin',
|
||||
//
|
||||
null,
|
||||
//
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
//
|
||||
null,
|
||||
],
|
||||
// mixed path and domain
|
||||
'mixed path and domain' => [
|
||||
// load short locale with different encoding
|
||||
'gettext load short ja no encoding' => [
|
||||
'ja',
|
||||
'SJIS',
|
||||
'admin',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
//
|
||||
'ja',
|
||||
'ja',
|
||||
'ja',
|
||||
'ja',
|
||||
'SJIS',
|
||||
'admin',
|
||||
//
|
||||
null,
|
||||
//
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
//
|
||||
null,
|
||||
],
|
||||
// mixed path and domain [DEPRECATED]
|
||||
'mixed path and domain [DEPRECATED]' => [
|
||||
'en_US.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'UTF-8',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
'frontend',
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'en_US',
|
||||
'en',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
//
|
||||
'context',
|
||||
//
|
||||
'Original',
|
||||
'Original context frontend en_US',
|
||||
//
|
||||
'L10n constructor parameter switch is no longer supported. domain is 2nd, path is 3rd parameter'
|
||||
],
|
||||
// unset path
|
||||
'unset path with locale and domain [DEPRECATED]' => [
|
||||
'ja_JP.UTF-8',
|
||||
'UTF-8',
|
||||
'admin',
|
||||
null,
|
||||
//
|
||||
'ja_JP.UTF-8',
|
||||
'ja_JP',
|
||||
'ja_JP',
|
||||
'ja',
|
||||
'UTF-8',
|
||||
'admin',
|
||||
//
|
||||
null,
|
||||
//
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
//
|
||||
'Empty path parameter is no longer allowed if locale and domain are set',
|
||||
],
|
||||
// null set
|
||||
'empty load new ' => [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
//
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'', // unset on empty call
|
||||
'',
|
||||
//
|
||||
null,
|
||||
//
|
||||
'Original',
|
||||
'Original',
|
||||
//
|
||||
null,
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -188,37 +253,62 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName]
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @param string|null $encoding
|
||||
* @param string|null $domain
|
||||
* @param string|null $path
|
||||
* @param string $locale_expected
|
||||
* @param string $locale_set_expected
|
||||
* @param string $lang_expected
|
||||
* @param string $lang_short_expected
|
||||
* @param string $encoding_expected
|
||||
* @param string $domain_expected
|
||||
* @param ?string $context
|
||||
* @param string|null $context
|
||||
* @param string $original
|
||||
* @param string $translated
|
||||
* @param string|null $deprecation_message
|
||||
* @return void
|
||||
*/
|
||||
public function testL10nObject(
|
||||
?string $locale,
|
||||
?string $encoding,
|
||||
?string $domain,
|
||||
?string $path,
|
||||
string $locale_expected,
|
||||
string $locale_set_expected,
|
||||
string $lang_expected,
|
||||
string $lang_short_expected,
|
||||
string $encoding_expected,
|
||||
string $domain_expected,
|
||||
?string $context,
|
||||
string $original,
|
||||
string $translated
|
||||
string $translated,
|
||||
?string $deprecation_message
|
||||
): void {
|
||||
if ($deprecation_message !== null) {
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// catch this with the message
|
||||
$this->expectExceptionMessage($deprecation_message);
|
||||
}
|
||||
if ($locale === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n();
|
||||
} elseif ($domain === null) {
|
||||
// deprecated, locale + domain must be set, handled like empty calls
|
||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||
} elseif ($path === null) {
|
||||
// deprecated, path must be set, will thow DEPRECATION error, handled like empty
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||
} else {
|
||||
} elseif ($encoding === null) {
|
||||
// if encoding not found will be UTF-8
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||
} else {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path, $encoding);
|
||||
}
|
||||
// print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
|
||||
restore_error_handler();
|
||||
// print "MO: " . $l10n->getMoFile() . "\n";
|
||||
$this->assertEquals(
|
||||
$locale_expected,
|
||||
@@ -248,6 +338,20 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'Translated string assert failed in context: ' . $context
|
||||
);
|
||||
}
|
||||
// test get locel as array
|
||||
$locale = $l10n->getLocaleAsArray();
|
||||
$this->assertEquals(
|
||||
[
|
||||
'locale' => $locale_expected,
|
||||
'lang' => $lang_expected,
|
||||
'lang_short' => $lang_short_expected,
|
||||
'domain' => $domain_expected,
|
||||
'encoding' => $encoding_expected,
|
||||
'path' => $path
|
||||
],
|
||||
$locale,
|
||||
'getLocaleAsArray mismatch'
|
||||
);
|
||||
}
|
||||
|
||||
// l10nReloadMOfile and getTranslator
|
||||
@@ -283,7 +387,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// set 0-2
|
||||
'en_US.UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// status 3
|
||||
false,
|
||||
// to translate 4
|
||||
@@ -296,7 +400,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// set new 8-10
|
||||
'ja_JP.UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// status new 11
|
||||
false,
|
||||
// check new setter 12-14
|
||||
@@ -322,7 +426,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// set new 8-10
|
||||
'en_US.UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// status new 11
|
||||
false,
|
||||
// check new setter 12-14
|
||||
@@ -387,12 +491,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
string $domain_expected_b,
|
||||
string $translated_b
|
||||
): void {
|
||||
if ($locale === null) {
|
||||
if ($locale === null || $domain === null || $path === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n();
|
||||
} elseif ($domain === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||
} elseif ($path === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||
} else {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||
}
|
||||
@@ -494,16 +594,16 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: path
|
||||
// 2: domain
|
||||
// 1: domain
|
||||
// 2: path
|
||||
// 3: context (null for none)
|
||||
// 4: single string
|
||||
// 5: plural string
|
||||
// 6: array for each n value expected string
|
||||
'plural text en' => [
|
||||
'en_US',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'admin',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// context
|
||||
null,
|
||||
// text single/multi in
|
||||
@@ -518,8 +618,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
],
|
||||
'plural text context en' => [
|
||||
'en_US',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'admin',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// context
|
||||
'context',
|
||||
// text single/multi in
|
||||
@@ -544,8 +644,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @testdox plural string test for locale $locale and domain $domain with $context [$_dataName]
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $path
|
||||
* @param string $domain
|
||||
* @param string $path
|
||||
* @param ?string $context
|
||||
* @param string $original_single
|
||||
* @param string $original_plural
|
||||
@@ -555,8 +655,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
public function testNgettext(
|
||||
// config 0-3
|
||||
string $locale,
|
||||
string $path,
|
||||
string $domain,
|
||||
string $path,
|
||||
// context string
|
||||
?string $context,
|
||||
// input strings
|
||||
@@ -565,7 +665,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// expected
|
||||
array $expected_strings
|
||||
): void {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain, false);
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||
|
||||
foreach ($expected_strings as $n => $expected) {
|
||||
if (empty($context)) {
|
||||
@@ -981,7 +1081,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'standard en' => [
|
||||
'en_US.UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
'UTF-8',
|
||||
'Original',
|
||||
'Translated frontend en_US',
|
||||
@@ -989,7 +1089,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'standard ja' => [
|
||||
'ja_JP.UTF-8',
|
||||
'admin',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
'UTF-8',
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
@@ -1030,6 +1130,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
_textdomain($domain);
|
||||
_bindtextdomain($domain, $path);
|
||||
_bind_textdomain_codeset($domain, $encoding);
|
||||
|
||||
$this->assertEquals(
|
||||
$translated,
|
||||
__($original),
|
||||
1
4dev/tests/Language/includes/locale/ja
Symbolic link
1
4dev/tests/Language/includes/locale/ja
Symbolic link
@@ -0,0 +1 @@
|
||||
ja_JP
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user