Compare commits
340 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae044bee6f | ||
|
|
529b6a75ba | ||
|
|
8de112ba7e | ||
|
|
ad070ebdf4 | ||
|
|
9edfc2acb6 | ||
|
|
35cc6dbf91 | ||
|
|
cb3d5e1f27 | ||
|
|
0a45300c21 | ||
|
|
54ce378ae2 | ||
|
|
4ac659f7d9 | ||
|
|
497833ca71 | ||
|
|
e5a9b149b1 | ||
|
|
5213805a58 | ||
|
|
a9f1d878f7 | ||
|
|
3845bc7ff5 | ||
|
|
32c192a362 | ||
|
|
2bd68f32ac | ||
|
|
f5964fed02 | ||
|
|
625272198d | ||
|
|
00821bd5ea | ||
|
|
921b9cb3d9 | ||
|
|
720b78b687 | ||
|
|
565014e1e2 | ||
|
|
d9bcb577d7 | ||
|
|
8613e8977b | ||
|
|
0c51a3be87 | ||
|
|
f9cf36524e | ||
|
|
bacb9881ac | ||
|
|
f0fae1f76d | ||
|
|
1653e6b684 | ||
|
|
c8bc0062ad | ||
|
|
5c8a2ef8da | ||
|
|
d8379a10d9 | ||
|
|
30e2f33620 | ||
|
|
a4f16f4ca9 | ||
|
|
6e7b9cd033 | ||
|
|
4bc2ad8fa0 | ||
|
|
0d4e959f39 | ||
|
|
95d567545a | ||
|
|
d89c6d1bde | ||
|
|
337ebb9032 | ||
|
|
9538ebce7b | ||
|
|
1bff19f4b6 | ||
|
|
66dc72ec67 | ||
|
|
f781b5e55f | ||
|
|
934db50b3a | ||
|
|
573588ad3c | ||
|
|
d04addba81 | ||
|
|
a50a38fd40 | ||
|
|
3c5200cd99 | ||
|
|
50a4b88f55 | ||
|
|
e82929f512 | ||
|
|
5fc55c53b8 | ||
|
|
47da4d02ff | ||
|
|
9d131cf6dd | ||
|
|
dfcae20f64 | ||
|
|
61e489ee4c | ||
|
|
29982f90bc | ||
|
|
7cced63c4b | ||
|
|
06c2ea5e0d | ||
|
|
2e9239ec23 | ||
|
|
0c89840dba | ||
|
|
db144493f3 | ||
|
|
5cec54d508 | ||
|
|
8e60c992f1 | ||
|
|
1b5437b675 | ||
|
|
ef80cba561 | ||
|
|
2d71e760e8 | ||
|
|
a8d07634ff | ||
|
|
aa2b60973e | ||
|
|
554dd5f73c | ||
|
|
e6f9559fbb | ||
|
|
770d6f30a4 | ||
|
|
f94f6cbe87 | ||
|
|
9b69390fa2 | ||
|
|
0524d8ac1b | ||
|
|
e933022671 | ||
|
|
c549d34e65 | ||
|
|
f4ff31721b | ||
|
|
21ac91d2e6 | ||
|
|
2d98d26d0b | ||
|
|
3fda1bef60 | ||
|
|
4f1104c36e | ||
|
|
db1007ef12 | ||
|
|
13c76efcef | ||
|
|
f59c325b05 | ||
|
|
aac5157173 | ||
|
|
abc2705c64 | ||
|
|
e2fff45b16 | ||
|
|
b6ae3f99d9 | ||
|
|
a377ab4b61 | ||
|
|
ec9275d8d3 | ||
|
|
10ed5b3ea0 | ||
|
|
5f290419c6 | ||
|
|
0152af6e65 | ||
|
|
4adb9fba30 | ||
|
|
672931ee67 | ||
|
|
373a9aff2f | ||
|
|
4e3ceecac8 | ||
|
|
8bf694b2b2 | ||
|
|
caf03421a7 | ||
|
|
facf8adaf7 | ||
|
|
c8158c8224 | ||
|
|
7b9a0043d3 | ||
|
|
6517747fef | ||
|
|
fb7071adc4 | ||
|
|
d96c92f9ef | ||
|
|
d7c0054ea0 | ||
|
|
80d2215f2b | ||
|
|
b18bf937d3 | ||
|
|
4b6c5df74f | ||
|
|
89e3888bf8 | ||
|
|
c46125aef1 | ||
|
|
a8ca5d7a2b | ||
|
|
ae2d6580a2 | ||
|
|
97e1b2b63d | ||
|
|
d632a2599e | ||
|
|
2f81009a97 | ||
|
|
e9799f888b | ||
|
|
94b24b4eae | ||
|
|
a304d29698 | ||
|
|
c4c809be66 | ||
|
|
a3bf38f6cf | ||
|
|
c1b906e701 | ||
|
|
32f8e1440d | ||
|
|
2f8f98642b | ||
|
|
7ab03913ac | ||
|
|
a7853171e0 | ||
|
|
dfdfcf87f2 | ||
|
|
6218e0a6a8 | ||
|
|
a84a745be2 | ||
|
|
312762e92e | ||
|
|
fa4c1f0597 | ||
|
|
438a75af23 | ||
|
|
afd8ff3e31 | ||
|
|
4343af7937 | ||
|
|
d06769c48b | ||
|
|
4c0390f082 | ||
|
|
95bee3dc8c | ||
|
|
65132d8a4a | ||
|
|
b2243cd06d | ||
|
|
8f09b67d86 | ||
|
|
fe459aec80 | ||
|
|
de0ed058ca | ||
|
|
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 | ||
|
|
5be34453ce | ||
|
|
7773b78e17 | ||
|
|
2a3798c8c2 | ||
|
|
bc8303fe5f | ||
|
|
ba89b188d9 | ||
|
|
d15618cde4 | ||
|
|
0fd89727e9 | ||
|
|
a8e75d158b | ||
|
|
4b3fbaa309 | ||
|
|
1a6c65df0e | ||
|
|
24f553a17e | ||
|
|
9a3ea2f7db | ||
|
|
bcdb877d90 | ||
|
|
6d0e528c38 | ||
|
|
7e6474195b | ||
|
|
1795d3ba6c | ||
|
|
e1340acf55 | ||
|
|
b5ead3e266 | ||
|
|
f5daaca598 | ||
|
|
6b4f310cd2 | ||
|
|
7b5bddb529 | ||
|
|
0a6fdf1248 | ||
|
|
3220180d58 | ||
|
|
8c8f14ec74 | ||
|
|
643991c3fd | ||
|
|
c81c46d426 | ||
|
|
d97b173ee7 | ||
|
|
b61152f10e | ||
|
|
0c68ebe652 | ||
|
|
31d0cdb8ad |
43
.eslintrc.js
Normal file
43
.eslintrc.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
module.exports = {
|
||||||
|
'env': {
|
||||||
|
'browser': true,
|
||||||
|
'es6': true,
|
||||||
|
'commonjs': true,
|
||||||
|
'jquery': true
|
||||||
|
},
|
||||||
|
'extends': 'eslint:recommended',
|
||||||
|
'parserOptions': {
|
||||||
|
'ecmaVersion': 6
|
||||||
|
},
|
||||||
|
'rules': {
|
||||||
|
'indent': [
|
||||||
|
'error',
|
||||||
|
'tab',
|
||||||
|
{
|
||||||
|
'SwitchCase': 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'linebreak-style': [
|
||||||
|
'error',
|
||||||
|
'unix'
|
||||||
|
],
|
||||||
|
'quotes': [
|
||||||
|
'error',
|
||||||
|
'single'
|
||||||
|
],
|
||||||
|
'semi': [
|
||||||
|
'error',
|
||||||
|
'always'
|
||||||
|
],
|
||||||
|
'no-console': 'off',
|
||||||
|
'no-unused-vars': [
|
||||||
|
'error', {
|
||||||
|
'vars': 'all',
|
||||||
|
'args': 'after-used',
|
||||||
|
'ignoreRestSiblings': false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// Requires eslint >= v8.14.0
|
||||||
|
'no-constant-binary-expression': 'error'
|
||||||
|
}
|
||||||
|
};
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -0,0 +1,7 @@
|
|||||||
|
.libs
|
||||||
|
node_modules/
|
||||||
|
composer.lock
|
||||||
|
vendor/
|
||||||
|
tools/
|
||||||
|
www/composer.lock
|
||||||
|
www/vendor
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
use Phan\Config;
|
use Phan\Config;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
// "target_php_version" => "8.2",
|
||||||
|
"minimum_target_php_version" => "8.1",
|
||||||
// turn color on (-C)
|
// turn color on (-C)
|
||||||
"color_issue_messages_if_supported" => true,
|
"color_issue_messages_if_supported" => true,
|
||||||
// If true, missing properties will be created when
|
// If true, missing properties will be created when
|
||||||
@@ -94,8 +96,6 @@ return [
|
|||||||
"exclude_analysis_directory_list" => [
|
"exclude_analysis_directory_list" => [
|
||||||
'www/vendor',
|
'www/vendor',
|
||||||
'www/tests',
|
'www/tests',
|
||||||
'www/lib/Smarty',
|
|
||||||
'www/lib/smarty-4.1.0',
|
|
||||||
'www/templates_c',
|
'www/templates_c',
|
||||||
'www/log',
|
'www/log',
|
||||||
'www/tmp',
|
'www/tmp',
|
||||||
@@ -116,8 +116,6 @@ return [
|
|||||||
// ignore the old qq tests
|
// ignore the old qq tests
|
||||||
'www/admin/qq_file_upload_front.php',
|
'www/admin/qq_file_upload_front.php',
|
||||||
'www/admin/qq_file_upload_ajax.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
|
// what not to show as problem
|
||||||
@@ -130,7 +128,12 @@ return [
|
|||||||
'PhanWriteOnlyPublicProperty',
|
'PhanWriteOnlyPublicProperty',
|
||||||
'PhanUnreferencedConstant',
|
'PhanUnreferencedConstant',
|
||||||
'PhanWriteOnlyPublicProperty',
|
'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.
|
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
|
||||||
|
|||||||
12
.phive/phars.xml
Normal file
12
.phive/phars.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phive xmlns="https://phar.io/phive">
|
||||||
|
<phar name="phpunit" version="^9.6" installed="9.6.21" location="./tools/phpunit" copy="false"/>
|
||||||
|
<phar name="phpcbf" version="^3.7.2" installed="3.10.3" location="./tools/phpcbf" copy="false"/>
|
||||||
|
<phar name="phpcs" version="^3.7.2" installed="3.10.3" location="./tools/phpcs" copy="false"/>
|
||||||
|
<phar name="phpstan" version="^1.10.37" installed="1.12.4" location="./tools/phpstan" copy="false"/>
|
||||||
|
<phar name="phan" version="^5.4.2" installed="5.4.3" location="./tools/phan" copy="false"/>
|
||||||
|
<phar name="psalm" version="^5.15.0" installed="5.24.0" location="./tools/psalm" copy="false"/>
|
||||||
|
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
|
||||||
|
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.3" location="./tools/phpDocumentor" copy="false"/>
|
||||||
|
<phar name="php-cs-fixer" version="^3.34.1" installed="3.57.2" location="./tools/php-cs-fixer" copy="false"/>
|
||||||
|
</phive>
|
||||||
2
.shellcheckrc
Normal file
2
.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
shell=bash
|
||||||
|
external-sources=true
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
base_folder='/var/www/html/developers/clemens/core_data/php_libraries/trunk/www/';
|
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||||
|
# Assume script is in 4dev/bin
|
||||||
|
base_folder="${BASE_FOLDER}../../www/";
|
||||||
|
|
||||||
# locale gettext po to mo translator master
|
# locale gettext po to mo translator master
|
||||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
for file in "${base_folder}"../4dev/locale/*.po; do
|
||||||
file=$(basename $file .po);
|
[[ -e "$file" ]] || break
|
||||||
echo "Translate language ${file}";
|
file=$(basename "$file" .po);
|
||||||
locale=$(echo "${file}" | cut -d "-" -f 1);
|
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||||
domain=$(echo "${file}" | cut -d "-" -f 2);
|
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||||
|
echo "- Translate language file '${file}' for locale '${locale}' and domain '${domain}':";
|
||||||
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
|
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
|
||||||
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
|
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
|
||||||
fi;
|
fi;
|
||||||
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}../4dev/locale/${locale}-${domain}.po;
|
msgfmt -o "${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo" "${base_folder}../4dev/locale/${locale}-${domain}.po";
|
||||||
done;
|
done;
|
||||||
|
|
||||||
# __END__
|
# __END__
|
||||||
|
|||||||
176
4dev/bin/mo_to_js.sh
Executable file
176
4dev/bin/mo_to_js.sh
Executable file
@@ -0,0 +1,176 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# read source mo files and writes target js files in object form
|
||||||
|
|
||||||
|
# check for ARG 1 is "no-move"
|
||||||
|
# then do not move the files directly for manual check
|
||||||
|
FILE_MOVE=1;
|
||||||
|
if [ "${1}" = "no-move" ]; then
|
||||||
|
echo "+++ CREATE TEMPORARY FILES +++";
|
||||||
|
FILE_MOVE=0;
|
||||||
|
else
|
||||||
|
echo "*** Direct write ***";
|
||||||
|
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="${TEXTDOMAIN}/layout/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 "${base_folder}"../4dev/locale/*.po; do
|
||||||
|
[[ -e "$file" ]] || break
|
||||||
|
file=$(basename "$file" .po);
|
||||||
|
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||||
|
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||||
|
echo "- Translate language file '${file}' for locale '${locale}' and domain '${domain}':";
|
||||||
|
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');
|
||||||
|
original_file=${template_file//.TMP/};
|
||||||
|
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}";
|
||||||
|
echo "// Translation strings in the format";
|
||||||
|
echo "// \"Original\":\"Translated\""$'\n'
|
||||||
|
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 -r 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');
|
||||||
|
str_source=${str_source//\"/\\\"}
|
||||||
|
# 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}" || exit;
|
||||||
|
ln -sf "${original_file}" "${template_file}";
|
||||||
|
cd - >/dev/null || exit;
|
||||||
|
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,3 +1,5 @@
|
|||||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||||
# must be run in ${base}www/
|
# must be run in ${base}
|
||||||
phan --progress-bar -C --analyze-twice
|
cd $base;
|
||||||
|
${base}tools/phan --progress-bar -C --analyze-twice;
|
||||||
|
cd ~;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||||
# must be run in ${base}www/
|
# must be run in ${base}
|
||||||
phpstan
|
cd $base;
|
||||||
|
${base}tools/phpstan;
|
||||||
|
cd ~;
|
||||||
|
|||||||
@@ -1,35 +1,42 @@
|
|||||||
|
#!/bin/env bash
|
||||||
|
|
||||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||||
# -c phpunit.xml
|
# -c phpunit.xml
|
||||||
# --testdox
|
# --testdox
|
||||||
# call with "t" to give verbose testdox output
|
# call with "t" to give verbose testdox output
|
||||||
# SUPPORTED: https://www.php.net/supported-versions.php
|
# 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="";
|
opt_testdox="";
|
||||||
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
||||||
opt_testdox="--testdox";
|
opt_testdox="--testdox";
|
||||||
fi;
|
fi;
|
||||||
php_bin="";
|
php_bin="";
|
||||||
if [ ! -z "${1}" ]; then
|
if [ -n "${1}" ]; then
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||||
|
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||||
|
"8.3") php_bin="/usr/bin/php8.4 "; ;;
|
||||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||||
esac;
|
esac;
|
||||||
fi;
|
fi;
|
||||||
if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
|
if [ -n "${2}" ] && [ -z "${php_bin}" ]; then
|
||||||
case "${2}" in
|
case "${2}" in
|
||||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||||
|
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||||
|
"8.3") php_bin="/usr/bin/php8.3 "; ;;
|
||||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||||
esac;
|
esac;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
phpunit_call="${php_bin}${base}www/vendor/bin/phpunit ${opt_testdox} -c ${base}phpunit.xml ${base}4dev/tests/";
|
# Note 4dev/tests/bootstrap.php has to be set as bootstrap file in phpunit.xml
|
||||||
|
phpunit_call="${php_bin}${base}vendor/bin/phpunit ${opt_testdox} -c ${base}phpunit.xml ${base}4dev/tests/";
|
||||||
|
|
||||||
${phpunit_call};
|
${phpunit_call};
|
||||||
|
|
||||||
|
|||||||
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__
|
||||||
@@ -270,8 +270,10 @@ BEGIN
|
|||||||
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
||||||
THEN
|
THEN
|
||||||
NEW.login_user_id_set_date = NOW();
|
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
|
ELSIF NEW.login_user_id IS NULL OR NEW.login_user_id = '' THEN
|
||||||
NEW.login_user_id_set_date = NULL;
|
NEW.login_user_id_set_date = NULL;
|
||||||
|
NEW.login_user_id_last_revalidate = NULL;
|
||||||
END IF;
|
END IF;
|
||||||
RETURN NEW;
|
RETURN NEW;
|
||||||
END;
|
END;
|
||||||
@@ -595,12 +597,13 @@ CREATE TABLE edit_user (
|
|||||||
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
|
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
|
password_reset_uid VARCHAR, -- the uid to access the password reset page
|
||||||
-- _GET login id for direct login
|
-- _GET login id for direct login
|
||||||
login_user_id VARCHAR UNIQUE, -- the login uid, at least 32 chars
|
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_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_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_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 login id after set days, 0 for forever
|
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 login user id, but still allow normal login
|
login_user_id_locked SMALLINT DEFAULT 0, -- lock for loginUserId, but still allow normal login
|
||||||
-- additional ACL json block
|
-- additional ACL json block
|
||||||
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
||||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||||
@@ -629,11 +632,12 @@ COMMENT ON COLUMN edit_user.password_change_interval IS 'After how many days the
|
|||||||
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
||||||
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid, one time, invalid after reset successful or time out';
|
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid, one time, invalid after reset successful or time out';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id IS 'Min 32 character UID to be used to login without password. Via GET/POST parameter';
|
COMMENT ON COLUMN edit_user.login_user_id IS 'Min 32 character UID to be used to login without password. Via GET/POST parameter';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_set_date IS 'login id was set at what date';
|
COMMENT ON COLUMN edit_user.login_user_id_set_date IS 'loginUserId was set at what date';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_valid_from IS 'login id is valid from this date, >=';
|
COMMENT ON COLUMN edit_user.login_user_id_last_revalidate IS 'set when username/password login is done and loginUserId is set';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_valid_until IS 'login id is valid until this date, <=';
|
COMMENT ON COLUMN edit_user.login_user_id_valid_from IS 'loginUserId is valid from this date, >=';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_revalidate_after IS 'If set to a number greater 0 then user must login after given amount of days to revalidate, set to 0 for valid forver';
|
COMMENT ON COLUMN edit_user.login_user_id_valid_until IS 'loginUserId is valid until this date, <=';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_locked IS 'A separte lock flag for login id, user can still login normal';
|
COMMENT ON COLUMN edit_user.login_user_id_revalidate_after IS 'If set to a number greater 0 then user must login after given amount of days to revalidate the loginUserId, set to 0 for valid forver';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_locked IS 'A separte lock flag for loginUserId, user can still login normal';
|
||||||
COMMENT ON COLUMN edit_user.additional_acl IS 'Additional Access Control List stored in JSON format';
|
COMMENT ON COLUMN edit_user.additional_acl IS 'Additional Access Control List stored in JSON format';
|
||||||
-- END: table/edit_user.sql
|
-- END: table/edit_user.sql
|
||||||
-- START: table/edit_log.sql
|
-- START: table/edit_log.sql
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ BEGIN
|
|||||||
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
||||||
THEN
|
THEN
|
||||||
NEW.login_user_id_set_date = NOW();
|
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
|
ELSIF NEW.login_user_id IS NULL OR NEW.login_user_id = '' THEN
|
||||||
NEW.login_user_id_set_date = NULL;
|
NEW.login_user_id_set_date = NULL;
|
||||||
|
NEW.login_user_id_last_revalidate = NULL;
|
||||||
END IF;
|
END IF;
|
||||||
RETURN NEW;
|
RETURN NEW;
|
||||||
END;
|
END;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ CREATE OR REPLACE FUNCTION set_edit_generic()
|
|||||||
RETURNS TRIGGER AS
|
RETURNS TRIGGER AS
|
||||||
$$
|
$$
|
||||||
DECLARE
|
DECLARE
|
||||||
random_length INT = 12; -- that should be long enough
|
random_length INT = 25; -- that should be long enough
|
||||||
BEGIN
|
BEGIN
|
||||||
IF TG_OP = 'INSERT' THEN
|
IF TG_OP = 'INSERT' THEN
|
||||||
NEW.date_created := 'now';
|
NEW.date_created := 'now';
|
||||||
|
|||||||
@@ -55,12 +55,13 @@ CREATE TABLE edit_user (
|
|||||||
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
|
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
|
password_reset_uid VARCHAR, -- the uid to access the password reset page
|
||||||
-- _GET login id for direct login
|
-- _GET login id for direct login
|
||||||
login_user_id VARCHAR UNIQUE, -- the login uid, at least 32 chars
|
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_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_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_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 login id after set days, 0 for forever
|
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 login user id, but still allow normal login
|
login_user_id_locked SMALLINT DEFAULT 0, -- lock for loginUserId, but still allow normal login
|
||||||
-- additional ACL json block
|
-- additional ACL json block
|
||||||
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
||||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||||
@@ -89,9 +90,10 @@ COMMENT ON COLUMN edit_user.password_change_interval IS 'After how many days the
|
|||||||
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
||||||
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid, one time, invalid after reset successful or time out';
|
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid, one time, invalid after reset successful or time out';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id IS 'Min 32 character UID to be used to login without password. Via GET/POST parameter';
|
COMMENT ON COLUMN edit_user.login_user_id IS 'Min 32 character UID to be used to login without password. Via GET/POST parameter';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_set_date IS 'login id was set at what date';
|
COMMENT ON COLUMN edit_user.login_user_id_set_date IS 'loginUserId was set at what date';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_valid_from IS 'login id is valid from this date, >=';
|
COMMENT ON COLUMN edit_user.login_user_id_last_revalidate IS 'set when username/password login is done and loginUserId is set';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_valid_until IS 'login id is valid until this date, <=';
|
COMMENT ON COLUMN edit_user.login_user_id_valid_from IS 'loginUserId is valid from this date, >=';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_revalidate_after IS 'If set to a number greater 0 then user must login after given amount of days to revalidate, set to 0 for valid forver';
|
COMMENT ON COLUMN edit_user.login_user_id_valid_until IS 'loginUserId is valid until this date, <=';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_locked IS 'A separte lock flag for login id, user can still login normal';
|
COMMENT ON COLUMN edit_user.login_user_id_revalidate_after IS 'If set to a number greater 0 then user must login after given amount of days to revalidate the loginUserId, set to 0 for valid forver';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_locked IS 'A separte lock flag for loginUserId, user can still login normal';
|
||||||
COMMENT ON COLUMN edit_user.additional_acl IS 'Additional Access Control List stored in JSON format';
|
COMMENT ON COLUMN edit_user.additional_acl IS 'Additional Access Control List stored in JSON format';
|
||||||
|
|||||||
81
4dev/database/tests/20220622-01.edit_user-table-updates.sql
Normal file
81
4dev/database/tests/20220622-01.edit_user-table-updates.sql
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
--
|
||||||
|
SELECT
|
||||||
|
eu.cuid, eu.username,
|
||||||
|
eu.lock_until, eu.lock_after,
|
||||||
|
CASE WHEN (
|
||||||
|
(eu.lock_until IS NULL
|
||||||
|
OR (eu.lock_until IS NOT NULL AND NOW() >= eu.lock_until))
|
||||||
|
AND (eu.lock_after IS NULL
|
||||||
|
OR (eu.lock_after IS NOT NULL AND NOW() <= eu.lock_after))
|
||||||
|
) THEN 0::INT ELSE 1::INT END locked_period
|
||||||
|
FROM edit_user eu
|
||||||
|
WHERE eu.username = 'empty';
|
||||||
|
|
||||||
|
UPDATE edit_user SET
|
||||||
|
lock_until = NOW() + '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
UPDATE edit_user SET
|
||||||
|
lock_after = NOW() - '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE edit_user SET
|
||||||
|
lock_until = NOW() - '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
UPDATE edit_user SET
|
||||||
|
lock_after = NOW() + '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
|
||||||
|
UPDATE edit_user SET lock_until = NULL, lock_after = NULL WHERE username = 'empty';
|
||||||
|
|
||||||
|
--
|
||||||
|
SELECT
|
||||||
|
eu.cuid, eu.username,
|
||||||
|
eu.login_user_id, login_user_id_set_date, eu.login_user_id_last_revalidate,
|
||||||
|
(eu.login_user_id_last_revalidate + eu.login_user_id_revalidate_after)::DATE AS reval_date, NOW()::DATE,
|
||||||
|
eu.login_user_id_valid_from, eu.login_user_id_valid_until,
|
||||||
|
eu.login_user_id_revalidate_after,
|
||||||
|
CASE WHEN (
|
||||||
|
(eu.login_user_id_valid_from IS NULL
|
||||||
|
OR (eu.login_user_id_valid_from IS NOT NULL AND NOW() >= eu.login_user_id_valid_from))
|
||||||
|
AND (eu.login_user_id_valid_until IS NULL
|
||||||
|
OR (eu.login_user_id_valid_until IS NOT NULL AND NOW() <= eu.login_user_id_valid_until))
|
||||||
|
) THEN 1::INT ELSE 0::INT END AS login_user_id_valid_date,
|
||||||
|
CASE WHEN eu.login_user_id_revalidate_after IS NOT NULL
|
||||||
|
AND eu.login_user_id_revalidate_after > '0 days'::INTERVAL
|
||||||
|
AND (eu.login_user_id_last_revalidate + eu.login_user_id_revalidate_after)::DATE <= NOW()::DATE
|
||||||
|
THEN 1::INT ELSE 0::INT END AS login_user_id_revalidate
|
||||||
|
FROM edit_user eu
|
||||||
|
WHERE eu.username = 'empty';
|
||||||
|
|
||||||
|
-- init
|
||||||
|
UPDATE edit_user SET login_user_id = random_string(5) WHERE username = 'empty';
|
||||||
|
|
||||||
|
-- outside valid
|
||||||
|
UPDATE edit_user SET
|
||||||
|
login_user_id_valid_from = NOW() - '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
UPDATE edit_user SET
|
||||||
|
login_user_id_valid_until = NOW() + '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
-- inside valid
|
||||||
|
UPDATE edit_user SET
|
||||||
|
login_user_id_valid_from = NOW() + '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
UPDATE edit_user SET
|
||||||
|
login_user_id_valid_until = NOW() - '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
|
||||||
|
-- revalidate must
|
||||||
|
UPDATE edit_user SET
|
||||||
|
login_user_id_last_revalidate = NOW() - '1 day'::interval,
|
||||||
|
login_user_id_revalidate_after = '1 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
-- revalidate not yet
|
||||||
|
UPDATE edit_user SET
|
||||||
|
login_user_id_last_revalidate = NOW(),
|
||||||
|
login_user_id_revalidate_after = '6 day'::interval
|
||||||
|
WHERE username = 'empty';
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE edit_user SET login_user_id_set_date = NULL, login_user_id_last_revalidate = NULL, login_user_id_valid_from = NULL, login_user_id_valid_until = NULL, login_user_id_revalidate_after = NULL WHERE username = 'empty';
|
||||||
@@ -25,7 +25,7 @@ declare(strict_types=1);
|
|||||||
* 1 for file loadable, but no data inside
|
* 1 for file loadable, but no data inside
|
||||||
* 2 for file not readable
|
* 2 for file not readable
|
||||||
* 3 for file not found
|
* 3 for file not found
|
||||||
* @deprecated V6 Use \CoreLibs\Get\ReadEnvFile::readEnvFile()
|
* @deprecated V6 Use \CoreLibs\Get\DotEnv::readEnvFile()
|
||||||
*/
|
*/
|
||||||
function readEnvFile(string $path = __DIR__, string $env_file = '.env'): int
|
function readEnvFile(string $path = __DIR__, string $env_file = '.env'): int
|
||||||
{
|
{
|
||||||
31
4dev/documentation/DB_Query_Params.md
Normal file
31
4dev/documentation/DB_Query_Params.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# DB Query Params ? and : to $
|
||||||
|
|
||||||
|
dbReturn*
|
||||||
|
dbExec
|
||||||
|
|
||||||
|
keep
|
||||||
|
->query
|
||||||
|
->params
|
||||||
|
for reference
|
||||||
|
|
||||||
|
## : named params
|
||||||
|
|
||||||
|
in order for each named found replace with order number:
|
||||||
|
|
||||||
|
```txt
|
||||||
|
:name, :foo, :bar, :name =>
|
||||||
|
$1, $2, $3, $1
|
||||||
|
```
|
||||||
|
|
||||||
|
```php
|
||||||
|
$query = str_replace(
|
||||||
|
[':name', ':foo', ':bar'],
|
||||||
|
['$1', '$2', '$3'],
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## ? Params
|
||||||
|
|
||||||
|
Foreach ? set $1 to $n and store that in new params array
|
||||||
|
in QUERY for each ? replace with matching $n
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# create path
|
# create path
|
||||||
path=$(pwd)"/"$0;
|
path=$(pwd)"/"$0;
|
||||||
@@ -10,6 +10,11 @@ TARGET_HOST_WEB="<user>@<host>";
|
|||||||
TMP_DIR=$LOCAL_BASE_DIR"/4dev/tmp/";
|
TMP_DIR=$LOCAL_BASE_DIR"/4dev/tmp/";
|
||||||
tmpf_web=$TMP_DIR"sync.exclude.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
|
# if vendor be sure group folder is +x
|
||||||
chmod -R ug+rX ${LOCAL_DIR}/vender/
|
chmod -R ug+rX ${LOCAL_DIR}/vender/
|
||||||
|
|
||||||
@@ -18,6 +23,7 @@ rm -f $tmpf_web;
|
|||||||
echo ".*.swp" >> $tmpf_web;
|
echo ".*.swp" >> $tmpf_web;
|
||||||
echo "._*" >> $tmpf_web;
|
echo "._*" >> $tmpf_web;
|
||||||
echo ".DS_Store" >> $tmpf_web;
|
echo ".DS_Store" >> $tmpf_web;
|
||||||
|
echo ".user.ini" >> $tmpf_web;
|
||||||
echo ".svn" >> $tmpf_web;
|
echo ".svn" >> $tmpf_web;
|
||||||
echo ".svnignore" >> $tmpf_web;
|
echo ".svnignore" >> $tmpf_web;
|
||||||
echo ".git" >> $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/
|
||||||
65
4dev/tests/AAASetupData/requests/http_requests.php
Normal file
65
4dev/tests/AAASetupData/requests/http_requests.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AUTHOR: Clemens Schwaighofer
|
||||||
|
* CREATED: Ymd
|
||||||
|
* DESCRIPTION:
|
||||||
|
* DescriptionHere
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* build return json
|
||||||
|
*
|
||||||
|
* @param array<string,mixed> $http_headers
|
||||||
|
* @param ?string $body
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function buildContent(array $http_headers, ?string $body): string
|
||||||
|
{
|
||||||
|
if (is_string($body) && !empty($body)) {
|
||||||
|
$_body = json_decode($body, true);
|
||||||
|
if (!is_array($_body)) {
|
||||||
|
$body = [$body];
|
||||||
|
} else {
|
||||||
|
$body = $_body;
|
||||||
|
}
|
||||||
|
} elseif (is_string($body)) {
|
||||||
|
$body = [];
|
||||||
|
}
|
||||||
|
return json_encode([
|
||||||
|
'HEADERS' => $http_headers,
|
||||||
|
"REQUEST_TYPE" => $_SERVER['REQUEST_METHOD'],
|
||||||
|
"PARAMS" => $_GET,
|
||||||
|
"BODY" => $body,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$http_headers = array_filter($_SERVER, function ($value, $key) {
|
||||||
|
if (str_starts_with($key, 'HTTP_')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}, ARRAY_FILTER_USE_BOTH);
|
||||||
|
|
||||||
|
header("Content-Type: application/json; charset=UTF-8");
|
||||||
|
|
||||||
|
// if the header has Authorization and RunAuthTest then exit with 401
|
||||||
|
if (!empty($http_headers['HTTP_AUTHORIZATION']) && !empty($http_headers['HTTP_RUNAUTHTEST'])) {
|
||||||
|
header("HTTP/1.1 401 Unauthorized");
|
||||||
|
print buildContent($http_headers, '{"code": 401, "content": {"Error": "Not Authorized"}}');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if server request type is get set file_get to null -> no body
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
||||||
|
$file_get = null;
|
||||||
|
} elseif (($file_get = file_get_contents('php://input')) === false) {
|
||||||
|
header("HTTP/1.1 404 Not Found");
|
||||||
|
print buildContent($http_headers, '{"code": 404, "content": {"Error": "file_get_contents failed"}}');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
print buildContent($http_headers, $file_get);
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -7,6 +7,14 @@ namespace tests;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Not yet covered tests:
|
||||||
|
- loginGetLocale
|
||||||
|
- loginGetHeaderColor
|
||||||
|
- loginGetPages
|
||||||
|
- loginGetEuid
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for ACL\Login
|
* Test class for ACL\Login
|
||||||
* @coversDefaultClass \CoreLibs\ACL\Login
|
* @coversDefaultClass \CoreLibs\ACL\Login
|
||||||
@@ -60,13 +68,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
|
|
||||||
// logger is always needed
|
// logger is always needed
|
||||||
// define basic connection set valid and one invalid
|
// 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' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||||
'file_id' => 'CoreLibs-ACL-Login-Test',
|
'log_file_id' => 'CoreLibs-ACL-Login-Test',
|
||||||
'debug_all' => true,
|
|
||||||
'echo_all' => false,
|
|
||||||
'print_all' => true,
|
|
||||||
]);
|
]);
|
||||||
// test database we need to connect do, if not possible this test is skipped
|
// test database we need to connect do, if not possible this test is skipped
|
||||||
self::$db = new \CoreLibs\DB\IO(
|
self::$db = new \CoreLibs\DB\IO(
|
||||||
@@ -120,8 +125,6 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
// define('LOGIN_DB_SCHEMA', '');
|
// define('LOGIN_DB_SCHEMA', '');
|
||||||
|
|
||||||
// SHOULD SET
|
// SHOULD SET
|
||||||
// PASSWORD_MIN_LENGTH (d9)
|
|
||||||
// PASSWORD_MAX_LENGTH (d255)
|
|
||||||
// DEFAULT_ACL_LEVEL (d80)
|
// DEFAULT_ACL_LEVEL (d80)
|
||||||
|
|
||||||
// OPT:
|
// OPT:
|
||||||
@@ -157,17 +160,20 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function loginProvider(): array
|
public function loginProvider(): array
|
||||||
{
|
{
|
||||||
// 0: mock settings/override flag settings
|
// 0[mock] : mock settings/override flag settings
|
||||||
// 2: get array IN
|
// 1[get] : get array IN
|
||||||
// 1: post array IN
|
// 2[post] : post array IN
|
||||||
// login_login, login_username, login_password, login_logout
|
// login_login, login_username, login_password, login_logout
|
||||||
// change_password, pw_username, pw_old_password, pw_new_password,
|
// change_password, pw_username, pw_old_password, pw_new_password,
|
||||||
// pw_new_password_confirm
|
// pw_new_password_confirm
|
||||||
// 2: override session set
|
// 3[session]: override session set
|
||||||
// 3: expected error code, 0 for all ok, 3000 for login page view
|
// 4[error] : expected error code, 0 for all ok, 100 for login page view
|
||||||
// note that 1000 (no db), 2000 (no session) must be tested too
|
// note that 1000 (no db), 2000 (no session), 3000 (options set error)
|
||||||
// 4: expected return array, eg login_error code, or other info data to match
|
// must be tested too
|
||||||
return [
|
// <1000 info, >=1000 critical error
|
||||||
|
// 5[return] : expected return array, eg login_error code,
|
||||||
|
// or other info data to match
|
||||||
|
$tests = [
|
||||||
'load, no login' => [
|
'load, no login' => [
|
||||||
// error code, only for exceptions
|
// error code, only for exceptions
|
||||||
[
|
[
|
||||||
@@ -176,7 +182,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 0,
|
'login_error' => 0,
|
||||||
'error_string' => 'Success: <b>No error</b>',
|
'error_string' => 'Success: <b>No error</b>',
|
||||||
@@ -194,7 +200,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 0,
|
'login_error' => 0,
|
||||||
'error_string' => 'Success: <b>No error</b>',
|
'error_string' => 'Success: <b>No error</b>',
|
||||||
@@ -217,7 +223,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 0,
|
'login_error' => 0,
|
||||||
'error_string' => 'Success: <b>No error</b>',
|
'error_string' => 'Success: <b>No error</b>',
|
||||||
@@ -260,6 +266,8 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'GROUP_ACL_LEVEL' => -1,
|
'GROUP_ACL_LEVEL' => -1,
|
||||||
'PAGES_ACL_LEVEL' => [],
|
'PAGES_ACL_LEVEL' => [],
|
||||||
'USER_ACL_LEVEL' => -1,
|
'USER_ACL_LEVEL' => -1,
|
||||||
|
'USER_ADDITIONAL_ACL' => [],
|
||||||
|
'GROUP_ADDITIONAL_ACL' => [],
|
||||||
'UNIT_UID' => [
|
'UNIT_UID' => [
|
||||||
'AdminAccess' => 1,
|
'AdminAccess' => 1,
|
||||||
],
|
],
|
||||||
@@ -273,6 +281,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'data' => [
|
'data' => [
|
||||||
'test' => 'value',
|
'test' => 'value',
|
||||||
],
|
],
|
||||||
|
'additional_acl' => []
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
// 'UNIT_DEFAULT' => '',
|
// 'UNIT_DEFAULT' => '',
|
||||||
@@ -290,7 +299,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
// login: all missing
|
// login: all missing
|
||||||
'login: all missing' => [
|
'login: failed: all missing' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
],
|
],
|
||||||
@@ -301,7 +310,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => '',
|
'login_password' => '',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 102,
|
'login_error' => 102,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -311,7 +320,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login: missing username
|
// login: missing username
|
||||||
'login: missing username' => [
|
'login: failed: missing username' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
],
|
],
|
||||||
@@ -322,7 +331,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'abc',
|
'login_password' => 'abc',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 102,
|
'login_error' => 102,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -332,7 +341,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login: missing password
|
// login: missing password
|
||||||
'login: missing password' => [
|
'login: failed: missing password' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
],
|
],
|
||||||
@@ -343,7 +352,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => '',
|
'login_password' => '',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 102,
|
'login_error' => 102,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -353,7 +362,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login: user not found
|
// login: user not found
|
||||||
'login: user not found' => [
|
'login: failed: user not found' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
],
|
],
|
||||||
@@ -364,7 +373,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'abc',
|
'login_password' => 'abc',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 1010,
|
'login_error' => 1010,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -377,7 +386,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
// 9999: not valid password encoding
|
// 9999: not valid password encoding
|
||||||
// 1013: normal password failed
|
// 1013: normal password failed
|
||||||
// 1012: plain password check failed
|
// 1012: plain password check failed
|
||||||
'login: invalid password' => [
|
'login: failed: invalid password' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
],
|
],
|
||||||
@@ -388,7 +397,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'abc',
|
'login_password' => 'abc',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
// default password is plain text
|
// default password is plain text
|
||||||
'login_error' => 1012,
|
'login_error' => 1012,
|
||||||
@@ -399,7 +408,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login: ok (but deleted)
|
// login: ok (but deleted)
|
||||||
'login: ok, but deleted' => [
|
'login: ok -> failed: but deleted' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -414,7 +423,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'admin',
|
'login_password' => 'admin',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 106,
|
'login_error' => 106,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -424,7 +433,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login: ok (but not enabled)
|
// login: ok (but not enabled)
|
||||||
'login: ok, but not enabled' => [
|
'login: ok -> failed: but not enabled' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -439,7 +448,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'admin',
|
'login_password' => 'admin',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 104,
|
'login_error' => 104,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -449,7 +458,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login: ok (but locked)
|
// login: ok (but locked)
|
||||||
'login: ok, but locked' => [
|
'login: ok -> failed: but locked' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -464,7 +473,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'admin',
|
'login_password' => 'admin',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 105,
|
'login_error' => 105,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -474,7 +483,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login: make user get locked strict
|
// login: make user get locked strict
|
||||||
'login: ok, get locked, strict' => [
|
'login: ok -> failed: get locked, strict' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -498,7 +507,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login ok, but in locked period (until)
|
// login ok, but in locked period (until)
|
||||||
'login: ok, but locked period (until:on)' => [
|
'login: ok -> failed: but locked period (until:on)' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -513,7 +522,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'admin',
|
'login_password' => 'admin',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 107,
|
'login_error' => 107,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -552,7 +561,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login ok, but in locked period (after)
|
// login ok, but in locked period (after)
|
||||||
'login: ok, but locked period (after:on)' => [
|
'login: ok -> failed: but locked period (after:on)' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -567,7 +576,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'admin',
|
'login_password' => 'admin',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 107,
|
'login_error' => 107,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -577,7 +586,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login ok, but in locked period (until, after)
|
// login ok, but in locked period (until, after)
|
||||||
'login: ok, but locked period (until:on, after:on)' => [
|
'login: ok -> failed:, but locked period (until:on, after:on)' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -593,7 +602,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'admin',
|
'login_password' => 'admin',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 107,
|
'login_error' => 107,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -603,7 +612,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// login ok, but login user id locked
|
// login ok, but login user id locked
|
||||||
'login: ok, but login user id locked' => [
|
'login: ok -> failed:, but loginUserId locked' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -618,7 +627,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'login_password' => 'admin',
|
'login_password' => 'admin',
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 108,
|
'login_error' => 108,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -754,7 +763,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 1010,
|
'login_error' => 1010,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -830,7 +839,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// loginUserId check with revalidate on/off
|
// loginUserId check with revalidate on/off
|
||||||
'login: ok, but revalidate trigger, _GET loginUserId' => [
|
'login: ok -> failed:, but revalidate trigger, _GET loginUserId' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -846,7 +855,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 1101,
|
'login_error' => 1101,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -886,7 +895,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// loginUserId check with active time from only
|
// loginUserId check with active time from only
|
||||||
'login: ok, _GET loginUserId, but outside valid (from:on) ' => [
|
'login: ok -> failed:, _GET loginUserId, but outside valid (from:on) ' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -902,7 +911,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 1102,
|
'login_error' => 1102,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -942,7 +951,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// loginUserId check with active time until only
|
// loginUserId check with active time until only
|
||||||
'login: ok, _GET loginUserId, but outside valid (until:on) ' => [
|
'login: ok -> failed:, _GET loginUserId, but outside valid (until:on) ' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -958,7 +967,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 1102,
|
'login_error' => 1102,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -968,7 +977,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// loginUserId check with active time from/until
|
// loginUserId check with active time from/until
|
||||||
'login: ok, _GET loginUserId, but outside valid (from:on,until:on) ' => [
|
'login: ok -> failed:, _GET loginUserId, but outside valid (from:on,until:on) ' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
'edit_access_id' => 1,
|
'edit_access_id' => 1,
|
||||||
@@ -985,7 +994,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
3000,
|
100,
|
||||||
[
|
[
|
||||||
'login_error' => 1102,
|
'login_error' => 1102,
|
||||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||||
@@ -994,11 +1003,53 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
. 'Login Failed - Login User ID is outside valid date range'
|
. 'Login Failed - Login User ID is outside valid date range'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
// TODO: Test that if we have n day check with login, that after login we can use parameter login again
|
||||||
|
'login: ok -> failed -> ok:, _GET loginUserId, but must revalidate, normal login, _GET loginUserId' => [
|
||||||
|
[
|
||||||
|
'page_name' => 'edit_users.php',
|
||||||
|
'edit_access_id' => 1,
|
||||||
|
'edit_access_uid' => 'AdminAccess',
|
||||||
|
'edit_access_data' => 'test',
|
||||||
|
'base_access' => 'list',
|
||||||
|
'page_access' => 'list',
|
||||||
|
'test_login_user_id_revalidate_reset' => true,
|
||||||
|
'test_login_user_id' => true,
|
||||||
|
'test_username' => 'admin',
|
||||||
|
'loginUserId' => '1234567890ABCDEFG',
|
||||||
|
// this error is thrown on first login round
|
||||||
|
'login_error' => 1101,
|
||||||
|
// get post as set sub arrays
|
||||||
|
'get' => [
|
||||||
|
'loginUserId' => '1234567890ABCDEFG',
|
||||||
|
],
|
||||||
|
'post' => [
|
||||||
|
'login_login' => 'Login',
|
||||||
|
'login_username' => 'admin',
|
||||||
|
'login_password' => 'admin',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
// all empty get, post, session
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
'login_error' => 0,
|
||||||
|
'admin_flag' => true,
|
||||||
|
'check_access' => true,
|
||||||
|
'check_access_id' => 1,
|
||||||
|
'check_access_data' => 'value',
|
||||||
|
'base_access' => true,
|
||||||
|
'page_access' => true,
|
||||||
|
]
|
||||||
|
]
|
||||||
//
|
//
|
||||||
// other:
|
// other:
|
||||||
// login check edit access id of ID not null and not in array
|
// login check edit access id of ID not null and not in array
|
||||||
// login OK, but during action user gets disabled/deleted/etc
|
// login OK, but during action user gets disabled/deleted/etc
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return $tests;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1063,13 +1114,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
|
|
||||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
$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'])
|
->onlyMethods(['loginTerminate', 'loginReadPageName', 'loginPrintLogin'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$login_mock->expects($this->any())
|
$login_mock->expects($this->any())
|
||||||
->method('loginTerminate')
|
->method('loginTerminate')
|
||||||
->will(
|
->will(
|
||||||
$this->returnCallback(function ($code) {
|
$this->returnCallback(function ($message, $code) {
|
||||||
throw new \Exception('', $code);
|
throw new \Exception('', $code);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -1163,7 +1229,11 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
$login_mock->loginSetMaxLoginErrorCount($mock_settings['max_login_error_count']);
|
$login_mock->loginSetMaxLoginErrorCount($mock_settings['max_login_error_count']);
|
||||||
// temporary wrong password
|
// temporary wrong password
|
||||||
$_POST['login_password'] = 'wrong';
|
$_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 {
|
try {
|
||||||
$login_mock->loginMainCall();
|
$login_mock->loginMainCall();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -1196,7 +1266,6 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
if (!empty($mock_settings['test_login_user_id'])) {
|
if (!empty($mock_settings['test_login_user_id'])) {
|
||||||
self::$db->dbExec(
|
self::$db->dbExec(
|
||||||
"UPDATE edit_user SET "
|
"UPDATE edit_user SET "
|
||||||
. "login_user_id_set_date = NOW(), "
|
|
||||||
. "login_user_id = "
|
. "login_user_id = "
|
||||||
. self::$db->dbEscapeLiteral($mock_settings['loginUserId'])
|
. self::$db->dbEscapeLiteral($mock_settings['loginUserId'])
|
||||||
. " "
|
. " "
|
||||||
@@ -1207,10 +1276,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
if (!empty($mock_settings['test_login_user_id_revalidate_after'])) {
|
if (!empty($mock_settings['test_login_user_id_revalidate_after'])) {
|
||||||
$q_sub = '';
|
$q_sub = '';
|
||||||
if ($mock_settings['test_login_user_id_revalidate_after'] == 'on') {
|
if ($mock_settings['test_login_user_id_revalidate_after'] == 'on') {
|
||||||
$q_sub = "login_user_id_set_date = NOW() - '1 day'::interval, "
|
$q_sub = "login_user_id_last_revalidate = NOW() - '1 day'::interval, "
|
||||||
. "login_user_id_revalidate_after = '1 day'::interval ";
|
. "login_user_id_revalidate_after = '1 day'::interval ";
|
||||||
} else {
|
} else {
|
||||||
$q_sub = "login_user_id_set_date = NOW(), "
|
$q_sub = "login_user_id_last_revalidate = NOW(), "
|
||||||
. "login_user_id_revalidate_after = '6 day'::interval ";
|
. "login_user_id_revalidate_after = '6 day'::interval ";
|
||||||
}
|
}
|
||||||
self::$db->dbExec(
|
self::$db->dbExec(
|
||||||
@@ -1220,6 +1289,50 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
. self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
. self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (!empty($mock_settings['test_login_user_id_revalidate_reset'])) {
|
||||||
|
// init dates data for revalidate frame,
|
||||||
|
// set to last revalidate 3 days ago and set revalidate frame to
|
||||||
|
// three days
|
||||||
|
self::$db->dbExec(
|
||||||
|
"UPDATE edit_user SET "
|
||||||
|
. "login_user_id_last_revalidate = NOW() - '3 day'::interval, "
|
||||||
|
. "login_user_id_revalidate_after = '3 day'::interval "
|
||||||
|
. "WHERE LOWER(username) = "
|
||||||
|
. self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
||||||
|
);
|
||||||
|
$_GET = $mock_settings['get'];
|
||||||
|
// login with loginUserId -> fail
|
||||||
|
try {
|
||||||
|
$login_mock->loginMainCall();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$mock_settings['login_error'],
|
||||||
|
$login_mock->loginGetLastErrorCode(),
|
||||||
|
'loginUserId reset 1: Assert first loginUserId run failes'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$_GET = [];
|
||||||
|
// login with username and password -> reset -> ok
|
||||||
|
// set _POST data
|
||||||
|
$_POST = $mock_settings['post'];
|
||||||
|
try {
|
||||||
|
$login_mock->loginMainCall();
|
||||||
|
$this->assertEquals(
|
||||||
|
0,
|
||||||
|
$login_mock->loginGetLastErrorCode(),
|
||||||
|
'loginUserId reset 2: Assert username/password login is successful'
|
||||||
|
);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// if we end up here we have an issue
|
||||||
|
$this->assertTrue(
|
||||||
|
false,
|
||||||
|
'loginUserId reset 2: FAILED successful login'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$_POST = [];
|
||||||
|
// logut and run normal login with loginUserId
|
||||||
|
$_GET = $mock_settings['get'];
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
!empty($mock_settings['test_login_user_id_valid_from']) ||
|
!empty($mock_settings['test_login_user_id_valid_from']) ||
|
||||||
!empty($mock_settings['test_login_user_id_valid_until'])
|
!empty($mock_settings['test_login_user_id_valid_until'])
|
||||||
@@ -1368,10 +1481,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
// print "AJAX: " . $login_mock->loginGetAjaxFlag() . "\n";
|
// print "AJAX: " . $login_mock->loginGetAjaxFlag() . "\n";
|
||||||
// print "AJAX GLOBAL: " . ($GLOBALS['AJAX_PAGE'] ?? '{f}') . "\n";
|
// print "AJAX GLOBAL: " . ($GLOBALS['AJAX_PAGE'] ?? '{f}') . "\n";
|
||||||
// print "Login error expext: " . ($expected['login_error'] ?? '{0}') . "\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 (
|
if (
|
||||||
$e->getCode() == 3000 ||
|
$e->getCode() == 100 ||
|
||||||
!empty($_POST['login_exit']) && $_POST['login_exit'] == 3000
|
!empty($_POST['login_exit']) && $_POST['login_exit'] == 100
|
||||||
) {
|
) {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected['login_error'],
|
$expected['login_error'],
|
||||||
@@ -1391,7 +1504,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
);
|
);
|
||||||
// - loginGetLoginHTML
|
// - loginGetLoginHTML
|
||||||
$this->assertStringContainsString(
|
$this->assertStringContainsString(
|
||||||
'<html>',
|
'<html lang="',
|
||||||
$login_mock->loginGetLoginHTML(),
|
$login_mock->loginGetLoginHTML(),
|
||||||
'Assert login html string exits'
|
'Assert login html string exits'
|
||||||
);
|
);
|
||||||
@@ -1443,7 +1556,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
// html login basic check only, content is the same as when
|
// html login basic check only, content is the same as when
|
||||||
// read from loginGetLoginHTML()
|
// read from loginGetLoginHTML()
|
||||||
$this->assertStringContainsString(
|
$this->assertStringContainsString(
|
||||||
'<html>',
|
'<html lang="',
|
||||||
$_POST['login_html'],
|
$_POST['login_html'],
|
||||||
'Assert ajax _POST html string exits'
|
'Assert ajax _POST html string exits'
|
||||||
);
|
);
|
||||||
@@ -1461,6 +1574,14 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if _POST login set check this is matching
|
||||||
|
if (!empty($post['login_login'])) {
|
||||||
|
$this->assertTrue(
|
||||||
|
$login_mock->loginActionRun(),
|
||||||
|
'Assert that post login_login was pressed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// always check, even on error or not set
|
// always check, even on error or not set
|
||||||
if (!$login_mock->loginGetLoginUserIdUnclean()) {
|
if (!$login_mock->loginGetLoginUserIdUnclean()) {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@@ -1540,36 +1661,38 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
. self::$db->dbEscapeLiteral($post['login_username'])
|
. self::$db->dbEscapeLiteral($post['login_username'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// if (!empty($mock_settings['test_login_user_id'])) {
|
if (!empty($mock_settings['test_login_user_id'])) {
|
||||||
// self::$db->dbExec(
|
self::$db->dbExec(
|
||||||
// "UPDATE edit_user SET "
|
"UPDATE edit_user SET "
|
||||||
// . "login_user_id = NULL, "
|
. "login_user_id = NULL, "
|
||||||
// . "login_user_id_set_date = NULL "
|
// below to rows are automatcially reset
|
||||||
// . "WHERE LOWER(username) = "
|
. "login_user_id_set_date = NULL, "
|
||||||
// . self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
. "login_user_id_last_revalidate = NULL "
|
||||||
// );
|
. "WHERE LOWER(username) = "
|
||||||
// }
|
. self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
||||||
// if (!empty($mock_settings['test_login_user_id_revalidate_after'])) {
|
);
|
||||||
// self::$db->dbExec(
|
}
|
||||||
// "UPDATE edit_user SET "
|
if (!empty($mock_settings['test_login_user_id_revalidate_after'])) {
|
||||||
// . "login_user_id_set_date = NULL, "
|
self::$db->dbExec(
|
||||||
// . "login_user_id_revalidate_after = NULL "
|
"UPDATE edit_user SET "
|
||||||
// . "WHERE LOWER(username) = "
|
. "login_user_id_last_revalidate = NULL, "
|
||||||
// . self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
. "login_user_id_revalidate_after = NULL "
|
||||||
// );
|
. "WHERE LOWER(username) = "
|
||||||
// }
|
. self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
||||||
// if (
|
);
|
||||||
// !empty($mock_settings['test_login_user_id_valid_from']) ||
|
}
|
||||||
// !empty($mock_settings['test_login_user_id_valid_until'])
|
if (
|
||||||
// ) {
|
!empty($mock_settings['test_login_user_id_valid_from']) ||
|
||||||
// self::$db->dbExec(
|
!empty($mock_settings['test_login_user_id_valid_until'])
|
||||||
// "UPDATE edit_user SET "
|
) {
|
||||||
// . "login_user_id_valid_from = NULL, "
|
self::$db->dbExec(
|
||||||
// . "login_user_id_valid_until = NULL "
|
"UPDATE edit_user SET "
|
||||||
// . "WHERE LOWER(username) = "
|
. "login_user_id_valid_from = NULL, "
|
||||||
// . self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
. "login_user_id_valid_until = NULL "
|
||||||
// );
|
. "WHERE LOWER(username) = "
|
||||||
// }
|
. self::$db->dbEscapeLiteral($mock_settings['test_username'])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// - loginGetAclList (null, invalid,)
|
// - loginGetAclList (null, invalid,)
|
||||||
@@ -1633,7 +1756,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
],
|
],
|
||||||
20
|
20
|
||||||
],
|
],
|
||||||
'invalud search' => [
|
'invalid search' => [
|
||||||
12,
|
12,
|
||||||
'foo',
|
'foo',
|
||||||
[],
|
[],
|
||||||
@@ -1678,13 +1801,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
);
|
);
|
||||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
$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'])
|
->onlyMethods(['loginTerminate'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$login_mock->expects($this->any())
|
$login_mock->expects($this->any())
|
||||||
->method('loginTerminate')
|
->method('loginTerminate')
|
||||||
->will(
|
->will(
|
||||||
$this->returnCallback(function ($code) {
|
$this->returnCallback(function ($message, $code) {
|
||||||
throw new \Exception('', $code);
|
throw new \Exception('', $code);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -1777,13 +1915,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
);
|
);
|
||||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
$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'])
|
->onlyMethods(['loginTerminate'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$login_mock->expects($this->any())
|
$login_mock->expects($this->any())
|
||||||
->method('loginTerminate')
|
->method('loginTerminate')
|
||||||
->will(
|
->will(
|
||||||
$this->returnCallback(function ($code) {
|
$this->returnCallback(function ($message, $code) {
|
||||||
throw new \Exception('', $code);
|
throw new \Exception('', $code);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -1850,13 +2003,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
);
|
);
|
||||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
$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'])
|
->onlyMethods(['loginTerminate'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$login_mock->expects($this->any())
|
$login_mock->expects($this->any())
|
||||||
->method('loginTerminate')
|
->method('loginTerminate')
|
||||||
->will(
|
->will(
|
||||||
$this->returnCallback(function ($code) {
|
$this->returnCallback(function ($message, $code) {
|
||||||
throw new \Exception('', $code);
|
throw new \Exception('', $code);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -1931,13 +2099,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
);
|
);
|
||||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
$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'])
|
->onlyMethods(['loginTerminate'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$login_mock->expects($this->any())
|
$login_mock->expects($this->any())
|
||||||
->method('loginTerminate')
|
->method('loginTerminate')
|
||||||
->will(
|
->will(
|
||||||
$this->returnCallback(function ($code) {
|
$this->returnCallback(function ($message, $code) {
|
||||||
throw new \Exception('', $code);
|
throw new \Exception('', $code);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -270,8 +270,10 @@ BEGIN
|
|||||||
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
||||||
THEN
|
THEN
|
||||||
NEW.login_user_id_set_date = NOW();
|
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
|
ELSIF NEW.login_user_id IS NULL OR NEW.login_user_id = '' THEN
|
||||||
NEW.login_user_id_set_date = NULL;
|
NEW.login_user_id_set_date = NULL;
|
||||||
|
NEW.login_user_id_last_revalidate = NULL;
|
||||||
END IF;
|
END IF;
|
||||||
RETURN NEW;
|
RETURN NEW;
|
||||||
END;
|
END;
|
||||||
@@ -595,12 +597,13 @@ CREATE TABLE edit_user (
|
|||||||
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
|
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
|
password_reset_uid VARCHAR, -- the uid to access the password reset page
|
||||||
-- _GET login id for direct login
|
-- _GET login id for direct login
|
||||||
login_user_id VARCHAR UNIQUE, -- the login uid, at least 32 chars
|
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_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_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_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 login id after set days, 0 for forever
|
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 login user id, but still allow normal login
|
login_user_id_locked SMALLINT DEFAULT 0, -- lock for loginUserId, but still allow normal login
|
||||||
-- additional ACL json block
|
-- additional ACL json block
|
||||||
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
||||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||||
@@ -629,11 +632,12 @@ COMMENT ON COLUMN edit_user.password_change_interval IS 'After how many days the
|
|||||||
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
||||||
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid, one time, invalid after reset successful or time out';
|
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid, one time, invalid after reset successful or time out';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id IS 'Min 32 character UID to be used to login without password. Via GET/POST parameter';
|
COMMENT ON COLUMN edit_user.login_user_id IS 'Min 32 character UID to be used to login without password. Via GET/POST parameter';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_set_date IS 'login id was set at what date';
|
COMMENT ON COLUMN edit_user.login_user_id_set_date IS 'loginUserId was set at what date';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_valid_from IS 'login id is valid from this date, >=';
|
COMMENT ON COLUMN edit_user.login_user_id_last_revalidate IS 'set when username/password login is done and loginUserId is set';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_valid_until IS 'login id is valid until this date, <=';
|
COMMENT ON COLUMN edit_user.login_user_id_valid_from IS 'loginUserId is valid from this date, >=';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_revalidate_after IS 'If set to a number greater 0 then user must login after given amount of days to revalidate, set to 0 for valid forver';
|
COMMENT ON COLUMN edit_user.login_user_id_valid_until IS 'loginUserId is valid until this date, <=';
|
||||||
COMMENT ON COLUMN edit_user.login_user_id_locked IS 'A separte lock flag for login id, user can still login normal';
|
COMMENT ON COLUMN edit_user.login_user_id_revalidate_after IS 'If set to a number greater 0 then user must login after given amount of days to revalidate the loginUserId, set to 0 for valid forver';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_locked IS 'A separte lock flag for loginUserId, user can still login normal';
|
||||||
COMMENT ON COLUMN edit_user.additional_acl IS 'Additional Access Control List stored in JSON format';
|
COMMENT ON COLUMN edit_user.additional_acl IS 'Additional Access Control List stored in JSON format';
|
||||||
-- END: table/edit_user.sql
|
-- END: table/edit_user.sql
|
||||||
-- START: table/edit_log.sql
|
-- START: table/edit_log.sql
|
||||||
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__
|
||||||
@@ -92,6 +92,7 @@ final class CoreLibsCheckEncodingTest extends TestCase
|
|||||||
$error_char,
|
$error_char,
|
||||||
$expected
|
$expected
|
||||||
): void {
|
): void {
|
||||||
|
$current_subsitute_character = mb_substitute_character();
|
||||||
if ($error_char !== null) {
|
if ($error_char !== null) {
|
||||||
\CoreLibs\Check\Encoding::setErrorChar($error_char);
|
\CoreLibs\Check\Encoding::setErrorChar($error_char);
|
||||||
if (!in_array($error_char, ['none', 'long', 'entity'])) {
|
if (!in_array($error_char, ['none', 'long', 'entity'])) {
|
||||||
@@ -111,6 +112,8 @@ final class CoreLibsCheckEncodingTest extends TestCase
|
|||||||
$expected,
|
$expected,
|
||||||
$return
|
$return
|
||||||
);
|
);
|
||||||
|
// reset after test
|
||||||
|
mb_substitute_character($current_subsitute_character);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,10 +28,10 @@ final class CoreLibsCheckFileTest extends TestCase
|
|||||||
public function filesList(): array
|
public function filesList(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['filename.txt', 'txt', 5],
|
['filename.txt', 'txt', 5, 'text/plain'],
|
||||||
['filename.csv', 'csv', 15],
|
['filename.csv', 'csv', 15, 'text/csv'],
|
||||||
['filename.tsv', 'tsv', 0],
|
['filename.tsv', 'tsv', 0, 'text/plain'],
|
||||||
['file_does_not_exits', '', -1],
|
['file_does_not_exits', '', -1, ''],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +63,15 @@ final class CoreLibsCheckFileTest extends TestCase
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function mimeTypeProvider(): array
|
||||||
|
{
|
||||||
|
$list = [];
|
||||||
|
foreach ($this->filesList() as $row) {
|
||||||
|
$list[$row[0] . ' must be mime type ' . $row[3]] = [$row[0], $row[3]];
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if file extension matches
|
* Tests if file extension matches
|
||||||
*
|
*
|
||||||
@@ -115,6 +124,51 @@ final class CoreLibsCheckFileTest extends TestCase
|
|||||||
unlink($this->base_folder . $input);
|
unlink($this->base_folder . $input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::getMimeType
|
||||||
|
* @dataProvider mimeTypeProvider
|
||||||
|
* @testdox getMimeType $input must be mime type $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetMimeType(string $input, string $expected): void
|
||||||
|
{
|
||||||
|
if (!empty($expected)) {
|
||||||
|
$file = $this->base_folder . $input;
|
||||||
|
$fp = fopen($file, 'w');
|
||||||
|
switch ($expected) {
|
||||||
|
case 'text/csv':
|
||||||
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
|
fwrite($fp, '"This is row","' . $expected . '",' . $i . PHP_EOL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'text/tsv':
|
||||||
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
|
fwrite($fp, "\"This is row\"\t\"" . $expected . "\"\t\"" . $i . PHP_EOL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'text/plain':
|
||||||
|
fwrite($fp, 'This is mime type: ' . $expected . PHP_EOL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
} else {
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Check\File::getMimeType($this->base_folder . $input)
|
||||||
|
);
|
||||||
|
// unlink file
|
||||||
|
if (is_file($this->base_folder . $input)) {
|
||||||
|
unlink($this->base_folder . $input);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
@@ -31,6 +31,7 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
4,
|
4,
|
||||||
'b',
|
'b',
|
||||||
'c' => 'test',
|
'c' => 'test',
|
||||||
|
'single' => 'single',
|
||||||
'same' => 'same',
|
'same' => 'same',
|
||||||
'deep' => [
|
'deep' => [
|
||||||
'sub' => [
|
'sub' => [
|
||||||
@@ -107,6 +108,13 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function arraySearchRecursiveAllProvider(): array
|
public function arraySearchRecursiveAllProvider(): array
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
0: $needle,
|
||||||
|
1: array $input,
|
||||||
|
2: ?string $key_search_for,
|
||||||
|
3: bool $flag,
|
||||||
|
4: array $expected
|
||||||
|
*/
|
||||||
return [
|
return [
|
||||||
'find value' => [
|
'find value' => [
|
||||||
0 => 'bar',
|
0 => 'bar',
|
||||||
@@ -172,6 +180,13 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function arraySearchSimpleProvider(): array
|
public function arraySearchSimpleProvider(): array
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
0: array $input,
|
||||||
|
1: $key,
|
||||||
|
2: $value,
|
||||||
|
3: bool $flag,
|
||||||
|
4: bool $expected
|
||||||
|
*/
|
||||||
return [
|
return [
|
||||||
'key/value exist' => [
|
'key/value exist' => [
|
||||||
0 => self::$array,
|
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
|
* provides array listing for the merge test
|
||||||
*
|
*
|
||||||
@@ -321,17 +518,20 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
return [
|
return [
|
||||||
// error <2 arguments
|
// error <2 arguments
|
||||||
'too view arguments' => [
|
'too view arguments' => [
|
||||||
|
'ArgumentCountError',
|
||||||
'arrayMergeRecursive needs two or more array arguments',
|
'arrayMergeRecursive needs two or more array arguments',
|
||||||
[1]
|
[1]
|
||||||
],
|
],
|
||||||
// error <2 arrays
|
// error <2 arrays
|
||||||
'only one array' => [
|
'only one array' => [
|
||||||
|
'ArgumentCountError',
|
||||||
'arrayMergeRecursive needs two or more array arguments',
|
'arrayMergeRecursive needs two or more array arguments',
|
||||||
[1],
|
[1],
|
||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
// error element is not array
|
// error element is not array
|
||||||
'non array between array' => [
|
'non array between array' => [
|
||||||
|
'TypeError',
|
||||||
'arrayMergeRecursive encountered a non array argument',
|
'arrayMergeRecursive encountered a non array argument',
|
||||||
[1],
|
[1],
|
||||||
'string',
|
'string',
|
||||||
@@ -665,7 +865,7 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @param string|int $key
|
* @param string|int $key
|
||||||
* @param string|int $value
|
* @param string|int|bool $value
|
||||||
* @param bool $expected
|
* @param bool $expected
|
||||||
* @return void
|
* @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
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -712,12 +950,25 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testArrayMergeRecursiveWarningA(): void
|
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();
|
$arrays = func_get_args();
|
||||||
// first is expected warning
|
// first is expected warning
|
||||||
|
$exception = array_shift($arrays);
|
||||||
$warning = 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);
|
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
|
||||||
|
|
||||||
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -847,16 +1098,109 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
|
* @param string $search
|
||||||
* @param array $expected
|
* @param array $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testArrayFlatForKey(array $input, $search, array $expected): void
|
public function testArrayFlatForKey(array $input, string $search, array $expected): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Combined\ArrayHandler::arrayFlatForKey($input, $search)
|
\CoreLibs\Combined\ArrayHandler::arrayFlatForKey($input, $search)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerArrayGetNextPrevKey(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'find, ok' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'b',
|
||||||
|
'a',
|
||||||
|
'c'
|
||||||
|
],
|
||||||
|
'find, first' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'a',
|
||||||
|
null,
|
||||||
|
'b'
|
||||||
|
],
|
||||||
|
'find, last' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'c',
|
||||||
|
'b',
|
||||||
|
null
|
||||||
|
],
|
||||||
|
'find, not found' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'z',
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
],
|
||||||
|
'int, index' => [
|
||||||
|
'input' => [
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
'c'
|
||||||
|
],
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
2
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::arrayGetPrevKey, ::arrayGetNextKey
|
||||||
|
* @dataProvider providerArrayGetNextPrevKey
|
||||||
|
* @testdox arrayGetNextPrevKey get next/prev key for $search wtih $expected_prev/$expected_next [$_dataName]
|
||||||
|
*
|
||||||
|
* @param array $input
|
||||||
|
* @param int|string $search
|
||||||
|
* @param int|string|null $expected_prev
|
||||||
|
* @param int|string|null $expected_next
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testArrayGetNextPrevKey(
|
||||||
|
array $input,
|
||||||
|
int|string $search,
|
||||||
|
int|string|null $expected_prev,
|
||||||
|
int|string|null $expected_next
|
||||||
|
): void {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_prev,
|
||||||
|
\CoreLibs\Combined\ArrayHandler::arrayGetPrevKey($input, $search),
|
||||||
|
'Find prev key in array'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_next,
|
||||||
|
\CoreLibs\Combined\ArrayHandler::arrayGetNextKey($input, $search),
|
||||||
|
'Find next key in array'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
1218
4dev/tests/Combined/CoreLibsCombinedDateTimeTest.php
Normal file
1218
4dev/tests/Combined/CoreLibsCombinedDateTimeTest.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,6 @@ use PHPUnit\Framework\TestCase;
|
|||||||
*/
|
*/
|
||||||
final class CoreLibsConvertByteTest extends TestCase
|
final class CoreLibsConvertByteTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -24,7 +23,31 @@ final class CoreLibsConvertByteTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function byteProvider(): array
|
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 [
|
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' => [
|
'negative number' => [
|
||||||
0 => -123123123,
|
0 => -123123123,
|
||||||
1 => '-117.42 MB',
|
1 => '-117.42 MB',
|
||||||
@@ -217,6 +240,43 @@ final class CoreLibsConvertByteTest extends TestCase
|
|||||||
\CoreLibs\Convert\Byte::stringByteFormat($input, \CoreLibs\Convert\Byte::BYTE_FORMAT_SI)
|
\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(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionCode(1);
|
||||||
|
\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(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionCode(1);
|
||||||
|
\CoreLibs\Convert\Byte::stringByteFormat(12, $flag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
1186
4dev/tests/Convert/CoreLibsConvertColorTest.php
Normal file
1186
4dev/tests/Convert/CoreLibsConvertColorTest.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
/**
|
/**
|
||||||
* Test class for Convert\Colors
|
* Test class for Convert\Colors
|
||||||
* @coversDefaultClass \CoreLibs\Convert\Colors
|
* @coversDefaultClass \CoreLibs\Convert\Colors
|
||||||
* @testdox \CoreLibs\Convert\Colors method tests
|
* @testdox \CoreLibs\Convert\Colors legacy method tests
|
||||||
*/
|
*/
|
||||||
final class CoreLibsConvertColorsTest extends TestCase
|
final class CoreLibsConvertColorsTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -21,7 +21,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rgb2hexColorProvider(): array
|
public function providerRgb2hexColor(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'color' => [
|
'color' => [
|
||||||
@@ -59,6 +59,27 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
3 => false,
|
3 => false,
|
||||||
4 => 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
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +88,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function hex2rgbColorProvider(): array
|
public function providerHex2rgbColor(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'color' => [
|
'color' => [
|
||||||
@@ -122,6 +143,8 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function rgb2hslAndhsbList(): 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 [
|
return [
|
||||||
'valid gray' => [
|
'valid gray' => [
|
||||||
'rgb' => [12, 12, 12],
|
'rgb' => [12, 12, 12],
|
||||||
@@ -137,11 +160,51 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
'hsl' => [211.6, 90.5, 41.2],
|
'hsl' => [211.6, 90.5, 41.2],
|
||||||
'valid' => true,
|
'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 values
|
||||||
'invalid color' => [
|
'invalid color r/h/h low' => [
|
||||||
'rgb' => [-12, 300, 12],
|
'rgb' => [-1, 12, 12],
|
||||||
'hsb' => [-12, 300, 12],
|
'hsb' => [-1, 50, 50],
|
||||||
'hsl' => [-12, 300, 12],
|
'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,
|
'valid' => false,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -152,7 +215,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rgb2hsbColorProvider(): array
|
public function providerRgb2hsbColor(): array
|
||||||
{
|
{
|
||||||
$list = [];
|
$list = [];
|
||||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||||
@@ -171,14 +234,14 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function hsb2rgbColorProvider(): array
|
public function providerHsb2rgbColor(): array
|
||||||
{
|
{
|
||||||
$list = [];
|
$list = [];
|
||||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||||
$list[$name . ', hsb to rgb'] = [
|
$list[$name . ', hsb to rgb'] = [
|
||||||
0 => $values['hsb'][0],
|
0 => $values['hsb_from'][0] ?? $values['hsb'][0],
|
||||||
1 => $values['hsb'][1],
|
1 => $values['hsb_from'][1] ?? $values['hsb'][1],
|
||||||
2 => $values['hsb'][2],
|
2 => $values['hsb_from'][2] ?? $values['hsb'][2],
|
||||||
3 => $values['valid'] ? $values['hsb_rgb'] : false
|
3 => $values['valid'] ? $values['hsb_rgb'] : false
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -190,7 +253,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rgb2hslColorProvider(): array
|
public function providerRgb2hslColor(): array
|
||||||
{
|
{
|
||||||
$list = [];
|
$list = [];
|
||||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||||
@@ -209,14 +272,14 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function hsl2rgbColorProvider(): array
|
public function providerHsl2rgbColor(): array
|
||||||
{
|
{
|
||||||
$list = [];
|
$list = [];
|
||||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||||
$list[$name . ', hsl to rgb'] = [
|
$list[$name . ', hsl to rgb'] = [
|
||||||
0 => $values['hsl'][0],
|
0 => $values['hsl_from'][0] ?? $values['hsl'][0],
|
||||||
1 => $values['hsl'][1],
|
1 => $values['hsl_from'][1] ?? $values['hsl'][1],
|
||||||
2 => $values['hsl'][2],
|
2 => $values['hsl_from'][2] ?? $values['hsl'][2],
|
||||||
3 => $values['valid'] ? $values['rgb'] : false
|
3 => $values['valid'] ? $values['rgb'] : false
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -228,17 +291,28 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* TODO: add cross convert check
|
* TODO: add cross convert check
|
||||||
*
|
*
|
||||||
* @covers ::rgb2hex
|
* @covers ::rgb2hex
|
||||||
* @dataProvider rgb2hexColorProvider
|
* @dataProvider providerRgb2hexColor
|
||||||
* @testdox rgb2hex $input_r,$input_g,$input_b will be $expected [$_dataName]
|
* @testdox rgb2hex $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param int $input_r
|
* @param int $input_r
|
||||||
* @param int $input_g
|
* @param int $input_g
|
||||||
* @param int $input_b
|
* @param int $input_b
|
||||||
|
* @param string|bool $expected_hash
|
||||||
* @param string|bool $expected
|
* @param string|bool $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testRgb2hex(int $input_r, int $input_g, int $input_b, $expected_hash, $expected)
|
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 #
|
// with #
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected_hash,
|
$expected_hash,
|
||||||
@@ -268,7 +342,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::hex2rgb
|
* @covers ::hex2rgb
|
||||||
* @dataProvider hex2rgbColorProvider
|
* @dataProvider providerHex2rgbColor
|
||||||
* @testdox hex2rgb $input will be $expected, $expected_str str[,], $expected_str_sep str[$separator] [$_dataName]
|
* @testdox hex2rgb $input will be $expected, $expected_str str[,], $expected_str_sep str[$separator] [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string $input
|
* @param string $input
|
||||||
@@ -280,11 +354,19 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testHex2rgb(
|
public function testHex2rgb(
|
||||||
string $input,
|
string $input,
|
||||||
$expected,
|
array|bool $expected,
|
||||||
$expected_str,
|
string|bool $expected_str,
|
||||||
string $separator,
|
string $separator,
|
||||||
$expected_str_sep
|
string|bool $expected_str_sep
|
||||||
): void {
|
): 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(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Convert\Colors::hex2rgb($input)
|
\CoreLibs\Convert\Colors::hex2rgb($input)
|
||||||
@@ -303,7 +385,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::rgb2hsb
|
* @covers ::rgb2hsb
|
||||||
* @dataProvider rgb2hsbColorProvider
|
* @dataProvider providerRgb2hsbColor
|
||||||
* @testdox rgb2hsb $input_r,$input_g,$input_b will be $expected [$_dataName]
|
* @testdox rgb2hsb $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param integer $input_r
|
* @param integer $input_r
|
||||||
@@ -312,8 +394,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* @param array|bool $expected
|
* @param array|bool $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testRgb2hsb(int $input_r, int $input_g, int $input_b, $expected): 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(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Convert\Colors::rgb2hsb($input_r, $input_g, $input_b)
|
\CoreLibs\Convert\Colors::rgb2hsb($input_r, $input_g, $input_b)
|
||||||
@@ -324,7 +409,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::hsb2rgb
|
* @covers ::hsb2rgb
|
||||||
* @dataProvider hsb2rgbColorProvider
|
* @dataProvider providerHsb2rgbColor
|
||||||
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param float $input_h
|
* @param float $input_h
|
||||||
@@ -333,8 +418,12 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* @param array|bool $expected
|
* @param array|bool $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, $expected): 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(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Convert\Colors::hsb2rgb($input_h, $input_s, $input_b)
|
\CoreLibs\Convert\Colors::hsb2rgb($input_h, $input_s, $input_b)
|
||||||
@@ -345,7 +434,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::rgb2hsl
|
* @covers ::rgb2hsl
|
||||||
* @dataProvider rgb2hslColorProvider
|
* @dataProvider providerRgb2hslColor
|
||||||
* @testdox rgb2hsl $input_r,$input_g,$input_b will be $expected [$_dataName]
|
* @testdox rgb2hsl $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param integer $input_r
|
* @param integer $input_r
|
||||||
@@ -354,8 +443,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* @param array|bool $expected
|
* @param array|bool $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testRgb2hsl(int $input_r, int $input_g, int $input_b, $expected): 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(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Convert\Colors::rgb2hsl($input_r, $input_g, $input_b)
|
\CoreLibs\Convert\Colors::rgb2hsl($input_r, $input_g, $input_b)
|
||||||
@@ -366,7 +458,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::hsl2rgb
|
* @covers ::hsl2rgb
|
||||||
* @dataProvider hsl2rgbColorProvider
|
* @dataProvider providerHsl2rgbColor
|
||||||
* @testdox hsl2rgb $input_h,$input_s,$input_l will be $expected [$_dataName]
|
* @testdox hsl2rgb $input_h,$input_s,$input_l will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param integer|float $input_h
|
* @param integer|float $input_h
|
||||||
@@ -375,13 +467,37 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* @param array|bool $expected
|
* @param array|bool $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testHsl2rgb($input_h, float $input_s, float $input_l, $expected): 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(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Convert\Colors::hsl2rgb($input_h, $input_s, $input_l)
|
\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__
|
// __END__
|
||||||
@@ -16,7 +16,7 @@ final class CoreLibsConvertJsonTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* test list for json convert tests
|
* test list for json convert tests
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array<mixed>
|
||||||
*/
|
*/
|
||||||
public function jsonProvider(): array
|
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
|
* json error list
|
||||||
*
|
*
|
||||||
* @return array JSON error list
|
* @return array<mixed> JSON error list
|
||||||
*/
|
*/
|
||||||
public function jsonErrorProvider(): array
|
public function jsonErrorProvider(): array
|
||||||
{
|
{
|
||||||
@@ -127,7 +153,7 @@ final class CoreLibsConvertJsonTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @param string|null $input
|
* @param string|null $input
|
||||||
* @param bool $flag
|
* @param bool $flag
|
||||||
* @param array $expected
|
* @param array<mixed> $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testJsonConvertToArray(?string $input, bool $flag, array $expected): 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]
|
* @testdox jsonGetLastError $input will be $expected_i/$expected_s [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string|null $input
|
* @param string|null $input
|
||||||
* @param string $expected
|
* @param int $expected_i
|
||||||
|
* @param string $expected_s
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testJsonGetLastError(?string $input, int $expected_i, string $expected_s): 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)
|
\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__
|
// __END__
|
||||||
500
4dev/tests/Convert/CoreLibsConvertMathTest.php
Normal file
500
4dev/tests/Convert/CoreLibsConvertMathTest.php
Normal file
@@ -0,0 +1,500 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented class
|
||||||
|
* @coversDefaultClass \CoreLibs\Convert\Math
|
||||||
|
* @testdox \CoreLibs\Convert\Math method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsConvertMathTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function providerFceil(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'5.5 must be 6' => [5.5, 6],
|
||||||
|
'5.1234567890 with 5 must be 6' => [5.1234567890, 6],
|
||||||
|
'6 must be 6' => [6, 6]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::fceil
|
||||||
|
* @dataProvider providerFceil
|
||||||
|
* @testdox fceil: Input $input must be $expected
|
||||||
|
*
|
||||||
|
* @param float $input
|
||||||
|
* @param int $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMathFceilValue(float $input, int $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Convert\Math::fceil($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function providerFloor(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'5123456 with -3 must be 5123000' => [5123456, -3, 5123000],
|
||||||
|
'5123456 with -10 must be 5000000' => [5123456, -10, 5000000]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::floorp
|
||||||
|
* @dataProvider providerFloor
|
||||||
|
* @testdox floor: Input $input with cutoff $cutoff must be $expected
|
||||||
|
*
|
||||||
|
* @param int $input
|
||||||
|
* @param int $cutoff
|
||||||
|
* @param int $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMathFloorValue(int $input, int $cutoff, int $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Convert\Math::floorp($input, $cutoff)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function providerInitNumeric(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'5 must be 5' => [5, 5, 'int'],
|
||||||
|
'5.123 must be 5.123' => [5.123, 5.123, 'float'],
|
||||||
|
"'5' must be 5" => ['5', 5, 'string'],
|
||||||
|
"'5.123' must be 5.123" => ['5.123', 5.123, 'string'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::initNumeric
|
||||||
|
* @dataProvider providerInitNumeric
|
||||||
|
* @testdox initNumeric: Input $info $input must match $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param int|float|string $input
|
||||||
|
* @param float $expected
|
||||||
|
* @param string $info
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMathInitNumericValue($input, float $expected, string $info): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Convert\Math::initNumeric($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerCbrt(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'cube root of 2' => [2, 1.25992, 5],
|
||||||
|
'cube root of 3' => [3, 1.44225, 5],
|
||||||
|
'cube root of -1' => [-1, 'NAN', 0],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::cbrt
|
||||||
|
* @dataProvider providerCbrt
|
||||||
|
* @testdox initNumeric: Input $input must match $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param float|int $number
|
||||||
|
* @param float $expected
|
||||||
|
* @param int $round_to
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCbrt(float|int $number, float|string $expected, int $round_to): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
round(\CoreLibs\Convert\Math::cbrt($number), $round_to)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerMultiplyMatrices(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'[3] x [3] => [3x1]' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
[14]
|
||||||
|
],
|
||||||
|
'[3] x [3x1]' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[[1], [2], [3]],
|
||||||
|
[14]
|
||||||
|
],
|
||||||
|
'[3] x [3x1]' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[[1], [2], [3]],
|
||||||
|
[14]
|
||||||
|
],
|
||||||
|
'[1x3L] x [3x1]' => [
|
||||||
|
[[1, 2, 3]],
|
||||||
|
[[1], [2], [3]],
|
||||||
|
[14]
|
||||||
|
],
|
||||||
|
'[1x3] x [3x1]' => [
|
||||||
|
[[1], [2], [3]],
|
||||||
|
[[1], [2], [3]],
|
||||||
|
[1, 2, 3]
|
||||||
|
],
|
||||||
|
'[2x3] x [3] => [3x1]' => [
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3]
|
||||||
|
],
|
||||||
|
[1, 2, 3],
|
||||||
|
[
|
||||||
|
14,
|
||||||
|
14
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[2x3] x [3x1]' => [
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3]
|
||||||
|
],
|
||||||
|
[[1], [2], [3]],
|
||||||
|
[
|
||||||
|
14,
|
||||||
|
14
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[2x3] x [2x3] => [3x3]' => [
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[3, 6, 9],
|
||||||
|
[3, 6, 9]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[2x3] x [3x3]' => [
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
[0, 0, 0],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[3, 6, 9],
|
||||||
|
[3, 6, 9]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[2x3] x [3x2]' => [
|
||||||
|
'a' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
'b' => [
|
||||||
|
[1, 1],
|
||||||
|
[2, 2],
|
||||||
|
[3, 3],
|
||||||
|
],
|
||||||
|
'prod' => [
|
||||||
|
[14, 14],
|
||||||
|
[14, 14],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[3x3] x [3] => [1x3]' => [
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[1, 2, 3],
|
||||||
|
[
|
||||||
|
14,
|
||||||
|
14,
|
||||||
|
14
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[3x3] x [2x3] => [3x3]' => [
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[3, 6, 9],
|
||||||
|
[3, 6, 9],
|
||||||
|
[3, 6, 9],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[3x3] x [3x3]' => [
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
// [0, 0, 0],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[3, 6, 9],
|
||||||
|
[3, 6, 9],
|
||||||
|
[3, 6, 9],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[3] x [3x3]' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[6, 12, 18],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'[2x3] x [3x3]' => [
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[6, 12, 18],
|
||||||
|
[6, 12, 18],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'inblanaced [2x2,3] x [3x2]' => [
|
||||||
|
'a' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5]
|
||||||
|
],
|
||||||
|
'b' => [
|
||||||
|
[6, 7],
|
||||||
|
[8, 9],
|
||||||
|
[10, 11]
|
||||||
|
],
|
||||||
|
'result' => [
|
||||||
|
[52, 58],
|
||||||
|
[64, 73],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'inblanaced [2x3] x [3x1,2]' => [
|
||||||
|
'a' => [
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5, 7]
|
||||||
|
],
|
||||||
|
'b' => [
|
||||||
|
[7, 8],
|
||||||
|
[9, 10],
|
||||||
|
[11]
|
||||||
|
],
|
||||||
|
'result' => [
|
||||||
|
[58, 28],
|
||||||
|
[150, 82],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::multiplyMatrices
|
||||||
|
* @dataProvider providerMultiplyMatrices
|
||||||
|
* @testdox initNumeric: Input $input_a x $input_b must match $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param array $input_a
|
||||||
|
* @param array $input_b
|
||||||
|
* @param array $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMultiplyMatrices(array $input_a, array $input_b, array $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Convert\Math::multiplyMatrices($input_a, $input_b)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerEqualWithEpsilon(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'equal' => [
|
||||||
|
'a' => 0.000000000000000222,
|
||||||
|
'b' => 0.000000000000000222,
|
||||||
|
'epsilon' => PHP_FLOAT_EPSILON,
|
||||||
|
'equal' => true,
|
||||||
|
],
|
||||||
|
'almost equal' => [
|
||||||
|
'a' => 0.000000000000000222,
|
||||||
|
'b' => 0.000000000000000232,
|
||||||
|
'epsilon' => PHP_FLOAT_EPSILON,
|
||||||
|
'equal' => true,
|
||||||
|
],
|
||||||
|
'not equal' => [
|
||||||
|
'a' => 0.000000000000000222,
|
||||||
|
'b' => 0.000000000000004222,
|
||||||
|
'epsilon' => PHP_FLOAT_EPSILON,
|
||||||
|
'equal' => false,
|
||||||
|
],
|
||||||
|
'equal, different epsilon' => [
|
||||||
|
'a' => 0.000000000000000222,
|
||||||
|
'b' => 0.000000000000004222,
|
||||||
|
'epsilon' => 0.0001,
|
||||||
|
'equal' => true,
|
||||||
|
],
|
||||||
|
'not equal, different epsilon' => [
|
||||||
|
'a' => 0.0001,
|
||||||
|
'b' => 0.0002,
|
||||||
|
'epsilon' => 0.0001,
|
||||||
|
'equal' => false,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::equalWithEpsilon
|
||||||
|
* @dataProvider providerEqualWithEpsilon
|
||||||
|
* @testdox equalWithEpsilon with $a and $b and Epsilon: $epsilon must be equal: $equal [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEqualWithEpsilon(float $a, float $b, float $epsilon, bool $equal): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$equal,
|
||||||
|
\CoreLibs\Convert\Math::equalWithEpsilon($a, $b, $epsilon)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerCompareWithEpsilon(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'smaller, true' => [
|
||||||
|
'value' => 0.0001,
|
||||||
|
'compare' => '<',
|
||||||
|
'limit' => 0.0002,
|
||||||
|
'epsilon' => 0.00001,
|
||||||
|
'match' => true,
|
||||||
|
],
|
||||||
|
'smaller, false' => [
|
||||||
|
'value' => 0.0001,
|
||||||
|
'compare' => '<',
|
||||||
|
'limit' => 0.0001,
|
||||||
|
'epsilon' => 0.00001,
|
||||||
|
'match' => false,
|
||||||
|
],
|
||||||
|
'bigger, true' => [
|
||||||
|
'value' => 0.0002,
|
||||||
|
'compare' => '>',
|
||||||
|
'limit' => 0.0001,
|
||||||
|
'epsilon' => 0.00001,
|
||||||
|
'match' => true,
|
||||||
|
],
|
||||||
|
'bigger, false' => [
|
||||||
|
'value' => 0.0001,
|
||||||
|
'compare' => '>',
|
||||||
|
'limit' => 0.0001,
|
||||||
|
'epsilon' => 0.00001,
|
||||||
|
'match' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::compareWithEpsilon
|
||||||
|
* @dataProvider providerCompareWithEpsilon
|
||||||
|
* @testdox compareWithEpsilon $value $compare $limit with $epsilon must match: $match [$_dataName]
|
||||||
|
*
|
||||||
|
* @param float $value
|
||||||
|
* @param string $compare
|
||||||
|
* @param float $limit
|
||||||
|
* @param float $epslion
|
||||||
|
* @param bool $match
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCompareWithEpsilon(
|
||||||
|
float $value,
|
||||||
|
string $compare,
|
||||||
|
float $limit,
|
||||||
|
float $epsilon,
|
||||||
|
bool $match
|
||||||
|
): void {
|
||||||
|
$this->assertEquals(
|
||||||
|
$match,
|
||||||
|
\CoreLibs\Convert\Math::compareWithEpsilon($value, $compare, $limit, $epsilon)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -33,15 +33,14 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
|||||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||||
. 'and has no idea what is going on here',
|
. 'and has no idea what is going on here',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
"The quick brown fox jumps over the lazy sheep that sleeps in the ravine and\r\n"
|
||||||
. 'and has no idea what is going on here'
|
. ' has no idea what is going on here'
|
||||||
],
|
],
|
||||||
'standard with special chars UTF-8' => [
|
'standard with special chars UTF-8' => [
|
||||||
'This is ümläßtと漢字もカタカナ!!^$%&',
|
'This is ümläßtと漢字もカタカナ!!^$%&',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
'This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?='
|
"This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?=\r\n"
|
||||||
. "\r\n"
|
. ' =?UTF-8?B?JSY=?='
|
||||||
. ' =?UTF-8?B?JQ==?=&'
|
|
||||||
],
|
],
|
||||||
'35 chars and space at the end UTF-8' => [
|
'35 chars and space at the end UTF-8' => [
|
||||||
'12345678901234567890123456789012345 '
|
'12345678901234567890123456789012345 '
|
||||||
@@ -62,9 +61,8 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
|||||||
. 'is there a space?',
|
. 'is there a space?',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
||||||
. " =?UTF-8?B?44K/44Kr44OK?=\r\n"
|
. " =?UTF-8?B?44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq?=\r\n"
|
||||||
. " =?UTF-8?B?44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr?=\r\n"
|
. " =?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/IGlzIHRoZXJlIGEgc3BhY2U/?="
|
||||||
. " =?UTF-8?B?44OK44Kr44K/?= is there a =?UTF-8?B?c3BhY2U/?="
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -85,16 +83,28 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
|||||||
// print "MIME: -" . $encoded . "-\n";
|
// print "MIME: -" . $encoded . "-\n";
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
$encoded
|
$encoded,
|
||||||
|
"__mbMimeEncode"
|
||||||
);
|
);
|
||||||
$decoded = mb_decode_mimeheader($encoded);
|
$decoded = mb_decode_mimeheader($encoded);
|
||||||
// print "INPUT : " . $input . "\n";
|
// print "ENCODED: " . $encoded . "\n";
|
||||||
// print "DECODED: " . $decoded . "\n";
|
// print "INPUT : " . $input . " | " . mb_strlen($input) . "\n";
|
||||||
|
// print "DECODED: " . $decoded . " | " . mb_strlen($decoded) . "\n";
|
||||||
|
// $test_enc = mb_encode_mimeheader($input, $encoding);
|
||||||
|
// $test_dec = mb_decode_mimeheader($test_enc);
|
||||||
|
// print "TEST ENC: " . $test_enc . "\n";
|
||||||
// back compare decoded
|
// back compare decoded
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$input,
|
$input,
|
||||||
$decoded
|
$decoded,
|
||||||
|
"mb_decode_mimeheader"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// $this->assertEquals(
|
||||||
|
// $input,
|
||||||
|
// $test_dec,
|
||||||
|
// 'mb_encode_to_decode'
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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__
|
||||||
383
4dev/tests/Convert/CoreLibsConvertStringsTest.php
Normal file
383
4dev/tests/Convert/CoreLibsConvertStringsTest.php
Normal file
@@ -0,0 +1,383 @@
|
|||||||
|
<?php // phpcs:disable Generic.Files.LineLength
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Convert\Strings
|
||||||
|
* @coversDefaultClass \CoreLibs\Convert\Strings
|
||||||
|
* @testdox \CoreLibs\Convert\Strings method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsConvertStringsTest extends TestCase
|
||||||
|
{
|
||||||
|
private const DATA_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function splitFormatStringProvider(): array
|
||||||
|
{
|
||||||
|
// 0: input
|
||||||
|
// 1: format
|
||||||
|
// 2: split characters as string, null for default
|
||||||
|
// 3: expected
|
||||||
|
return [
|
||||||
|
'all empty string' => [
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
''
|
||||||
|
],
|
||||||
|
'empty input string' => [
|
||||||
|
'',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
''
|
||||||
|
],
|
||||||
|
'empty format string string' => [
|
||||||
|
'1234',
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
'1234'
|
||||||
|
],
|
||||||
|
'string format match' => [
|
||||||
|
'1234',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'12-34'
|
||||||
|
],
|
||||||
|
'string format trailing match' => [
|
||||||
|
'1234',
|
||||||
|
'2-2-',
|
||||||
|
null,
|
||||||
|
'12-34'
|
||||||
|
],
|
||||||
|
'string format leading match' => [
|
||||||
|
'1234',
|
||||||
|
'-2-2',
|
||||||
|
null,
|
||||||
|
'12-34'
|
||||||
|
],
|
||||||
|
'string format double inside match' => [
|
||||||
|
'1234',
|
||||||
|
'2--2',
|
||||||
|
null,
|
||||||
|
'12--34',
|
||||||
|
],
|
||||||
|
'string format short first' => [
|
||||||
|
'1',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'1'
|
||||||
|
],
|
||||||
|
'string format match first' => [
|
||||||
|
'12',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'12'
|
||||||
|
],
|
||||||
|
'string format short second' => [
|
||||||
|
'123',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'12-3'
|
||||||
|
],
|
||||||
|
'string format too long' => [
|
||||||
|
'1234567',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'12-34-567'
|
||||||
|
],
|
||||||
|
'string format invalid format string' => [
|
||||||
|
'1234',
|
||||||
|
'2_2',
|
||||||
|
null,
|
||||||
|
'1234'
|
||||||
|
],
|
||||||
|
'different split character' => [
|
||||||
|
'1234',
|
||||||
|
'2_2',
|
||||||
|
'_',
|
||||||
|
'12_34'
|
||||||
|
],
|
||||||
|
'mixed split characters' => [
|
||||||
|
'123456',
|
||||||
|
'2-2_2',
|
||||||
|
'-_',
|
||||||
|
'12-34_56'
|
||||||
|
],
|
||||||
|
'length mixed' => [
|
||||||
|
'ABCD12345568ABC13',
|
||||||
|
'2-4_5-2#4',
|
||||||
|
'-_#',
|
||||||
|
'AB-CD12_34556-8A#BC13'
|
||||||
|
],
|
||||||
|
'split with split chars in string' => [
|
||||||
|
'12-34',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'12--3-4'
|
||||||
|
],
|
||||||
|
'mutltibyte string' => [
|
||||||
|
'あいうえ',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'あいうえ'
|
||||||
|
],
|
||||||
|
'mutltibyte split string' => [
|
||||||
|
'1234',
|
||||||
|
'2-2',
|
||||||
|
null,
|
||||||
|
'1234'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* split format string
|
||||||
|
*
|
||||||
|
* @covers ::splitFormatString
|
||||||
|
* @dataProvider splitFormatStringProvider
|
||||||
|
* @testdox splitFormatString $input with format $format and splitters $split_characters will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $format
|
||||||
|
* @param string|null $split_characters
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSplitFormatString(
|
||||||
|
string $input,
|
||||||
|
string $format,
|
||||||
|
?string $split_characters,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
|
if ($split_characters === null) {
|
||||||
|
$output = \CoreLibs\Convert\Strings::splitFormatString(
|
||||||
|
$input,
|
||||||
|
$format
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$output = \CoreLibs\Convert\Strings::splitFormatString(
|
||||||
|
$input,
|
||||||
|
$format,
|
||||||
|
$split_characters
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$output
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function countSplitPartsProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'0 elements' => [
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
'1 element' => [
|
||||||
|
'1',
|
||||||
|
null,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
'2 elements, trailing' => [
|
||||||
|
'1-2-',
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
'2 elements, leading' => [
|
||||||
|
'-1-2',
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
'2 elements, midde double' => [
|
||||||
|
'1--2',
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
'4 elements' => [
|
||||||
|
'1-2-3-4',
|
||||||
|
null,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
'3 elemenst, other splitter' => [
|
||||||
|
'2-3_3',
|
||||||
|
'-_',
|
||||||
|
3
|
||||||
|
],
|
||||||
|
'illegal splitter' => [
|
||||||
|
'あsdf',
|
||||||
|
null,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* count split parts
|
||||||
|
*
|
||||||
|
* @covers ::countSplitParts
|
||||||
|
* @dataProvider countSplitPartsProvider
|
||||||
|
* @testdox countSplitParts $input with splitters $split_characters will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string|null $split_characters
|
||||||
|
* @param int $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCountSplitParts(
|
||||||
|
string $input,
|
||||||
|
?string $split_characters,
|
||||||
|
int $expected
|
||||||
|
): void {
|
||||||
|
if ($split_characters === null) {
|
||||||
|
$output = \CoreLibs\Convert\Strings::countSplitParts(
|
||||||
|
$input
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$output = \CoreLibs\Convert\Strings::countSplitParts(
|
||||||
|
$input,
|
||||||
|
$split_characters
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$output
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provider for testStripMultiplePathSlashes
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function stripMultiplePathSlashesProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'no slahses' => [
|
||||||
|
'input' => 'string_abc',
|
||||||
|
'expected' => 'string_abc',
|
||||||
|
],
|
||||||
|
'one slash' => [
|
||||||
|
'input' => 'some/foo',
|
||||||
|
'expected' => 'some/foo',
|
||||||
|
],
|
||||||
|
'two slashes' => [
|
||||||
|
'input' => 'some//foo',
|
||||||
|
'expected' => 'some/foo',
|
||||||
|
],
|
||||||
|
'three slashes' => [
|
||||||
|
'input' => 'some///foo',
|
||||||
|
'expected' => 'some/foo',
|
||||||
|
],
|
||||||
|
'slashes in front' => [
|
||||||
|
'input' => '/foo',
|
||||||
|
'expected' => '/foo',
|
||||||
|
],
|
||||||
|
'two slashes in front' => [
|
||||||
|
'input' => '//foo',
|
||||||
|
'expected' => '/foo',
|
||||||
|
],
|
||||||
|
'thee slashes in front' => [
|
||||||
|
'input' => '///foo',
|
||||||
|
'expected' => '/foo',
|
||||||
|
],
|
||||||
|
'slashes in back' => [
|
||||||
|
'input' => 'foo/',
|
||||||
|
'expected' => 'foo/',
|
||||||
|
],
|
||||||
|
'two slashes in back' => [
|
||||||
|
'input' => 'foo//',
|
||||||
|
'expected' => 'foo/',
|
||||||
|
],
|
||||||
|
'thee slashes in back' => [
|
||||||
|
'input' => 'foo///',
|
||||||
|
'expected' => 'foo/',
|
||||||
|
],
|
||||||
|
'multiple slashes' => [
|
||||||
|
'input' => '/foo//bar///string/end_times',
|
||||||
|
'expected' => '/foo/bar/string/end_times',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test multiple slashes clean up
|
||||||
|
*
|
||||||
|
* @covers ::stripMultiplePathSlashes
|
||||||
|
* @dataProvider stripMultiplePathSlashesProvider
|
||||||
|
* @testdox stripMultiplePathSlashes $input will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testStripMultiplePathSlashes(string $input, string $expected): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Convert\Strings::stripMultiplePathSlashes($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerStripUTF8BomBytes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"utf8-bom" => [
|
||||||
|
"file" => "UTF8BOM.csv",
|
||||||
|
"expect" => "Asset Type,Epic,File Name\n",
|
||||||
|
],
|
||||||
|
"utf8" => [
|
||||||
|
"file" => "UTF8.csv",
|
||||||
|
"expect" => "Asset Type,Epic,File Name\n",
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test utf8 bom remove
|
||||||
|
*
|
||||||
|
* @covers ::stripUTF8BomBytes
|
||||||
|
* @dataProvider providerStripUTF8BomBytes
|
||||||
|
* @testdox stripUTF8BomBytes $file will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $file
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testStripUTF8BomBytes(string $file, string $expected): void
|
||||||
|
{
|
||||||
|
// load sample file
|
||||||
|
if (!is_file(self::DATA_FOLDER . $file)) {
|
||||||
|
$this->markTestSkipped('File: ' . $file . ' could not be opened');
|
||||||
|
}
|
||||||
|
$file = file_get_contents(self::DATA_FOLDER . $file);
|
||||||
|
if ($file === false) {
|
||||||
|
$this->markTestSkipped('File: ' . $file . ' could not be read');
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Convert\Strings::stripUTF8BomBytes($file)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
1
4dev/tests/Convert/data/UTF8.csv
Normal file
1
4dev/tests/Convert/data/UTF8.csv
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Asset Type,Epic,File Name
|
||||||
|
1
4dev/tests/Convert/data/UTF8BOM.csv
Normal file
1
4dev/tests/Convert/data/UTF8BOM.csv
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Asset Type,Epic,File Name
|
||||||
|
@@ -1,630 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace tests;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for Combined\DateTime
|
|
||||||
* @coversDefaultClass \CoreLibs\Combined\DateTime
|
|
||||||
* @testdox \CoreLibs\Combined\DateTime method tests
|
|
||||||
*/
|
|
||||||
final class CoreLibsCombinedDateTimeTest extends TestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timestamps
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function timestampProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'valid timestamp no microtime' => [
|
|
||||||
1641515890,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
'2022-01-07 09:38:10',
|
|
||||||
],
|
|
||||||
'valid timestamp with microtime' => [
|
|
||||||
1641515890,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
'2022-01-07 09:38:10',
|
|
||||||
],
|
|
||||||
'valid timestamp with microtime float' => [
|
|
||||||
1641515890,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
'2022-01-07 09:38:10',
|
|
||||||
],
|
|
||||||
'valid micro timestamp with microtime' => [
|
|
||||||
1641515890.123456,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
'2022-01-07 09:38:10 1235ms',
|
|
||||||
],
|
|
||||||
'valid micro timestamp with microtime float' => [
|
|
||||||
1641515890.123456,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
'2022-01-07 09:38:10.1235',
|
|
||||||
],
|
|
||||||
'valid micro timestamp no microtime' => [
|
|
||||||
1641515890.123456,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
'2022-01-07 09:38:10',
|
|
||||||
],
|
|
||||||
'invalid timestamp' => [
|
|
||||||
-123123,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
'1969-12-30 22:47:57',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* interval for both directions
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function intervalProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'interval no microtime' => [
|
|
||||||
1641515890,
|
|
||||||
false,
|
|
||||||
'18999d 0h 38m 10s',
|
|
||||||
],
|
|
||||||
'interval with microtime' => [
|
|
||||||
1641515890,
|
|
||||||
true,
|
|
||||||
'18999d 0h 38m 10s',
|
|
||||||
],
|
|
||||||
'micro interval no microtime' => [
|
|
||||||
1641515890.123456,
|
|
||||||
false,
|
|
||||||
'18999d 0h 38m 10s',
|
|
||||||
],
|
|
||||||
'micro interval with microtime' => [
|
|
||||||
1641515890.123456,
|
|
||||||
true,
|
|
||||||
'18999d 0h 38m 10s 1235ms',
|
|
||||||
],
|
|
||||||
'negative interval no microtime' => [
|
|
||||||
-1641515890,
|
|
||||||
false,
|
|
||||||
'-18999d 0h 38m 10s',
|
|
||||||
],
|
|
||||||
// short for mini tests
|
|
||||||
'microtime only' => [
|
|
||||||
0.123456,
|
|
||||||
true,
|
|
||||||
'0s 1235ms',
|
|
||||||
],
|
|
||||||
'seconds only' => [
|
|
||||||
30.123456,
|
|
||||||
true,
|
|
||||||
'30s 1235ms',
|
|
||||||
],
|
|
||||||
'minutes only' => [
|
|
||||||
90.123456,
|
|
||||||
true,
|
|
||||||
'1m 30s 1235ms',
|
|
||||||
],
|
|
||||||
'hours only' => [
|
|
||||||
3690.123456,
|
|
||||||
true,
|
|
||||||
'1h 1m 30s 1235ms',
|
|
||||||
],
|
|
||||||
'days only' => [
|
|
||||||
90090.123456,
|
|
||||||
true,
|
|
||||||
'1d 1h 1m 30s 1235ms',
|
|
||||||
],
|
|
||||||
'already set' => [
|
|
||||||
'1d 1h 1m 30s 1235ms',
|
|
||||||
true,
|
|
||||||
'1d 1h 1m 30s 1235ms',
|
|
||||||
],
|
|
||||||
'invalid data' => [
|
|
||||||
'xyz',
|
|
||||||
true,
|
|
||||||
'0s',
|
|
||||||
],
|
|
||||||
'out of bounds timestamp' => [
|
|
||||||
999999999999999,
|
|
||||||
false,
|
|
||||||
'1s'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function reverseIntervalProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'interval no microtime' => [
|
|
||||||
'18999d 0h 38m 10s',
|
|
||||||
1641515890,
|
|
||||||
],
|
|
||||||
'micro interval with microtime' => [
|
|
||||||
'18999d 0h 38m 10s 1235ms',
|
|
||||||
1641515890.1235,
|
|
||||||
],
|
|
||||||
'micro interval with microtime' => [
|
|
||||||
'18999d 0h 38m 10s 1234567890ms',
|
|
||||||
1641515890.1234567,
|
|
||||||
],
|
|
||||||
'negative interval no microtime' => [
|
|
||||||
'-18999d 0h 38m 10s',
|
|
||||||
-1641515890,
|
|
||||||
],
|
|
||||||
// short for mini tests
|
|
||||||
'microtime only' => [
|
|
||||||
'0s 1235ms',
|
|
||||||
0.1235,
|
|
||||||
],
|
|
||||||
'seconds only' => [
|
|
||||||
'30s 1235ms',
|
|
||||||
30.1235,
|
|
||||||
],
|
|
||||||
'minutes only' => [
|
|
||||||
'1m 30s 1235ms',
|
|
||||||
90.1235,
|
|
||||||
],
|
|
||||||
'hours only' => [
|
|
||||||
'1h 1m 30s 1235ms',
|
|
||||||
3690.1235,
|
|
||||||
],
|
|
||||||
'days only' => [
|
|
||||||
'1d 1h 1m 30s 1235ms',
|
|
||||||
90090.1235,
|
|
||||||
],
|
|
||||||
'already set' => [
|
|
||||||
1641515890,
|
|
||||||
1641515890,
|
|
||||||
],
|
|
||||||
'invalid data' => [
|
|
||||||
'xyz',
|
|
||||||
'xyz',
|
|
||||||
],
|
|
||||||
'out of bound data' => [
|
|
||||||
'99999999999999999999d',
|
|
||||||
8.64E+24
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function dateProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'valid date with -' => [
|
|
||||||
'2021-12-12',
|
|
||||||
true,
|
|
||||||
],
|
|
||||||
'valid date with /' => [
|
|
||||||
'2021/12/12',
|
|
||||||
true,
|
|
||||||
],
|
|
||||||
'valid date time with -' => [
|
|
||||||
'2021-12-12 12:12:12',
|
|
||||||
true,
|
|
||||||
],
|
|
||||||
'invalid date' => [
|
|
||||||
'2021-31-31',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid date string' => [
|
|
||||||
'xyz',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'out of bound date' => [
|
|
||||||
'9999-12-31',
|
|
||||||
true
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function dateTimeProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'valid date time with -' => [
|
|
||||||
'2021-12-12 12:12:12',
|
|
||||||
true,
|
|
||||||
],
|
|
||||||
'valid date time with /' => [
|
|
||||||
'2021/12/12 12:12:12',
|
|
||||||
true,
|
|
||||||
],
|
|
||||||
'vald date time with hour/min' => [
|
|
||||||
'2021/12/12 12:12',
|
|
||||||
true,
|
|
||||||
],
|
|
||||||
'valid date missing time' => [
|
|
||||||
'2021-12-12',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'valid date invalid time string' => [
|
|
||||||
'2021-12-12 ab:cd',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid hour +' => [
|
|
||||||
'2021-12-12 35:12',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid hour -' => [
|
|
||||||
'2021-12-12 -12:12',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid minute +' => [
|
|
||||||
'2021-12-12 23:65:12',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid minute -' => [
|
|
||||||
'2021-12-12 23:-12:12',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid seconds +' => [
|
|
||||||
'2021-12-12 23:12:99',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid seconds -' => [
|
|
||||||
'2021-12-12 23:12:-12',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid seconds string' => [
|
|
||||||
'2021-12-12 23:12:ss',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function dateCompareProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'first date smaller' => [
|
|
||||||
'2020-12-12',
|
|
||||||
'2021-12-12',
|
|
||||||
-1,
|
|
||||||
],
|
|
||||||
'dates equal' => [
|
|
||||||
'2020-12-12',
|
|
||||||
'2020-12-12',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
'second date smaller' => [
|
|
||||||
'2021-12-12',
|
|
||||||
'2020-12-12',
|
|
||||||
1
|
|
||||||
],
|
|
||||||
'dates equal with different time' => [
|
|
||||||
'2020-12-12 12:12:12',
|
|
||||||
'2020-12-12 13:13:13',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
'invalid dates --' => [
|
|
||||||
'--',
|
|
||||||
'--',
|
|
||||||
false
|
|
||||||
],
|
|
||||||
'empty dates' => [
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
false
|
|
||||||
],
|
|
||||||
'invalid dates' => [
|
|
||||||
'not a date',
|
|
||||||
'not a date either',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'out of bound dates' => [
|
|
||||||
'1900-1-1',
|
|
||||||
'9999-12-31',
|
|
||||||
-1
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeCompareProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'first date smaller no time' => [
|
|
||||||
'2020-12-12',
|
|
||||||
'2021-12-12',
|
|
||||||
-1,
|
|
||||||
],
|
|
||||||
'dates equal no timestamp' => [
|
|
||||||
'2020-12-12',
|
|
||||||
'2020-12-12',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
'second date smaller no timestamp' => [
|
|
||||||
'2021-12-12',
|
|
||||||
'2020-12-12',
|
|
||||||
1
|
|
||||||
],
|
|
||||||
'date equal first time smaller' => [
|
|
||||||
'2020-12-12 12:12:12',
|
|
||||||
'2020-12-12 13:13:13',
|
|
||||||
-1,
|
|
||||||
],
|
|
||||||
'date equal time equal' => [
|
|
||||||
'2020-12-12 12:12:12',
|
|
||||||
'2020-12-12 12:12:12',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
'date equal second time smaller' => [
|
|
||||||
'2020-12-12 13:13:13',
|
|
||||||
'2020-12-12 12:12:12',
|
|
||||||
1,
|
|
||||||
],
|
|
||||||
'valid date invalid time' => [
|
|
||||||
'2020-12-12 13:99:13',
|
|
||||||
'2020-12-12 12:12:99',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid datetimes --' => [
|
|
||||||
'--',
|
|
||||||
'--',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'empty datetimess' => [
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
'invalid datetimes' => [
|
|
||||||
'not a date',
|
|
||||||
'not a date either',
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function daysIntervalProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'valid interval /, not named array' => [
|
|
||||||
'2020/1/1',
|
|
||||||
'2020/1/30',
|
|
||||||
false,
|
|
||||||
[29, 22, 8],
|
|
||||||
],
|
|
||||||
'valid interval /, named array' => [
|
|
||||||
'2020/1/1',
|
|
||||||
'2020/1/30',
|
|
||||||
true,
|
|
||||||
['overall' => 29, 'weekday' => 22, 'weekend' => 8],
|
|
||||||
],
|
|
||||||
'valid interval -' => [
|
|
||||||
'2020-1-1',
|
|
||||||
'2020-1-30',
|
|
||||||
false,
|
|
||||||
[29, 22, 8],
|
|
||||||
],
|
|
||||||
'valid interval switched' => [
|
|
||||||
'2020/1/30',
|
|
||||||
'2020/1/1',
|
|
||||||
false,
|
|
||||||
[28, 0, 0],
|
|
||||||
],
|
|
||||||
'valid interval with time' => [
|
|
||||||
'2020/1/1 12:12:12',
|
|
||||||
'2020/1/30 13:13:13',
|
|
||||||
false,
|
|
||||||
[28, 21, 8],
|
|
||||||
],
|
|
||||||
'invalid dates' => [
|
|
||||||
'abc',
|
|
||||||
'xyz',
|
|
||||||
false,
|
|
||||||
[0, 0, 0]
|
|
||||||
],
|
|
||||||
// this test will take a long imte
|
|
||||||
'out of bound dates' => [
|
|
||||||
'1900-1-1',
|
|
||||||
'9999-12-31',
|
|
||||||
false,
|
|
||||||
[2958463,2113189,845274],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* date string convert test
|
|
||||||
*
|
|
||||||
* @covers ::dateStringFormat
|
|
||||||
* @dataProvider timestampProvider
|
|
||||||
* @testdox dateStringFormat $input (microtime $flag) will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param int|float $input
|
|
||||||
* @param bool $flag
|
|
||||||
* @param string $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testDateStringFormat(
|
|
||||||
$input,
|
|
||||||
bool $flag_show_micro,
|
|
||||||
bool $flag_micro_as_float,
|
|
||||||
string $expected
|
|
||||||
): void {
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::dateStringFormat(
|
|
||||||
$input,
|
|
||||||
$flag_show_micro,
|
|
||||||
$flag_micro_as_float
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* interval convert test
|
|
||||||
*
|
|
||||||
* @covers ::timeStringFormat
|
|
||||||
* @dataProvider intervalProvider
|
|
||||||
* @testdox timeStringFormat $input (microtime $flag) will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param int|float $input
|
|
||||||
* @param bool $flag
|
|
||||||
* @param string $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testTimeStringFormat($input, bool $flag, string $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::timeStringFormat($input, $flag)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::stringToTime
|
|
||||||
* @dataProvider reverseIntervalProvider
|
|
||||||
* @testdox stringToTime $input will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string|int|float $input
|
|
||||||
* @param string|int|float $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testStringToTime($input, $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::stringToTime($input)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::checkDate
|
|
||||||
* @dataProvider dateProvider
|
|
||||||
* @testdox checkDate $input will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string $input
|
|
||||||
* @param bool $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCheckDate(string $input, bool $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::checkDate($input)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::checkDateTime
|
|
||||||
* @dataProvider dateTimeProvider
|
|
||||||
* @testdox checkDateTime $input will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string $input
|
|
||||||
* @param bool $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCheckDateTime(string $input, bool $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::checkDateTime($input)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::compareDate
|
|
||||||
* @dataProvider dateCompareProvider
|
|
||||||
* @testdox compareDate $input_a compared to $input_b will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string $input_a
|
|
||||||
* @param string $input_b
|
|
||||||
* @param int|bool $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCompareDate(string $input_a, string $input_b, $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::compareDate($input_a, $input_b)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::compareDateTime
|
|
||||||
* @dataProvider dateTimeCompareProvider
|
|
||||||
* @testdox compareDateTime $input_a compared to $input_b will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string $input_a
|
|
||||||
* @param string $input_b
|
|
||||||
* @param int|bool $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCompareDateTime(string $input_a, string $input_b, $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::calcDaysInterval
|
|
||||||
* @dataProvider daysIntervalProvider
|
|
||||||
* @testdox calcDaysInterval $input_a compared to $input_b will be $expected [$_dataName]
|
|
||||||
* @medium
|
|
||||||
*
|
|
||||||
* @param string $input_a
|
|
||||||
* @param string $input_b
|
|
||||||
* @param bool $flag
|
|
||||||
* @param array $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testCalcDaysInterval(string $input_a, string $input_b, bool $flag, $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Combined\DateTime::calcDaysInterval($input_a, $input_b, $flag)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// __END__
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace tests;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented class
|
|
||||||
* @coversDefaultClass \CoreLibs\Convert\Math
|
|
||||||
* @testdox \CoreLibs\Convert\Math method tests
|
|
||||||
*/
|
|
||||||
final class CoreLibsConvertMathTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array<mixed>
|
|
||||||
*/
|
|
||||||
public function fceilProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'5.5 must be 6' => [5.5, 6],
|
|
||||||
'5.1234567890 with 5 must be 6' => [5.1234567890, 6],
|
|
||||||
'6 must be 6' => [6, 6]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::fceil
|
|
||||||
* @dataProvider fceilProvider
|
|
||||||
* @testdox fceil: Input $input must be $expected
|
|
||||||
*
|
|
||||||
* @param float $input
|
|
||||||
* @param int $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testMathFceilValue(float $input, int $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Convert\Math::fceil($input)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array<mixed>
|
|
||||||
*/
|
|
||||||
public function floorProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'5123456 with -3 must be 5123000' => [5123456, -3, 5123000],
|
|
||||||
'5123456 with -10 must be 5000000' => [5123456, -10, 5000000]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::floorp
|
|
||||||
* @dataProvider floorProvider
|
|
||||||
* @testdox floor: Input $input with cutoff $cutoff must be $expected
|
|
||||||
*
|
|
||||||
* @param int $input
|
|
||||||
* @param int $cutoff
|
|
||||||
* @param int $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testMathFloorValue(int $input, int $cutoff, int $expected): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Convert\Math::floorp($input, $cutoff)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return array<mixed>
|
|
||||||
*/
|
|
||||||
public function initNumericProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'5 must be 5' => [5, 5, 'int'],
|
|
||||||
'5.123 must be 5.123' => [5.123, 5.123, 'float'],
|
|
||||||
"'5' must be 5" => ['5', 5, 'string'],
|
|
||||||
"'5.123' must be 5.123" => ['5.123', 5.123, 'string'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::initNumeric
|
|
||||||
* @dataProvider initNumericProvider
|
|
||||||
* @testdox initNumeric: Input $info $input must match $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param int|float|string $input
|
|
||||||
* @param float $expected
|
|
||||||
* @param string $info
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testMathInitNumericValue($input, float $expected, string $info): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Convert\Math::initNumeric($input)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// __END__
|
|
||||||
@@ -1,424 +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',
|
|
||||||
],
|
|
||||||
'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
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'null string, default' => [
|
|
||||||
0 => null,
|
|
||||||
1 => null,
|
|
||||||
2 => '-'
|
|
||||||
],
|
|
||||||
'empty string, ... replace' => [
|
|
||||||
0 => '',
|
|
||||||
1 => '...',
|
|
||||||
2 => '...'
|
|
||||||
],
|
|
||||||
'filled string' => [
|
|
||||||
0 => 'some string',
|
|
||||||
1 => null,
|
|
||||||
2 => 'some string'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected_group,
|
|
||||||
\CoreLibs\Debug\Support::getCallerMethodList()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 will be $expected [$_dataName]
|
|
||||||
*
|
|
||||||
* @param string|null $input
|
|
||||||
* @param string|null $replace
|
|
||||||
* @param string $expected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testDebugString(?string $input, ?string $replace, string $expected)
|
|
||||||
{
|
|
||||||
if ($replace === null) {
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Debug\Support::debugString($input)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected,
|
|
||||||
\CoreLibs\Debug\Support::debugString($input, $replace)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// __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__
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace tests;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for Output\Image
|
|
||||||
* @coversDefaultClass \CoreLibs\Output\Image
|
|
||||||
* @testdox \CoreLibs\Output\Image method tests
|
|
||||||
*/
|
|
||||||
final class CoreLibsOutputImageTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @testdox Output\Image Class tests
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testOutputImage()
|
|
||||||
{
|
|
||||||
$this->assertTrue(true, 'Output Image Tests not implemented');
|
|
||||||
$this->markTestIncomplete(
|
|
||||||
'Output\Image Tests have not yet been implemented'
|
|
||||||
);
|
|
||||||
// $this->markTestSkipped('No implementation for Output\Image at the moment');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// __END__
|
|
||||||
699
4dev/tests/Create/CoreLibsCreateEmailTest.php
Normal file
699
4dev/tests/Create/CoreLibsCreateEmailTest.php
Normal file
@@ -0,0 +1,699 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Create\Email
|
||||||
|
* @coversDefaultClass \CoreLibs\Create\Email
|
||||||
|
* @testdox \CoreLibs\Create\Email method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsCreateEmailTest extends TestCase
|
||||||
|
{
|
||||||
|
private static $log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* start DB conneciton, setup DB, etc
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
self::$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||||
|
'log_file_id' => 'CoreLibs-Create-Email-Test',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function encodeEmailNameProvider(): array
|
||||||
|
{
|
||||||
|
// 0: email
|
||||||
|
// 1: name
|
||||||
|
// 2: encoding
|
||||||
|
// 3: kv_folding
|
||||||
|
// 4: expected
|
||||||
|
return [
|
||||||
|
'all empty' => [
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
''
|
||||||
|
],
|
||||||
|
'email only' => [
|
||||||
|
'test@test.com',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'test@test.com'
|
||||||
|
],
|
||||||
|
'email and name' => [
|
||||||
|
'test@test.com',
|
||||||
|
'Test Name',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'"Test Name" <test@test.com>'
|
||||||
|
],
|
||||||
|
'name in mime encoded, default UTF-8' => [
|
||||||
|
'test@test.com',
|
||||||
|
'日本語',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'"=?UTF-8?B?5pel5pys6Kqe?=" <test@test.com>'
|
||||||
|
],
|
||||||
|
'name in mime encoded with half width Katakana, default UTF-8' => [
|
||||||
|
'test@test.com',
|
||||||
|
'日本語カタカナパ',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'"=?UTF-8?B?5pel5pys6Kqe7722776A7722776F776K776f?=" <test@test.com>'
|
||||||
|
],
|
||||||
|
'name in mime encoded with half width Katakana, folding on, default UTF-8' => [
|
||||||
|
'test@test.com',
|
||||||
|
'日本語カタカナパ',
|
||||||
|
'UTF-8',
|
||||||
|
true,
|
||||||
|
'"=?UTF-8?B?5pel5pys6Kqe44Kr44K/44Kr44OK44OR?=" <test@test.com>'
|
||||||
|
],
|
||||||
|
'name in mime encoded, UTF-8 parameter' => [
|
||||||
|
'test@test.com',
|
||||||
|
'日本語',
|
||||||
|
'UTF-8',
|
||||||
|
null,
|
||||||
|
'"=?UTF-8?B?5pel5pys6Kqe?=" <test@test.com>'
|
||||||
|
],
|
||||||
|
// does internal UTF-8 to ISO-2022-JP convert
|
||||||
|
'encoding in ISO-2022-JP' => [
|
||||||
|
'test@test.com',
|
||||||
|
'日本語',
|
||||||
|
'ISO-2022-JP',
|
||||||
|
null,
|
||||||
|
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhC?=" <test@test.com>'
|
||||||
|
],
|
||||||
|
'encoding with half width Katakana in ISO-2022-JP' => [
|
||||||
|
'test@test.com',
|
||||||
|
'日本語カタカナパ',
|
||||||
|
'ISO-2022-JP',
|
||||||
|
null,
|
||||||
|
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8/?=" <test@test.com>'
|
||||||
|
],
|
||||||
|
'encoding with half width Katakana, folding on in ISO-2022-JP' => [
|
||||||
|
'test@test.com',
|
||||||
|
'日本語カタカナパ',
|
||||||
|
'ISO-2022-JP',
|
||||||
|
true,
|
||||||
|
// 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>'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @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(
|
||||||
|
string $email,
|
||||||
|
?string $name,
|
||||||
|
?string $encoding,
|
||||||
|
?bool $kv_folding,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
|
if ($name === null && $encoding === null && $kv_folding === null) {
|
||||||
|
$encoded_email = \CoreLibs\Create\Email::encodeEmailName($email);
|
||||||
|
} elseif ($encoding === null && $kv_folding === null) {
|
||||||
|
$encoded_email = \CoreLibs\Create\Email::encodeEmailName($email, $name);
|
||||||
|
} elseif ($kv_folding === null) {
|
||||||
|
$encoded_email = \CoreLibs\Create\Email::encodeEmailName($email, $name, $encoding);
|
||||||
|
} else {
|
||||||
|
$encoded_email = \CoreLibs\Create\Email::encodeEmailName($email, $name, $encoding, $kv_folding);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$encoded_email
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendEmailProvider(): array
|
||||||
|
{
|
||||||
|
// 0: subject
|
||||||
|
// 1: body
|
||||||
|
// 2: from email
|
||||||
|
// 3: from name ('')
|
||||||
|
// 4: array for to email
|
||||||
|
// 5: replace content ([]/null)
|
||||||
|
// 6: encoding (UTF-8/null)
|
||||||
|
// 7: kv_folding
|
||||||
|
// 8: return status
|
||||||
|
// 9: expected content
|
||||||
|
return [
|
||||||
|
'all empty, fail -1' => [
|
||||||
|
'subject' => '',
|
||||||
|
'body' => '',
|
||||||
|
'from_email' => '',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => -1,
|
||||||
|
'expected_content' => [],
|
||||||
|
],
|
||||||
|
'missing to entry, fail -2' => [
|
||||||
|
'subject' => 'SUBJECT',
|
||||||
|
'body' => 'BODY',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => -2,
|
||||||
|
'expected_content' => [],
|
||||||
|
],
|
||||||
|
'bad encoding, fail -3' => [
|
||||||
|
'subject' => 'SUBJECT',
|
||||||
|
'body' => 'BODY',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => ['to@test.com'],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => 'IDONTEXISTENCODING',
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => -3,
|
||||||
|
'expected_content' => [],
|
||||||
|
],
|
||||||
|
'sending email 1' => [
|
||||||
|
'subject' => 'SUBJECT',
|
||||||
|
'body' => 'BODY',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
'test@test.com'
|
||||||
|
],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT',
|
||||||
|
'body' => 'BODY',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 1, encoded' => [
|
||||||
|
'subject' => 'SUBJECT 日本語',
|
||||||
|
'body' => 'BODY 日本語',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
'test@test.com'
|
||||||
|
],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6Kqe?=',
|
||||||
|
'body' => 'BODY 日本語',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 1, encoded, with half width katakanata' => [
|
||||||
|
'subject' => 'SUBJECT 日本語カタカナパ',
|
||||||
|
'body' => 'BODY 日本語',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
'test@test.com'
|
||||||
|
],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => 'UTF-8',
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6Kqe7722776A7722776F776K776f?=',
|
||||||
|
'body' => 'BODY 日本語',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 1, encoded, with half width katakanata, folding on' => [
|
||||||
|
'subject' => 'SUBJECT 日本語カタカナパ',
|
||||||
|
'body' => 'BODY 日本語',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
'test@test.com'
|
||||||
|
],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => 'UTF-8',
|
||||||
|
'kv_folding' => true,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6Kqe44Kr44K/44Kr44OK44OR?=',
|
||||||
|
'body' => 'BODY 日本語',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 1, encoded subject ISO-2022-JP' => [
|
||||||
|
'subject' => 'SUBJECT 日本語',
|
||||||
|
'body' => 'BODY 日本語',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
'test@test.com'
|
||||||
|
],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => 'ISO-2022-JP',
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT =?ISO-2022-JP?B?GyRCRnxLXDhsGyhC?=',
|
||||||
|
// body is stored as UTF-8 in log and here, so both must be translated
|
||||||
|
'body' => 'BODY 日本語',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 2' => [
|
||||||
|
'subject' => 'SUBJECT',
|
||||||
|
'body' => 'BODY',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
'e1@test.com',
|
||||||
|
'e2@test.com'
|
||||||
|
],
|
||||||
|
'replace' => null,
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'e1@test.com',
|
||||||
|
'subject' => 'SUBJECT',
|
||||||
|
'body' => 'BODY',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'e2@test.com',
|
||||||
|
'subject' => 'SUBJECT',
|
||||||
|
'body' => 'BODY',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 1: dynamic' => [
|
||||||
|
'subject' => 'SUBJECT {FOO}',
|
||||||
|
'body' => 'BODY {FOO} {VAR}',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
'test@test.com'
|
||||||
|
],
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo',
|
||||||
|
'VAR' => 'bar',
|
||||||
|
],
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT foo',
|
||||||
|
'body' => 'BODY foo bar',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 1: dynamic encoded' => [
|
||||||
|
'subject' => 'SUBJECT 日本語 {FOO}',
|
||||||
|
'body' => 'BODY 日本語 {FOO} {VAR}',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
'test@test.com'
|
||||||
|
],
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo',
|
||||||
|
'VAR' => 'bar',
|
||||||
|
],
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbw==?=',
|
||||||
|
'body' => 'BODY 日本語 foo bar',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 1: dynamic, to override' => [
|
||||||
|
'subject' => 'SUBJECT {FOO}',
|
||||||
|
'body' => 'BODY {FOO} {VAR}',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
[
|
||||||
|
'email' => 'test@test.com',
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo to'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo',
|
||||||
|
'VAR' => 'bar',
|
||||||
|
],
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT foo to',
|
||||||
|
'body' => 'BODY foo to bar',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 1: dynamic, to override encoded' => [
|
||||||
|
'subject' => 'SUBJECT 日本語 {FOO}',
|
||||||
|
'body' => 'BODY 日本語 {FOO} {VAR}',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
[
|
||||||
|
'email' => 'test@test.com',
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo to'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo',
|
||||||
|
'VAR' => 'bar',
|
||||||
|
],
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 'test@test.com',
|
||||||
|
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbyB0bw==?=',
|
||||||
|
'body' => 'BODY 日本語 foo to bar',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 3: dynamic, to mixed override' => [
|
||||||
|
'subject' => 'SUBJECT {FOO}',
|
||||||
|
'body' => 'BODY {FOO} {VAR}',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
[
|
||||||
|
'email' => 't1@test.com',
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo to 1'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'email' => 't2@test.com',
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo to 2'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'email' => 't3@test.com',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo',
|
||||||
|
'VAR' => 'bar',
|
||||||
|
],
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 't1@test.com',
|
||||||
|
'subject' => 'SUBJECT foo to 1',
|
||||||
|
'body' => 'BODY foo to 1 bar',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 't2@test.com',
|
||||||
|
'subject' => 'SUBJECT foo to 2',
|
||||||
|
'body' => 'BODY foo to 2 bar',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 't3@test.com',
|
||||||
|
'subject' => 'SUBJECT foo',
|
||||||
|
'body' => 'BODY foo bar',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sending email 3: dynamic, to mixed override encoded' => [
|
||||||
|
'subject' => 'SUBJECT 日本語 {FOO}',
|
||||||
|
'body' => 'BODY 日本語 {FOO} {VAR}',
|
||||||
|
'from_email' => 'test@test.com',
|
||||||
|
'from_name' => '',
|
||||||
|
'to_email' => [
|
||||||
|
[
|
||||||
|
'email' => 't1@test.com',
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo to 1'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'email' => 't2@test.com',
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo to 2'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'email' => 't3@test.com',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'replace' => [
|
||||||
|
'FOO' => 'foo',
|
||||||
|
'VAR' => 'bar',
|
||||||
|
],
|
||||||
|
'encoding' => null,
|
||||||
|
'kv_folding' => null,
|
||||||
|
'expected_status' => 2,
|
||||||
|
'expected_content' => [
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 't1@test.com',
|
||||||
|
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbyB0byAx?=',
|
||||||
|
'body' => 'BODY 日本語 foo to 1 bar',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 't2@test.com',
|
||||||
|
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbyB0byAy?=',
|
||||||
|
'body' => 'BODY 日本語 foo to 2 bar',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'header' => [
|
||||||
|
'From' => 'test@test.com'
|
||||||
|
],
|
||||||
|
'to' => 't3@test.com',
|
||||||
|
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbw==?=',
|
||||||
|
'body' => 'BODY 日本語 foo bar',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @dataProvider sendEmailProvider
|
||||||
|
* @testdox email sending with expected status $expected_status [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $subject
|
||||||
|
* @param string $body
|
||||||
|
* @param string $from_email
|
||||||
|
* @param string $from_name
|
||||||
|
* @param array $to_email
|
||||||
|
* @param array|null $replace
|
||||||
|
* @param string|null $encoding
|
||||||
|
* @param bool|null $kv_folding
|
||||||
|
* @param int $expected_status
|
||||||
|
* @param array $expected_content
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSendEmail(
|
||||||
|
string $subject,
|
||||||
|
string $body,
|
||||||
|
string $from_email,
|
||||||
|
string $from_name,
|
||||||
|
array $to_email,
|
||||||
|
?array $replace,
|
||||||
|
?string $encoding,
|
||||||
|
?bool $kv_folding,
|
||||||
|
int $expected_status,
|
||||||
|
array $expected_content
|
||||||
|
): void {
|
||||||
|
if ($replace === null) {
|
||||||
|
$replace = [];
|
||||||
|
}
|
||||||
|
if ($encoding === null) {
|
||||||
|
$encoding = 'UTF-8';
|
||||||
|
}
|
||||||
|
if ($kv_folding === null) {
|
||||||
|
$kv_folding = false;
|
||||||
|
}
|
||||||
|
// force new set for each run
|
||||||
|
self::$log->setLogUniqueId(true);
|
||||||
|
// set on of unique log id
|
||||||
|
self::$log->setLogFlag(\CoreLibs\Logging\Logger\Flag::per_run);
|
||||||
|
// init logger
|
||||||
|
$status = \CoreLibs\Create\Email::sendEmail(
|
||||||
|
$subject,
|
||||||
|
$body,
|
||||||
|
$from_email,
|
||||||
|
$from_name,
|
||||||
|
$to_email,
|
||||||
|
$replace,
|
||||||
|
$encoding,
|
||||||
|
$kv_folding,
|
||||||
|
true,
|
||||||
|
self::$log
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_status,
|
||||||
|
$status,
|
||||||
|
'Assert sending status'
|
||||||
|
);
|
||||||
|
// 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->getLogFolder() . self::$log->getLogFile()
|
||||||
|
);
|
||||||
|
if ($file !== false) {
|
||||||
|
// extract SEND EMAIL JSON line
|
||||||
|
$found = preg_match_all("/^.* <SEND EMAIL JSON> - (.*)$/m", $file, $matches);
|
||||||
|
// print "Found: $found | EMAIL: " . print_r($matches, true) . "\n";
|
||||||
|
if (!empty($matches[1])) {
|
||||||
|
foreach ($matches[1] as $pos => $email_json) {
|
||||||
|
$email = \CoreLibs\Convert\Json::jsonConvertToArray($email_json);
|
||||||
|
// print "EMAIL: " . print_r($email, true) . "\n";
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_content[$pos]['header']['From'] ?? 'MISSING FROM',
|
||||||
|
$email['header']['From'] ?? '',
|
||||||
|
'Email check: assert header from'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'text/plain; charset=' . $encoding ?? 'UTF-8',
|
||||||
|
$email['header']['Content-type'] ?? '',
|
||||||
|
'Email check: assert header content type'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'1.0',
|
||||||
|
$email['header']['MIME-Version'] ?? '',
|
||||||
|
'Email check: assert header mime version'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_content[$pos]['to'] ?? 'MISSING TO',
|
||||||
|
$email['to'] ?? '',
|
||||||
|
'Email check: assert to'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_content[$pos]['subject'] ?? 'MISSING SUBJECT',
|
||||||
|
$email['subject'] ?? '',
|
||||||
|
'Email check: assert subject'
|
||||||
|
);
|
||||||
|
// body must be translated back to encoding if encoding is not UTF-8
|
||||||
|
$this->assertEquals(
|
||||||
|
$encoding != 'UTF-8' ?
|
||||||
|
mb_convert_encoding($expected_content[$pos]['body'] ?? '', $encoding, 'UTF-8') :
|
||||||
|
$expected_content[$pos]['body'] ?? 'MISSING BODY',
|
||||||
|
$email['encoding'] != 'UTF-8' ?
|
||||||
|
mb_convert_encoding($email['body'] ?? '', $email['encoding'], 'UTF-8') :
|
||||||
|
$email['body'] ?? '',
|
||||||
|
'Email check: assert body'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -13,7 +13,11 @@ use PHPUnit\Framework\TestCase;
|
|||||||
*/
|
*/
|
||||||
final class CoreLibsCreateHashTest extends TestCase
|
final class CoreLibsCreateHashTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function hashData(): array
|
public function hashData(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@@ -30,8 +30,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
// setSessionName: true/false,
|
// setSessionName: true/false,
|
||||||
// checkActiveSession: true/false, [1st call, 2nd call]
|
// checkActiveSession: true/false, [1st call, 2nd call]
|
||||||
// getSessionId: string or false
|
// getSessionId: string or false
|
||||||
// 3: exepcted name (session)
|
// 3: exepcted name (session)]
|
||||||
// 4: expected error string
|
// 4: Exception thrown on error
|
||||||
|
// 5: exception code, null for none
|
||||||
|
// 6: expected error string
|
||||||
return [
|
return [
|
||||||
'session parameter' => [
|
'session parameter' => [
|
||||||
'sessionNameParameter',
|
'sessionNameParameter',
|
||||||
@@ -44,7 +46,9 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'sessionNameParameter',
|
'sessionNameParameter',
|
||||||
''
|
null,
|
||||||
|
null,
|
||||||
|
'',
|
||||||
],
|
],
|
||||||
'session globals' => [
|
'session globals' => [
|
||||||
'sessionNameGlobals',
|
'sessionNameGlobals',
|
||||||
@@ -57,7 +61,9 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'sessionNameGlobals',
|
'sessionNameGlobals',
|
||||||
''
|
null,
|
||||||
|
null,
|
||||||
|
'',
|
||||||
],
|
],
|
||||||
'session name default' => [
|
'session name default' => [
|
||||||
'',
|
'',
|
||||||
@@ -70,7 +76,9 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
''
|
null,
|
||||||
|
null,
|
||||||
|
'',
|
||||||
],
|
],
|
||||||
// error checks
|
// error checks
|
||||||
// 1: we are in cli
|
// 1: we are in cli
|
||||||
@@ -85,6 +93,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'RuntimeException',
|
||||||
|
1,
|
||||||
'[SESSION] No sessions in php cli'
|
'[SESSION] No sessions in php cli'
|
||||||
],
|
],
|
||||||
// 2: session disabled
|
// 2: session disabled
|
||||||
@@ -99,6 +109,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'RuntimeException',
|
||||||
|
2,
|
||||||
'[SESSION] Sessions are disabled'
|
'[SESSION] Sessions are disabled'
|
||||||
],
|
],
|
||||||
// 3: invalid session name: string
|
// 3: invalid session name: string
|
||||||
@@ -113,6 +125,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'UnexpectedValueException',
|
||||||
|
3,
|
||||||
'[SESSION] Invalid session name: 1invalid$session#;'
|
'[SESSION] Invalid session name: 1invalid$session#;'
|
||||||
],
|
],
|
||||||
// 3: invalid session name: only numbers
|
// 3: invalid session name: only numbers
|
||||||
@@ -127,6 +141,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'UnexpectedValueException',
|
||||||
|
3,
|
||||||
'[SESSION] Invalid session name: 123'
|
'[SESSION] Invalid session name: 123'
|
||||||
],
|
],
|
||||||
// 3: invalid session name: invalid name short
|
// 3: invalid session name: invalid name short
|
||||||
@@ -143,6 +159,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => '1234abcd4567'
|
'getSessionId' => '1234abcd4567'
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'RuntimeException',
|
||||||
|
4,
|
||||||
'[SESSION] Failed to activate session'
|
'[SESSION] Failed to activate session'
|
||||||
],
|
],
|
||||||
// 5: get session id return false
|
// 5: get session id return false
|
||||||
@@ -157,6 +175,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
'getSessionId' => false
|
'getSessionId' => false
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
|
'UnexpectedValueException',
|
||||||
|
5,
|
||||||
'[SESSION] getSessionId did not return a session id'
|
'[SESSION] getSessionId did not return a session id'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -173,6 +193,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
* @param string $type
|
* @param string $type
|
||||||
* @param array<mixed> $mock_data
|
* @param array<mixed> $mock_data
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
|
* @param string|null $exception
|
||||||
* @param string $expected_error
|
* @param string $expected_error
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -181,7 +202,9 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
string $type,
|
string $type,
|
||||||
array $mock_data,
|
array $mock_data,
|
||||||
string $expected,
|
string $expected,
|
||||||
string $expected_error,
|
?string $exception,
|
||||||
|
?int $exception_code,
|
||||||
|
string $expected_error
|
||||||
): void {
|
): void {
|
||||||
// override expected
|
// override expected
|
||||||
if ($type == 'd') {
|
if ($type == 'd') {
|
||||||
@@ -224,6 +247,11 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
// regex for session id
|
// regex for session id
|
||||||
$ression_id_regex = "/^\w+$/";
|
$ression_id_regex = "/^\w+$/";
|
||||||
|
|
||||||
|
if ($exception !== null) {
|
||||||
|
$this->expectException($exception);
|
||||||
|
$this->expectExceptionCode($exception_code);
|
||||||
|
}
|
||||||
|
|
||||||
unset($GLOBALS['SET_SESSION_NAME']);
|
unset($GLOBALS['SET_SESSION_NAME']);
|
||||||
$session_id = '';
|
$session_id = '';
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
@@ -253,13 +281,6 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
$expected,
|
$expected,
|
||||||
$session_mock->getSessionName()
|
$session_mock->getSessionName()
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
// false checks
|
|
||||||
$this->assertEquals(
|
|
||||||
$expected_error,
|
|
||||||
$session_mock->getErrorStr(),
|
|
||||||
'error assert'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,45 +21,83 @@ final class CoreLibsCreateUidsTest extends TestCase
|
|||||||
public function uniqIdProvider(): array
|
public function uniqIdProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
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' => [
|
'md5 hash' => [
|
||||||
0 => 'md5',
|
0 => 'md5',
|
||||||
1 => 32,
|
1 => 32,
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'sha256 hash' => [
|
'sha256 hash' => [
|
||||||
0 => 'sha256',
|
0 => 'sha256',
|
||||||
1 => 64
|
1 => 64,
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'ripemd160 hash' => [
|
'ripemd160 hash' => [
|
||||||
0 => 'ripemd160',
|
0 => 'ripemd160',
|
||||||
1 => 40
|
1 => 40,
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'adler32 hash' => [
|
'adler32 hash' => [
|
||||||
0 => 'adler32',
|
0 => 'adler32',
|
||||||
1 => 8
|
1 => 8,
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'not in list hash but valid' => [
|
'not in list, set default length' => [
|
||||||
0 => 'sha3-512',
|
0 => 'sha3-512',
|
||||||
1 => strlen(hash('sha3-512', 'A'))
|
1 => 64,
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'default hash not set' => [
|
'default hash not set' => [
|
||||||
0 => null,
|
0 => null,
|
||||||
1 => 64,
|
1 => 64,
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'invalid name' => [
|
'invalid name' => [
|
||||||
0 => 'iamnotavalidhash',
|
0 => 'iamnotavalidhash',
|
||||||
1 => 64,
|
1 => 64,
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_HASH => [
|
// auto calls
|
||||||
0 => \CoreLibs\Create\Uids::DEFAULT_HASH,
|
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH => [
|
||||||
1 => strlen(hash(\CoreLibs\Create\Uids::DEFAULT_HASH, 'A'))
|
0 => \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH,
|
||||||
|
1 => 64,
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_LONG,
|
0 => \CoreLibs\Create\Uids::STANDARD_HASH_LONG,
|
||||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A'))
|
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A')),
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_SHORT => [
|
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_SHORT => [
|
||||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_SHORT,
|
0 => \CoreLibs\Create\Uids::STANDARD_HASH_SHORT,
|
||||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A'))
|
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A')),
|
||||||
|
2 => null
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -105,26 +143,27 @@ final class CoreLibsCreateUidsTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @covers ::uniqId
|
* @covers ::uniqId
|
||||||
* @dataProvider uniqIdProvider
|
* @dataProvider uniqIdProvider
|
||||||
* @testdox uniqId $input will be length $expected [$_dataName]
|
* @testdox uniqId $input will be length $expected (Force $flag) [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string|null $input
|
* @param int|string|null $input
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
|
* @param bool|null $flag
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testUniqId(?string $input, int $expected): void
|
public function testUniqId(int|string|null $input, int $expected, ?bool $flag): void
|
||||||
{
|
{
|
||||||
if ($input === null) {
|
if ($input === null) {
|
||||||
$this->assertEquals(
|
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId());
|
||||||
$expected,
|
} elseif ($flag === null) {
|
||||||
strlen(\CoreLibs\Create\Uids::uniqId())
|
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input));
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
|
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input, $flag));
|
||||||
|
}
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
strlen(\CoreLibs\Create\Uids::uniqId($input))
|
$uniq_id_length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Because we set a constant here, we can only run one test
|
* Because we set a constant here, we can only run one test
|
||||||
@@ -10,7 +10,6 @@ use PHPUnit\Framework\TestCase;
|
|||||||
* Test class for DB\Extended\ArrayIO
|
* Test class for DB\Extended\ArrayIO
|
||||||
* This will only test the PgSQL parts
|
* This will only test the PgSQL parts
|
||||||
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
||||||
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
|
||||||
* @testdox \CoreLibs\Extended\ArrayIO method tests for extended DB interface
|
* @testdox \CoreLibs\Extended\ArrayIO method tests for extended DB interface
|
||||||
*/
|
*/
|
||||||
final class CoreLibsDBExtendedArrayIOTest extends TestCase
|
final class CoreLibsDBExtendedArrayIOTest extends TestCase
|
||||||
@@ -36,9 +35,9 @@ final class CoreLibsDBExtendedArrayIOTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDBIO()
|
public function testArrayDBIO()
|
||||||
{
|
{
|
||||||
$this->assertTrue(true, 'DB Extended ArrayIO Tests not implemented');
|
// $this->assertTrue(true, 'DB Extended ArrayIO Tests not implemented');
|
||||||
$this->markTestIncomplete(
|
$this->markTestIncomplete(
|
||||||
'DB\Extended\ArrayIO Tests have not yet been implemented'
|
'DB\Extended\ArrayIO Tests have not yet been implemented'
|
||||||
);
|
);
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
732
4dev/tests/Debug/CoreLibsDebugSupportTest.php
Normal file
732
4dev/tests/Debug/CoreLibsDebugSupportTest.php
Normal file
@@ -0,0 +1,732 @@
|
|||||||
|
<?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:6434","phar:///home/clemens/.phive/phars/phpunit-9.6.13.phar/phpunit/Framework/TestCase.php:6434"]
|
||||||
|
* @testdox getCallerFileLine check based on regex .../Framework/TestCase.php:\d+ [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetCallerFileLine(): void
|
||||||
|
{
|
||||||
|
// regex prefix with path "/../" and then fixed vendor + \d+
|
||||||
|
// or phar start if phiev installed
|
||||||
|
// phar:///home/clemens/.phive/phars/phpunit-9.6.13.phar/phpunit/Framework/TestCase.php
|
||||||
|
$regex = "/^("
|
||||||
|
. "\/.*\/vendor\/phpunit\/phpunit\/src"
|
||||||
|
. "|"
|
||||||
|
. "phar:\/\/\/.*\.phive\/phars\/phpunit-\d+\.\d+\.\d+\.phar\/phpunit"
|
||||||
|
. ")"
|
||||||
|
. "\/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: legacy
|
||||||
|
// 11: direct
|
||||||
|
// 12: full call
|
||||||
|
switch (count($compare)) {
|
||||||
|
case 10:
|
||||||
|
// add nothing
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$compare,
|
||||||
|
'assert expected 10'
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
if ($compare[0] == 'include') {
|
||||||
|
// add include at first
|
||||||
|
array_splice(
|
||||||
|
$expected,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
['include']
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
array_splice(
|
||||||
|
$expected,
|
||||||
|
6,
|
||||||
|
0,
|
||||||
|
['run']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$compare,
|
||||||
|
'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,
|
||||||
|
$compare,
|
||||||
|
'assert expected 12'
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @cover ::getCallStack
|
||||||
|
* @testdox getCallStack check if it returns data [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetCallStack(): void
|
||||||
|
{
|
||||||
|
$call_stack = Support::getCallStack();
|
||||||
|
// print "Get CALL: " . print_r(Support::getCallStack(), true) . "\n";
|
||||||
|
if ($call_stack < 8) {
|
||||||
|
$this->assertFalse(true, 'getCallStack too low: 8');
|
||||||
|
} else {
|
||||||
|
$this->assertTrue(true, 'getCallSteck ok');
|
||||||
|
}
|
||||||
|
// just test top entry
|
||||||
|
$first = array_shift($call_stack);
|
||||||
|
$this->assertStringEndsWith(
|
||||||
|
':tests\CoreLibsDebugSupportTest->testGetCallStack',
|
||||||
|
$first,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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',
|
'file' => 'cannot_read.env',
|
||||||
'status' => 2,
|
'status' => 2,
|
||||||
'content' => [],
|
'content' => [],
|
||||||
'chmod' => '000',
|
// 0000
|
||||||
|
'chmod' => '100000',
|
||||||
],
|
],
|
||||||
'empty file' => [
|
'empty file' => [
|
||||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||||
'file' => 'empty.env',
|
'file' => 'empty.env',
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'content' => [],
|
'content' => [],
|
||||||
'chmod' => null,
|
// 0664
|
||||||
|
'chmod' => '100664',
|
||||||
],
|
],
|
||||||
'override all' => [
|
'override all' => [
|
||||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||||
'file' => 'test.env',
|
'file' => 'test.env',
|
||||||
'status' => 0,
|
'status' => 0,
|
||||||
'content' => $dot_env_content,
|
'content' => $dot_env_content,
|
||||||
'chmod' => null,
|
// 0664
|
||||||
|
'chmod' => '100664',
|
||||||
],
|
],
|
||||||
'override directory' => [
|
'override directory' => [
|
||||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||||
@@ -124,6 +127,16 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
|||||||
array $expected_env,
|
array $expected_env,
|
||||||
?string $chmod
|
?string $chmod
|
||||||
): void {
|
): 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
|
// if we have file + chmod set
|
||||||
$old_chmod = null;
|
$old_chmod = null;
|
||||||
if (
|
if (
|
||||||
@@ -134,6 +147,20 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
|||||||
$old_chmod = fileperms($folder . DIRECTORY_SEPARATOR . $file);
|
$old_chmod = fileperms($folder . DIRECTORY_SEPARATOR . $file);
|
||||||
chmod($folder . DIRECTORY_SEPARATOR . $file, octdec($chmod));
|
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) {
|
if ($folder !== null && $file !== null) {
|
||||||
$status = DotEnv::readEnvFile($folder, $file);
|
$status = DotEnv::readEnvFile($folder, $file);
|
||||||
} elseif ($folder !== null) {
|
} elseif ($folder !== null) {
|
||||||
@@ -141,6 +168,7 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
|||||||
} else {
|
} else {
|
||||||
$status = DotEnv::readEnvFile();
|
$status = DotEnv::readEnvFile();
|
||||||
}
|
}
|
||||||
|
restore_error_handler();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$status,
|
$status,
|
||||||
$expected_status,
|
$expected_status,
|
||||||
@@ -153,8 +181,9 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
|||||||
'Assert _ENV correct'
|
'Assert _ENV correct'
|
||||||
);
|
);
|
||||||
// if we have file and chmod unset
|
// if we have file and chmod unset
|
||||||
if ($old_chmod !== null) {
|
print "Write mode: $old_chmod\n";
|
||||||
chmod($folder . DIRECTORY_SEPARATOR . $file, $old_chmod);
|
if ($old_chmod !== null && $chmod == '100000') {
|
||||||
|
chmod($folder . DIRECTORY_SEPARATOR . $file, 0664);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,17 +67,17 @@ final class CoreLibsGetSystemTest extends TestCase
|
|||||||
'original set' => [
|
'original set' => [
|
||||||
0 => null,
|
0 => null,
|
||||||
1 => 'NOHOST',
|
1 => 'NOHOST',
|
||||||
2 => 'NOPORT',
|
2 => 0,
|
||||||
],
|
],
|
||||||
'override set no port' => [
|
'override set no port' => [
|
||||||
0 => 'foo.org',
|
0 => 'foo.org',
|
||||||
1 => 'foo.org',
|
1 => 'foo.org',
|
||||||
2 => '80'
|
2 => 80
|
||||||
],
|
],
|
||||||
'override set with port' => [
|
'override set with port' => [
|
||||||
0 => 'foo.org:443',
|
0 => 'foo.org:443',
|
||||||
1 => 'foo.org',
|
1 => 'foo.org',
|
||||||
2 => '443'
|
2 => 443
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ final class CoreLibsGetSystemTest extends TestCase
|
|||||||
1 => 'phpunit',
|
1 => 'phpunit',
|
||||||
2 => 'phpunit',
|
2 => 'phpunit',
|
||||||
// NOTE: this can change, so it is a regex check
|
// NOTE: this can change, so it is a regex check
|
||||||
3 => "/^(\/?.*\/?)?www\/vendor\/bin\/phpunit$/",
|
3 => "/^(\/?.*\/?)?(vendor\/bin|tools)\/phpunit$/",
|
||||||
],
|
],
|
||||||
'some path with extension' => [
|
'some path with extension' => [
|
||||||
0 => '/some/path/to/file.txt',
|
0 => '/some/path/to/file.txt',
|
||||||
@@ -138,10 +138,10 @@ final class CoreLibsGetSystemTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @param string|null $input
|
* @param string|null $input
|
||||||
* @param string $expected_host
|
* @param string $expected_host
|
||||||
* @param string $expected_port
|
* @param int $expected_port
|
||||||
* @return void
|
* @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 "HOSTNAME: " . $_SERVER['HTTP_HOST'] . "<br>";
|
||||||
// print "SERVER: " . print_r($_SERVER, true) . "\n";
|
// print "SERVER: " . print_r($_SERVER, true) . "\n";
|
||||||
@@ -216,6 +216,29 @@ final class CoreLibsGetSystemTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::getIpAddresses
|
||||||
|
* @testdox getIpAddresses check
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetIpAddresses()
|
||||||
|
{
|
||||||
|
// response must have "REMOTE_ADDR" entry, others are optional
|
||||||
|
// NOTE: we have no IP addresses on command line
|
||||||
|
$this->assertTrue(
|
||||||
|
true,
|
||||||
|
"We do not have REMOTE_ADDR on command line"
|
||||||
|
);
|
||||||
|
// $this->assertContains(
|
||||||
|
// 'REMOTE_ADDR',
|
||||||
|
// array_keys(\CoreLibs\Get\System::getIpAddresses()),
|
||||||
|
// 'failed REMOTE_ADDR assert'
|
||||||
|
// );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
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
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
// default web page encoding setting
|
// for deprecation test only, will be removed
|
||||||
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')) {
|
if (!defined('BASE')) {
|
||||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
define('BASE', str_replace(DIRECTORY_SEPARATOR . 'configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||||
}
|
}
|
||||||
if (!defined('INCLUDES')) {
|
if (!defined('INCLUDES')) {
|
||||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||||
}
|
}
|
||||||
if (!defined('LANG')) {
|
|
||||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
|
||||||
}
|
|
||||||
if (!defined('LOCALE')) {
|
if (!defined('LOCALE')) {
|
||||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
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 [
|
return [
|
||||||
// 0: locale
|
// 0: locale
|
||||||
// 1: domain
|
// 1: encoding
|
||||||
// 2: encoding
|
// 2: domain
|
||||||
// 3: path
|
// 3: path
|
||||||
// 4: locale expected
|
// 4: locale expected
|
||||||
// 5: locale set expected
|
// 5: locale set expected
|
||||||
// 6: domain exepcted
|
// 6: lang expected
|
||||||
// 7: context (null for none)
|
// 7: lang short expected
|
||||||
// 8: test string in
|
// 8: encoding expected
|
||||||
// 9: test translated
|
// 9: domain exepcted
|
||||||
|
// 10: context (null for none)
|
||||||
|
// 11: test string in
|
||||||
|
// 12: test translated
|
||||||
|
// 13: deprecation message (until removed)
|
||||||
// new style load
|
// new style load
|
||||||
'gettext load en' => [
|
'gettext load en' => [
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
|
'UTF-8',
|
||||||
'frontend',
|
'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.UTF-8',
|
||||||
'en_US',
|
'en_US',
|
||||||
|
'en_US',
|
||||||
|
'en',
|
||||||
|
'UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
|
// 10
|
||||||
null,
|
null,
|
||||||
|
// 11, 12
|
||||||
'Original',
|
'Original',
|
||||||
'Translated frontend en_US',
|
'Translated frontend en_US',
|
||||||
|
// 13
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'gettext load en' => [
|
'gettext load en' => [
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
|
'UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
__DIR__ . 'includes/locale/',
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
//
|
//
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'en_US',
|
'en_US',
|
||||||
|
'en_US',
|
||||||
|
'en',
|
||||||
|
'UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
|
//
|
||||||
'context',
|
'context',
|
||||||
|
//
|
||||||
'Original',
|
'Original',
|
||||||
'Original context frontend en_US',
|
'Original context frontend en_US',
|
||||||
|
//
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
'gettext load ja' => [
|
'gettext load ja' => [
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
|
'UTF-8',
|
||||||
'admin',
|
'admin',
|
||||||
__DIR__ . 'includes/locale/',
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
//
|
//
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
'ja_JP',
|
'ja_JP',
|
||||||
|
'ja_JP',
|
||||||
|
'ja',
|
||||||
|
'UTF-8',
|
||||||
'admin',
|
'admin',
|
||||||
|
//
|
||||||
null,
|
null,
|
||||||
|
//
|
||||||
'Original',
|
'Original',
|
||||||
'Translated admin ja_JP',
|
'Translated admin ja_JP',
|
||||||
|
//
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
// mixed path and domain
|
// load short locale with different encoding
|
||||||
'mixed path and domain' => [
|
'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',
|
'en_US.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
'UTF-8',
|
||||||
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
'frontend',
|
'frontend',
|
||||||
//
|
//
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'en_US',
|
'en_US',
|
||||||
|
'en_US',
|
||||||
|
'en',
|
||||||
|
'UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
|
//
|
||||||
'context',
|
'context',
|
||||||
|
//
|
||||||
'Original',
|
'Original',
|
||||||
'Original context frontend en_US',
|
'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
|
// null set
|
||||||
'empty load new ' => [
|
'empty load new ' => [
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
|
'',
|
||||||
//
|
//
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
|
'',
|
||||||
|
'', // unset on empty call
|
||||||
|
'',
|
||||||
|
//
|
||||||
null,
|
null,
|
||||||
|
//
|
||||||
'Original',
|
'Original',
|
||||||
'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]
|
* @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string|null $locale
|
* @param string|null $locale
|
||||||
|
* @param string|null $encoding
|
||||||
* @param string|null $domain
|
* @param string|null $domain
|
||||||
* @param string|null $path
|
* @param string|null $path
|
||||||
* @param string $locale_expected
|
* @param string $locale_expected
|
||||||
* @param string $locale_set_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 $domain_expected
|
||||||
* @param ?string $context
|
* @param string|null $context
|
||||||
* @param string $original
|
* @param string $original
|
||||||
* @param string $translated
|
* @param string $translated
|
||||||
|
* @param string|null $deprecation_message
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testL10nObject(
|
public function testL10nObject(
|
||||||
?string $locale,
|
?string $locale,
|
||||||
|
?string $encoding,
|
||||||
?string $domain,
|
?string $domain,
|
||||||
?string $path,
|
?string $path,
|
||||||
string $locale_expected,
|
string $locale_expected,
|
||||||
string $locale_set_expected,
|
string $locale_set_expected,
|
||||||
|
string $lang_expected,
|
||||||
|
string $lang_short_expected,
|
||||||
|
string $encoding_expected,
|
||||||
string $domain_expected,
|
string $domain_expected,
|
||||||
?string $context,
|
?string $context,
|
||||||
string $original,
|
string $original,
|
||||||
string $translated
|
string $translated,
|
||||||
|
?string $deprecation_message
|
||||||
): void {
|
): 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) {
|
if ($locale === null) {
|
||||||
$l10n = new \CoreLibs\Language\L10n();
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
} elseif ($domain === null) {
|
} elseif ($domain === null) {
|
||||||
|
// deprecated, locale + domain must be set, handled like empty calls
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||||
} elseif ($path === null) {
|
} elseif ($path === null) {
|
||||||
|
// deprecated, path must be set, will thow DEPRECATION error, handled like empty
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
$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);
|
$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";
|
// print "MO: " . $l10n->getMoFile() . "\n";
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$locale_expected,
|
$locale_expected,
|
||||||
@@ -248,6 +338,20 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
'Translated string assert failed in context: ' . $context
|
'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
|
// l10nReloadMOfile and getTranslator
|
||||||
@@ -283,7 +387,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
// set 0-2
|
// set 0-2
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
__DIR__ . 'includes/locale/',
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
// status 3
|
// status 3
|
||||||
false,
|
false,
|
||||||
// to translate 4
|
// to translate 4
|
||||||
@@ -296,7 +400,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
// set new 8-10
|
// set new 8-10
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
__DIR__ . 'includes/locale/',
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
// status new 11
|
// status new 11
|
||||||
false,
|
false,
|
||||||
// check new setter 12-14
|
// check new setter 12-14
|
||||||
@@ -322,7 +426,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
// set new 8-10
|
// set new 8-10
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
__DIR__ . 'includes/locale/',
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
// status new 11
|
// status new 11
|
||||||
false,
|
false,
|
||||||
// check new setter 12-14
|
// check new setter 12-14
|
||||||
@@ -387,12 +491,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
string $domain_expected_b,
|
string $domain_expected_b,
|
||||||
string $translated_b
|
string $translated_b
|
||||||
): void {
|
): void {
|
||||||
if ($locale === null) {
|
if ($locale === null || $domain === null || $path === null) {
|
||||||
$l10n = new \CoreLibs\Language\L10n();
|
$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 {
|
} else {
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||||
}
|
}
|
||||||
@@ -494,16 +594,16 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
// 0: locale
|
// 0: locale
|
||||||
// 1: path
|
// 1: domain
|
||||||
// 2: domain
|
// 2: path
|
||||||
// 3: context (null for none)
|
// 3: context (null for none)
|
||||||
// 4: single string
|
// 4: single string
|
||||||
// 5: plural string
|
// 5: plural string
|
||||||
// 6: array for each n value expected string
|
// 6: array for each n value expected string
|
||||||
'plural text en' => [
|
'plural text en' => [
|
||||||
'en_US',
|
'en_US',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'admin',
|
'admin',
|
||||||
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
// context
|
// context
|
||||||
null,
|
null,
|
||||||
// text single/multi in
|
// text single/multi in
|
||||||
@@ -518,8 +618,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
],
|
],
|
||||||
'plural text context en' => [
|
'plural text context en' => [
|
||||||
'en_US',
|
'en_US',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'admin',
|
'admin',
|
||||||
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
// context
|
// context
|
||||||
'context',
|
'context',
|
||||||
// text single/multi in
|
// 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]
|
* @testdox plural string test for locale $locale and domain $domain with $context [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string $locale
|
* @param string $locale
|
||||||
* @param string $path
|
|
||||||
* @param string $domain
|
* @param string $domain
|
||||||
|
* @param string $path
|
||||||
* @param ?string $context
|
* @param ?string $context
|
||||||
* @param string $original_single
|
* @param string $original_single
|
||||||
* @param string $original_plural
|
* @param string $original_plural
|
||||||
@@ -555,8 +655,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
public function testNgettext(
|
public function testNgettext(
|
||||||
// config 0-3
|
// config 0-3
|
||||||
string $locale,
|
string $locale,
|
||||||
string $path,
|
|
||||||
string $domain,
|
string $domain,
|
||||||
|
string $path,
|
||||||
// context string
|
// context string
|
||||||
?string $context,
|
?string $context,
|
||||||
// input strings
|
// input strings
|
||||||
@@ -565,7 +665,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
// expected
|
// expected
|
||||||
array $expected_strings
|
array $expected_strings
|
||||||
): void {
|
): void {
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain, false);
|
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||||
|
|
||||||
foreach ($expected_strings as $n => $expected) {
|
foreach ($expected_strings as $n => $expected) {
|
||||||
if (empty($context)) {
|
if (empty($context)) {
|
||||||
@@ -981,7 +1081,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
'standard en' => [
|
'standard en' => [
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
__DIR__ . 'includes/locale/',
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
'Original',
|
'Original',
|
||||||
'Translated frontend en_US',
|
'Translated frontend en_US',
|
||||||
@@ -989,7 +1089,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
'standard ja' => [
|
'standard ja' => [
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
'admin',
|
'admin',
|
||||||
__DIR__ . 'includes/locale/',
|
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
'Original',
|
'Original',
|
||||||
'Translated admin ja_JP',
|
'Translated admin ja_JP',
|
||||||
@@ -1030,6 +1130,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
_textdomain($domain);
|
_textdomain($domain);
|
||||||
_bindtextdomain($domain, $path);
|
_bindtextdomain($domain, $path);
|
||||||
_bind_textdomain_codeset($domain, $encoding);
|
_bind_textdomain_codeset($domain, $encoding);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$translated,
|
$translated,
|
||||||
__($original),
|
__($original),
|
||||||
1
4dev/tests/Language/includes/locale/ja
Symbolic link
1
4dev/tests/Language/includes/locale/ja
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
ja_JP
|
||||||
563
4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php
Normal file
563
4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php
Normal file
@@ -0,0 +1,563 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use CoreLibs\Logging\Logger\Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Logging
|
||||||
|
* @coversDefaultClass \CoreLibs\Logging\ErrorMessages
|
||||||
|
* @testdox \CoreLibs\Logging\ErrorMEssages method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||||
|
{
|
||||||
|
private const LOG_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tear down and remove log data
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function tearDownAfterClass(): void
|
||||||
|
{
|
||||||
|
array_map('unlink', glob(self::LOG_FOLDER . '*.log'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for checking level only
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerErrorMessageLevel(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'ok' => [
|
||||||
|
'level' => 'ok',
|
||||||
|
'str' => 'OK',
|
||||||
|
'expected' => 'ok',
|
||||||
|
],
|
||||||
|
'success' => [
|
||||||
|
'level' => 'success',
|
||||||
|
'str' => 'SUCCESS',
|
||||||
|
'expected' => 'success',
|
||||||
|
],
|
||||||
|
'info' => [
|
||||||
|
'level' => 'info',
|
||||||
|
'str' => 'INFO',
|
||||||
|
'expected' => 'info',
|
||||||
|
],
|
||||||
|
'notice' => [
|
||||||
|
'level' => 'notice',
|
||||||
|
'str' => 'NOTICE',
|
||||||
|
'expected' => 'notice',
|
||||||
|
],
|
||||||
|
'warn' => [
|
||||||
|
'level' => 'warn',
|
||||||
|
'str' => 'WARN',
|
||||||
|
'expected' => 'warn'
|
||||||
|
],
|
||||||
|
'warning' => [
|
||||||
|
'level' => 'warning',
|
||||||
|
'str' => 'WARN',
|
||||||
|
'expected' => 'warn'
|
||||||
|
],
|
||||||
|
'error' => [
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR',
|
||||||
|
'expected' => 'error'
|
||||||
|
],
|
||||||
|
'abort' => [
|
||||||
|
'level' => 'abort',
|
||||||
|
'str' => 'ABORT',
|
||||||
|
'expected' => 'abort'
|
||||||
|
],
|
||||||
|
'crash' => [
|
||||||
|
'level' => 'crash',
|
||||||
|
'str' => 'CRASH',
|
||||||
|
'expected' => 'crash'
|
||||||
|
],
|
||||||
|
'wrong level' => [
|
||||||
|
'level' => 'wrong',
|
||||||
|
'str' => 'WRONG',
|
||||||
|
'expected' => 'unknown'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @dataProvider providerErrorMessageLevel
|
||||||
|
* @testdox error message level: $level will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $level
|
||||||
|
* @param string $str
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testErrorMessageLevelOk(string $level, string $str, string $expected): void
|
||||||
|
{
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testErrorMessagesLevelOk',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Error,
|
||||||
|
]);
|
||||||
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
|
$em->setMessage(
|
||||||
|
$level,
|
||||||
|
$str
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'level' => $expected,
|
||||||
|
'str' => $str,
|
||||||
|
'id' => '',
|
||||||
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
|
'highlight' => [],
|
||||||
|
],
|
||||||
|
$em->getLastErrorMsg()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox Test of all methods for n messages [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testErrorMessageOk(): void
|
||||||
|
{
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testErrorMessagesOk',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Error
|
||||||
|
]);
|
||||||
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
|
$em->setErrorMsg(
|
||||||
|
'100',
|
||||||
|
'info',
|
||||||
|
'INFO MESSAGE'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'id' => '100',
|
||||||
|
'level' => 'info',
|
||||||
|
'str' => 'INFO MESSAGE',
|
||||||
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
|
'highlight' => [],
|
||||||
|
],
|
||||||
|
$em->getLastErrorMsg()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
['100'],
|
||||||
|
$em->getErrorIds()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'id' => '100',
|
||||||
|
'level' => 'info',
|
||||||
|
'str' => 'INFO MESSAGE',
|
||||||
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
|
'highlight' => [],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
$em->getErrorMsg()
|
||||||
|
);
|
||||||
|
|
||||||
|
$em->setErrorMsg(
|
||||||
|
'200',
|
||||||
|
'error',
|
||||||
|
'ERROR MESSAGE'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR MESSAGE',
|
||||||
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
|
'highlight' => [],
|
||||||
|
],
|
||||||
|
$em->getLastErrorMsg()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
['100', '200'],
|
||||||
|
$em->getErrorIds()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'id' => '100',
|
||||||
|
'level' => 'info',
|
||||||
|
'str' => 'INFO MESSAGE',
|
||||||
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
|
'highlight' => [],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR MESSAGE',
|
||||||
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
|
'highlight' => [],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
$em->getErrorMsg()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerErrorMessageLog(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'error, not logged' => [
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<ERROR> ERROR MESSAGE',
|
||||||
|
],
|
||||||
|
'error, logged' => [
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => true,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<ERROR> ERROR MESSAGE',
|
||||||
|
],
|
||||||
|
'error, logged, message' => [
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR MESSAGE',
|
||||||
|
'message' => 'OTHER ERROR MESSAGE',
|
||||||
|
'log_error' => true,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<ERROR> OTHER ERROR MESSAGE',
|
||||||
|
],
|
||||||
|
'warn, not logged' => [
|
||||||
|
'id' => '300',
|
||||||
|
'level' => 'warn',
|
||||||
|
'str' => 'WARNING MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<WARNING> WARNING MESSAGE',
|
||||||
|
],
|
||||||
|
'warn, logged' => [
|
||||||
|
'id' => '300',
|
||||||
|
'level' => 'warn',
|
||||||
|
'str' => 'WARNING MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => true,
|
||||||
|
'expected' => '<WARNING> WARNING MESSAGE',
|
||||||
|
],
|
||||||
|
'warn, logged, message' => [
|
||||||
|
'id' => '300',
|
||||||
|
'level' => 'warn',
|
||||||
|
'str' => 'WARNING MESSAGE',
|
||||||
|
'message' => 'OTHER WARNING MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => true,
|
||||||
|
'expected' => '<WARNING> OTHER WARNING MESSAGE',
|
||||||
|
],
|
||||||
|
'notice' => [
|
||||||
|
'id' => '100',
|
||||||
|
'level' => 'notice',
|
||||||
|
'str' => 'NOTICE MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<NOTICE> NOTICE MESSAGE',
|
||||||
|
],
|
||||||
|
'notice, message' => [
|
||||||
|
'id' => '100',
|
||||||
|
'level' => 'notice',
|
||||||
|
'str' => 'NOTICE MESSAGE',
|
||||||
|
'message' => 'OTHER NOTICE MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<NOTICE> OTHER NOTICE MESSAGE',
|
||||||
|
],
|
||||||
|
'crash' => [
|
||||||
|
'id' => '300',
|
||||||
|
'level' => 'crash',
|
||||||
|
'str' => 'CRASH MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<ALERT> CRASH MESSAGE',
|
||||||
|
],
|
||||||
|
'crash, message' => [
|
||||||
|
'id' => '300',
|
||||||
|
'level' => 'crash',
|
||||||
|
'str' => 'CRASH MESSAGE',
|
||||||
|
'message' => 'OTHER CRASH MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<ALERT> OTHER CRASH MESSAGE',
|
||||||
|
],
|
||||||
|
'abort' => [
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'abort',
|
||||||
|
'str' => 'ABORT MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<CRITICAL> ABORT MESSAGE',
|
||||||
|
],
|
||||||
|
'abort, message' => [
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'abort',
|
||||||
|
'str' => 'ABORT MESSAGE',
|
||||||
|
'message' => 'OTHER ABORT MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<CRITICAL> OTHER ABORT MESSAGE',
|
||||||
|
],
|
||||||
|
'unknown' => [
|
||||||
|
'id' => '400',
|
||||||
|
'level' => 'wrong level',
|
||||||
|
'str' => 'WRONG LEVEL MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<EMERGENCY> WRONG LEVEL MESSAGE',
|
||||||
|
],
|
||||||
|
'unknown, message' => [
|
||||||
|
'id' => '400',
|
||||||
|
'level' => 'wrong level',
|
||||||
|
'str' => 'WRONG LEVEL MESSAGE',
|
||||||
|
'message' => 'OTHER WRONG LEVEL MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
|
'log_warning' => null,
|
||||||
|
'expected' => '<EMERGENCY> OTHER WRONG LEVEL MESSAGE',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @dataProvider providerErrorMessageLog
|
||||||
|
* @testdox Test Log writing with log level Error [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param string $level
|
||||||
|
* @param string $str
|
||||||
|
* @param string|null $message
|
||||||
|
* @param bool|null $log_error
|
||||||
|
* @param bool|null $log_warning
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testErrorMessageLogErrorLevel(
|
||||||
|
string $id,
|
||||||
|
string $level,
|
||||||
|
string $str,
|
||||||
|
?string $message,
|
||||||
|
?bool $log_error,
|
||||||
|
?bool $log_warning,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testErrorMessagesLogError',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Notice,
|
||||||
|
'log_per_run' => true
|
||||||
|
]);
|
||||||
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
|
$em->setErrorMsg(
|
||||||
|
$id,
|
||||||
|
$level,
|
||||||
|
$str,
|
||||||
|
message: $message,
|
||||||
|
log_error: $log_error,
|
||||||
|
log_warning: $log_warning
|
||||||
|
);
|
||||||
|
$file_content = '';
|
||||||
|
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||||
|
$file_content = file_get_contents(
|
||||||
|
$log->getLogFolder() . $log->getLogFile()
|
||||||
|
) ?: '';
|
||||||
|
}
|
||||||
|
// if error, if null or false, it will not be logged
|
||||||
|
if ($level == 'error' && ($log_error === null || $log_error === false)) {
|
||||||
|
$this->assertStringNotContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
} elseif ($level == 'warn' && ($log_warning === null || $log_warning === false)) {
|
||||||
|
$this->assertStringNotContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @dataProvider providerErrorMessageLog
|
||||||
|
* @testdox Test Log writing with log Level Debug [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param string $level
|
||||||
|
* @param string $str
|
||||||
|
* @param string|null $message
|
||||||
|
* @param bool|null $log_error
|
||||||
|
* @param bool|null $log_warning
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testErrorMessageLogErrorDebug(
|
||||||
|
string $id,
|
||||||
|
string $level,
|
||||||
|
string $str,
|
||||||
|
?string $message,
|
||||||
|
?bool $log_error,
|
||||||
|
?bool $log_warning,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testErrorMessagesLogDebug',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Debug,
|
||||||
|
'log_per_run' => true
|
||||||
|
]);
|
||||||
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
|
$em->setErrorMsg(
|
||||||
|
$id,
|
||||||
|
$level,
|
||||||
|
$str,
|
||||||
|
message: $message,
|
||||||
|
log_error: $log_error,
|
||||||
|
log_warning: $log_warning
|
||||||
|
);
|
||||||
|
$file_content = '';
|
||||||
|
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||||
|
$file_content = file_get_contents(
|
||||||
|
$log->getLogFolder() . $log->getLogFile()
|
||||||
|
) ?: '';
|
||||||
|
}
|
||||||
|
// if error, and log is debug level, only explicit false are not logged
|
||||||
|
if ($level == 'error' && $log_error === false) {
|
||||||
|
$this->assertStringNotContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
} elseif ($level == 'warn' && $log_warning === false) {
|
||||||
|
$this->assertStringNotContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox Test jump target set and reporting
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testJumpTarget(): void
|
||||||
|
{
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testErrorMessagesLogDebug',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Debug,
|
||||||
|
'log_per_run' => true
|
||||||
|
]);
|
||||||
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
|
$em->setJumpTarget(
|
||||||
|
'target-f',
|
||||||
|
'Target text'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error']
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
// set same target, keep as before
|
||||||
|
$em->setJumpTarget(
|
||||||
|
'target-f',
|
||||||
|
'Other text'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error']
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
// add new now two messages
|
||||||
|
$em->setJumpTarget(
|
||||||
|
'target-s',
|
||||||
|
'More text'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'],
|
||||||
|
['target' => 'target-s', 'info' => 'More text', 'level' => 'error'],
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
// add empty info
|
||||||
|
$em->setJumpTarget(
|
||||||
|
'target-e',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'],
|
||||||
|
['target' => 'target-s', 'info' => 'More text', 'level' => 'error'],
|
||||||
|
['target' => 'target-e', 'info' => 'Jump to: target-e', 'level' => 'error'],
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
// add through message
|
||||||
|
$em->setErrorMsg('E-101', 'abort', 'Abort message', jump_target:[
|
||||||
|
'target' => 'abort-target',
|
||||||
|
'info' => 'Abort error'
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'],
|
||||||
|
['target' => 'target-s', 'info' => 'More text', 'level' => 'error'],
|
||||||
|
['target' => 'target-e', 'info' => 'Jump to: target-e', 'level' => 'error'],
|
||||||
|
['target' => 'abort-target', 'info' => 'Abort error', 'level' => 'abort'],
|
||||||
|
],
|
||||||
|
$em->getJumpTarget()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
847
4dev/tests/Logging/CoreLibsLoggingLoggingTest.php
Normal file
847
4dev/tests/Logging/CoreLibsLoggingLoggingTest.php
Normal file
@@ -0,0 +1,847 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use CoreLibs\Logging\Logger\Level;
|
||||||
|
use CoreLibs\Logging\Logger\Flag;
|
||||||
|
|
||||||
|
// TODO: setLogPer test log file written matches pattern
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Logging
|
||||||
|
* @coversDefaultClass \CoreLibs\Logging\Logging
|
||||||
|
* @testdox \CoreLibs\Logging\Logging method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsLoggingLoggingTest extends TestCase
|
||||||
|
{
|
||||||
|
private const LOG_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;
|
||||||
|
private const REGEX_BASE = "\[[\d\-\s\.:]+\]\s{1}" // date
|
||||||
|
. "\[[\w\.]+(:\d+)?\]\s{1}" // host:port
|
||||||
|
. "\[(phar:\/\/)?[\w\-\.\/]+:\d+\]\s{1}" // folder/file [note phar:// is for phpunit]
|
||||||
|
. "\[\w+\]\s{1}" // run id
|
||||||
|
. "{[\w\\\\]+((::|->)\w+)?}\s{1}"; // class
|
||||||
|
|
||||||
|
public static function tearDownAfterClass(): void
|
||||||
|
{
|
||||||
|
array_map('unlink', glob(self::LOG_FOLDER . '*.log'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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' => [
|
||||||
|
'options' => [
|
||||||
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||||
|
'log_file_id' => 'testClassInit',
|
||||||
|
],
|
||||||
|
'expected' => [
|
||||||
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||||
|
'log_level' => Level::Debug,
|
||||||
|
'log_file_id' => 'testClassInit',
|
||||||
|
],
|
||||||
|
'override' => [],
|
||||||
|
],
|
||||||
|
// -> deprecation warning, log_folder must be set
|
||||||
|
'no log folder set' => [
|
||||||
|
'options' => [
|
||||||
|
'log_file_id' => 'testClassInit'
|
||||||
|
],
|
||||||
|
'expected' => [
|
||||||
|
'log_folder' => getcwd() . DIRECTORY_SEPARATOR,
|
||||||
|
'log_level' => Level::Debug,
|
||||||
|
'log_file_id' => 'testClassInit',
|
||||||
|
],
|
||||||
|
'override' => []
|
||||||
|
],
|
||||||
|
// -> upcoming deprecated
|
||||||
|
'file_id set but not log_file_id' => [
|
||||||
|
'options' => [
|
||||||
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||||
|
'file_id' => 'testClassInit',
|
||||||
|
],
|
||||||
|
'expected' => [
|
||||||
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||||
|
'log_level' => Level::Debug,
|
||||||
|
'log_file_id' => 'testClassInit',
|
||||||
|
],
|
||||||
|
'override' => [],
|
||||||
|
],
|
||||||
|
// both file_id and log_file_id set -> WARNING
|
||||||
|
'file_id and log_file_id set' => [
|
||||||
|
'options' => [
|
||||||
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||||
|
'file_id' => 'testClassInit',
|
||||||
|
'log_file_id' => 'testClassInit',
|
||||||
|
],
|
||||||
|
'expected' => [
|
||||||
|
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||||
|
'log_level' => Level::Debug,
|
||||||
|
'log_file_id' => 'testClassInit',
|
||||||
|
],
|
||||||
|
'override' => [],
|
||||||
|
],
|
||||||
|
// no log file id set -> error,
|
||||||
|
'nothing set' => [
|
||||||
|
'options' => [],
|
||||||
|
'expected' => [
|
||||||
|
'log_folder' => getcwd() . DIRECTORY_SEPARATOR,
|
||||||
|
'log_level' => Level::Debug,
|
||||||
|
'log_file_id' => 'NOHOST-0_PHPUnit-TextUI-Command',
|
||||||
|
],
|
||||||
|
'override' => []
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init logging class
|
||||||
|
*
|
||||||
|
* @dataProvider optionsProvider
|
||||||
|
* @testdox init test [$_dataName]
|
||||||
|
*
|
||||||
|
* @param array $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) {
|
||||||
|
if (!defined($var)) {
|
||||||
|
define($var, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for deprecated no log_folder set
|
||||||
|
// if base is defined and it does have AAASetupData set
|
||||||
|
// change the log_folder "Debug" to "AAASetupData"
|
||||||
|
if (
|
||||||
|
defined('BASE') &&
|
||||||
|
strpos(BASE, DIRECTORY_SEPARATOR . 'AAASetupData') !== false
|
||||||
|
) {
|
||||||
|
$expected['log_folder'] = str_replace(
|
||||||
|
DIRECTORY_SEPARATOR . 'Debug',
|
||||||
|
DIRECTORY_SEPARATOR . 'AAASetupData',
|
||||||
|
$expected['log_folder']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if not log folder and constant set -> expect E_USER_DEPRECATION
|
||||||
|
if (!empty($override['constant']) && empty($options['log_folder'])) {
|
||||||
|
// the deprecation message
|
||||||
|
$deprecation_message = 'options: log_folder must be set. '
|
||||||
|
. 'Setting via BASE and LOG constants is deprecated';
|
||||||
|
// 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
|
||||||
|
);
|
||||||
|
// catch this with the message
|
||||||
|
$this->expectExceptionMessage($deprecation_message);
|
||||||
|
}
|
||||||
|
// alert for log file id with globals
|
||||||
|
if (!empty($override['constant']) && empty($options['log_file_id'])) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
// alert for log file id and file id set
|
||||||
|
if (
|
||||||
|
!empty($options['log_file_id']) &&
|
||||||
|
!empty($options['file_id'])
|
||||||
|
) {
|
||||||
|
set_error_handler(
|
||||||
|
static function (int $errno, string $errstr): never {
|
||||||
|
throw new \InvalidArgumentException($errstr, $errno);
|
||||||
|
},
|
||||||
|
E_USER_WARNING
|
||||||
|
);
|
||||||
|
$error_message = 'options: "file_id" is deprecated use: "log_file_id".';
|
||||||
|
$this->expectExceptionMessage($error_message);
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
set_error_handler(
|
||||||
|
static function (int $errno, string $errstr): never {
|
||||||
|
throw new \Exception($errstr, $errno);
|
||||||
|
},
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
$this->expectException(\Exception::class);
|
||||||
|
// $error_message = 'options: both log_file_id and log_id are set at the same time, will use log_file_id';
|
||||||
|
// $this->expectExceptionMessage($error_message);
|
||||||
|
}
|
||||||
|
// empty log folder
|
||||||
|
if (empty($override['constant']) && empty($options['log_folder'])) {
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessageMatches("/^Missing mandatory option: \"/");
|
||||||
|
} elseif (empty($options['log_file_id']) && !empty($options['file_id'])) {
|
||||||
|
// the deprecation message
|
||||||
|
$deprecation_message = 'options: "file_id" is deprecated use: "log_file_id".';
|
||||||
|
// 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
|
||||||
|
);
|
||||||
|
// catch this with the message
|
||||||
|
$this->expectExceptionMessage($deprecation_message);
|
||||||
|
}
|
||||||
|
$log = new \CoreLibs\Logging\Logging($options);
|
||||||
|
// reset error handler
|
||||||
|
restore_error_handler();
|
||||||
|
// check that settings match
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected['log_folder'],
|
||||||
|
$log->getLogFolder(),
|
||||||
|
'log folder not matching'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected['log_file_id'],
|
||||||
|
$log->getLogFileId(),
|
||||||
|
'log file id not matching'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test all setters/getters
|
||||||
|
|
||||||
|
// setLoggingLevel
|
||||||
|
// getLoggingLevel
|
||||||
|
// loggingLevelIsDebug
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setLoggingLevel
|
||||||
|
* @covers ::getLoggingLevel
|
||||||
|
* @covers ::loggingLevelIsDebug
|
||||||
|
* @testdox setLoggingLevel set/get checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSetLoggingLevel(): void
|
||||||
|
{
|
||||||
|
// valid that is not Debug
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testSetLoggingLevel',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Info
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
Level::Info,
|
||||||
|
$log->getLoggingLevel()
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
$log->loggingLevelIsDebug()
|
||||||
|
);
|
||||||
|
// not set, should be debug]
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testSetLoggingLevel',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
Level::Debug,
|
||||||
|
$log->getLoggingLevel()
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
$log->loggingLevelIsDebug()
|
||||||
|
);
|
||||||
|
// invalid, should be debug, will throw excpetion too
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage('Option: "log_level" is not of instance \CoreLibs\Logging\Logger\Level');
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testSetLoggingLevel',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => 'I'
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
Level::Debug,
|
||||||
|
$log->getLoggingLevel()
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
$log->loggingLevelIsDebug()
|
||||||
|
);
|
||||||
|
// set valid, then change
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testSetLoggingLevel',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => Level::Info
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
Level::Info,
|
||||||
|
$log->getLoggingLevel()
|
||||||
|
);
|
||||||
|
$log->setLoggingLevel(Level::Notice);
|
||||||
|
$this->assertEquals(
|
||||||
|
Level::Notice,
|
||||||
|
$log->getLoggingLevel()
|
||||||
|
);
|
||||||
|
// illegal logging level
|
||||||
|
$this->expectException(\Psr\Log\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessageMatches("/^Level \"NotGood\" is not defined, use one of: /");
|
||||||
|
$log->setLoggingLevel('NotGood');
|
||||||
|
}
|
||||||
|
|
||||||
|
// setLogFileId
|
||||||
|
// getLogFileId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setLogFileId
|
||||||
|
* @covers ::getLogFileId
|
||||||
|
* @testdox setLogFileId set/get checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testLogFileId(): void
|
||||||
|
{
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testLogFileId',
|
||||||
|
'log_folder' => self::LOG_FOLDER
|
||||||
|
]);
|
||||||
|
// bad, keep same
|
||||||
|
$log->setLogFileId('$$##$%#$%&');
|
||||||
|
$this->assertEquals(
|
||||||
|
'testLogFileId',
|
||||||
|
$log->getLogFileId()
|
||||||
|
);
|
||||||
|
// good, change
|
||||||
|
$log->setLogFileId('validID');
|
||||||
|
$this->assertEquals(
|
||||||
|
'validID',
|
||||||
|
$log->getLogFileId()
|
||||||
|
);
|
||||||
|
// invalid on init
|
||||||
|
$this->expectException(\Psr\Log\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage('LogFileId: no log file id set');
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => '$$$"#"#$"#$',
|
||||||
|
'log_folder' => self::LOG_FOLDER
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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\Logging\Logging([
|
||||||
|
'log_file_id' => 'testLogUniqueId',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_per_run' => $option
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testLogUniqueId',
|
||||||
|
'log_folder' => self::LOG_FOLDER
|
||||||
|
]);
|
||||||
|
$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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// setLogDate
|
||||||
|
// getLogDate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setLogDate
|
||||||
|
* @covers ::getLogDate
|
||||||
|
* @testdox setLogDate set/get checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSetLogDate(): void
|
||||||
|
{
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testLogFileId',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_per_date' => true,
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
date('Y-m-d'),
|
||||||
|
$log->getLogDate()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setLogFlag
|
||||||
|
// getLogFlag
|
||||||
|
// unsetLogFlag
|
||||||
|
// getLogFlags
|
||||||
|
// Logger\Flag
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers Logger\Flag
|
||||||
|
* @testdox Logger\Flag enum test
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testLoggerFlag(): void
|
||||||
|
{
|
||||||
|
// logger flags to check that they exist
|
||||||
|
$flags = [
|
||||||
|
'all_off' => 0,
|
||||||
|
'per_run' => 1,
|
||||||
|
'per_date' => 2,
|
||||||
|
'per_group' => 4,
|
||||||
|
'per_page' => 8,
|
||||||
|
'per_class' => 16,
|
||||||
|
'per_level' => 32,
|
||||||
|
];
|
||||||
|
// from int -> return value
|
||||||
|
foreach ($flags as $name => $value) {
|
||||||
|
$this->assertEquals(
|
||||||
|
Flag::fromName($name),
|
||||||
|
Flag::fromValue($value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setLogFlag
|
||||||
|
* @covers ::getLogFlag
|
||||||
|
* @covers ::unsetLogFlag
|
||||||
|
* @covers ::getLogFlags
|
||||||
|
* @testdox setLogDate set/get checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSetLogFlag(): void
|
||||||
|
{
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testSetLogFlag',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
]);
|
||||||
|
// set valid log flag
|
||||||
|
$log->setLogFlag(Flag::per_run);
|
||||||
|
$this->assertTrue(
|
||||||
|
$log->getLogFlag(Flag::per_run)
|
||||||
|
);
|
||||||
|
// flags seum
|
||||||
|
$this->assertEquals(
|
||||||
|
Flag::per_run->value,
|
||||||
|
$log->getLogFlags(),
|
||||||
|
);
|
||||||
|
// unset valid log flag
|
||||||
|
$log->unsetLogFlag(Flag::per_run);
|
||||||
|
$this->assertFalse(
|
||||||
|
$log->getLogFlag(Flag::per_run)
|
||||||
|
);
|
||||||
|
// illegal Flags cannot be set, they will throw eerros onrun
|
||||||
|
|
||||||
|
// test multi set and sum is equals set
|
||||||
|
$log->setLogFlag(Flag::per_date);
|
||||||
|
$log->setLogFlag(Flag::per_group);
|
||||||
|
$this->assertEquals(
|
||||||
|
Flag::per_date->value + Flag::per_group->value,
|
||||||
|
$log->getLogFlags()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setLogFolder
|
||||||
|
// getLogFolder
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setLogFolder
|
||||||
|
* @covers ::getLogFolder
|
||||||
|
* @testdox setLogFolder set/get checks, init check
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSetLogFolder(): void
|
||||||
|
{
|
||||||
|
// set to good folder
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testSetLogFolder',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
self::LOG_FOLDER,
|
||||||
|
$log->getLogFolder()
|
||||||
|
);
|
||||||
|
// set to a good other folder
|
||||||
|
$log->setLogFolder(DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR);
|
||||||
|
$this->assertEquals(
|
||||||
|
DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||||
|
$log->getLogFolder()
|
||||||
|
);
|
||||||
|
// good other folder with missing trailing slash
|
||||||
|
$log->setLogFolder(DIRECTORY_SEPARATOR . 'tmp');
|
||||||
|
$this->assertEquals(
|
||||||
|
DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||||
|
$log->getLogFolder()
|
||||||
|
);
|
||||||
|
// a bad folder -> last good folder
|
||||||
|
$log->setLogFolder('I-am-not existing');
|
||||||
|
$this->assertEquals(
|
||||||
|
DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||||
|
$log->getLogFolder()
|
||||||
|
);
|
||||||
|
// init with a bad folder
|
||||||
|
$this->expectException(\Psr\Log\InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage('Folder: "I-am-bad" is not writeable for logging');
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testSetLogFolderInvalid',
|
||||||
|
'log_folder' => 'I-am-bad',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// getLogFile (no set, only correct after log run)
|
||||||
|
|
||||||
|
// setLogMaxFileSize
|
||||||
|
// getLogMaxFileSize
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setLogMaxFileSize
|
||||||
|
* @covers ::getLogMaxFileSize
|
||||||
|
* @testdox setLogMaxFileSize set/get checks, init check
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSetLogMaxFileSize(): void
|
||||||
|
{
|
||||||
|
// init set to 0
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testSetLogMaxFileSize',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
0,
|
||||||
|
$log->getLogMaxFileSize()
|
||||||
|
);
|
||||||
|
// set to new, valid size
|
||||||
|
$file_size = 200 * 1024;
|
||||||
|
$valid = $log->setLogMaxFileSize($file_size);
|
||||||
|
$this->assertTrue($valid);
|
||||||
|
$this->assertEquals(
|
||||||
|
$file_size,
|
||||||
|
$log->getLogMaxFileSize()
|
||||||
|
);
|
||||||
|
// invalid size, < 0, will be last and return false
|
||||||
|
$valid = $log->setLogMaxFileSize(-1);
|
||||||
|
$this->assertFalse($valid);
|
||||||
|
$this->assertEquals(
|
||||||
|
$file_size,
|
||||||
|
$log->getLogMaxFileSize()
|
||||||
|
);
|
||||||
|
// too small (< MIN_LOG_MAX_FILESIZE)
|
||||||
|
$valid = $log->setLogMaxFileSize($log::MIN_LOG_MAX_FILESIZE - 1);
|
||||||
|
$this->assertFalse($valid);
|
||||||
|
$this->assertEquals(
|
||||||
|
$file_size,
|
||||||
|
$log->getLogMaxFileSize()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// getOption (option params)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::getOption
|
||||||
|
* @testdox getOption checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetOption(): void
|
||||||
|
{
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testGetOption',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
self::LOG_FOLDER,
|
||||||
|
$log->getOption('log_folder')
|
||||||
|
);
|
||||||
|
// not found
|
||||||
|
$this->assertNull(
|
||||||
|
$log->getOption('I_do not exist')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test all logger functions
|
||||||
|
// debug (special)
|
||||||
|
// info
|
||||||
|
// notice
|
||||||
|
// warning
|
||||||
|
// error
|
||||||
|
// critical
|
||||||
|
// alert
|
||||||
|
// emergency
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::debug
|
||||||
|
* @testdox debug checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testDebug(): void
|
||||||
|
{
|
||||||
|
// init logger
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testDebug',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
]);
|
||||||
|
// clean all data in folder first
|
||||||
|
array_map('unlink', glob($log->getLogFolder() . $log->getLogFileId() . '*.log'));
|
||||||
|
|
||||||
|
$group_id = 'G';
|
||||||
|
$message = 'D';
|
||||||
|
$log_status = $log->debug($group_id, $message);
|
||||||
|
$this->assertTrue($log_status, 'debug write successful');
|
||||||
|
$file_content = file_get_contents(
|
||||||
|
$log->getLogFolder() . $log->getLogFile()
|
||||||
|
) ?: '';
|
||||||
|
$log_level = $log->getLoggingLevel()->getName();
|
||||||
|
// [2023-05-30 15:51:39.36128800] [NOHOST:0]
|
||||||
|
// [www/vendor/bin/phpunit] [7b9d0747] {PHPUnit\TextUI\Command}
|
||||||
|
// <DEBUG:G> D
|
||||||
|
$this->assertMatchesRegularExpression(
|
||||||
|
"/" . self::REGEX_BASE
|
||||||
|
. "<$log_level:$group_id>\s{1}" // log level / group id
|
||||||
|
. "$message" // message
|
||||||
|
. "/",
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerLoggingLevelWrite(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'info' => [
|
||||||
|
'message' => 'I',
|
||||||
|
'file_id' => Level::Info->name,
|
||||||
|
'level' => Level::Info
|
||||||
|
],
|
||||||
|
'notice' => [
|
||||||
|
'message' => 'N',
|
||||||
|
'file_id' => Level::Notice->name,
|
||||||
|
'level' => Level::Notice
|
||||||
|
],
|
||||||
|
'warning' => [
|
||||||
|
'message' => 'W',
|
||||||
|
'file_id' => Level::Warning->name,
|
||||||
|
'level' => Level::Warning
|
||||||
|
],
|
||||||
|
'error' => [
|
||||||
|
'message' => 'E',
|
||||||
|
'file_id' => Level::Error->name,
|
||||||
|
'level' => Level::Error
|
||||||
|
],
|
||||||
|
'crticial' => [
|
||||||
|
'message' => 'C',
|
||||||
|
'file_id' => Level::Critical->name,
|
||||||
|
'level' => Level::Critical
|
||||||
|
],
|
||||||
|
'alert' => [
|
||||||
|
'message' => 'A',
|
||||||
|
'file_id' => Level::Alert->name,
|
||||||
|
'level' => Level::Alert
|
||||||
|
],
|
||||||
|
'emergency' => [
|
||||||
|
'message' => 'Em',
|
||||||
|
'file_id' => Level::Emergency->name,
|
||||||
|
'level' => Level::Emergency
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::info
|
||||||
|
* @covers ::notice
|
||||||
|
* @covers ::warning
|
||||||
|
* @covers ::error
|
||||||
|
* @covers ::critical
|
||||||
|
* @covers ::alert
|
||||||
|
* @covers ::emergency
|
||||||
|
* @dataProvider providerLoggingLevelWrite
|
||||||
|
* @testdox logging level write checks for $level [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testLoggingLevelWrite(string $message, string $file_id, Level $level): void
|
||||||
|
{
|
||||||
|
// init logger
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'test' . $file_id,
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_level' => $level,
|
||||||
|
]);
|
||||||
|
// clean all data in folder first
|
||||||
|
array_map('unlink', glob($log->getLogFolder() . $log->getLogFileId() . '*.log'));
|
||||||
|
|
||||||
|
switch ($level->value) {
|
||||||
|
case 200:
|
||||||
|
$log_status = $log->info($message);
|
||||||
|
break;
|
||||||
|
case 250:
|
||||||
|
$log_status = $log->notice($message);
|
||||||
|
break;
|
||||||
|
case 300:
|
||||||
|
$log_status = $log->warning($message);
|
||||||
|
break;
|
||||||
|
case 400:
|
||||||
|
$log_status = $log->error($message);
|
||||||
|
break;
|
||||||
|
case 500:
|
||||||
|
$log_status = $log->critical($message);
|
||||||
|
break;
|
||||||
|
case 550:
|
||||||
|
$log_status = $log->alert($message);
|
||||||
|
break;
|
||||||
|
case 600:
|
||||||
|
$log_status = $log->emergency($message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$this->assertTrue($log_status, 'log write successful');
|
||||||
|
$file_content = file_get_contents(
|
||||||
|
$log->getLogFolder() . $log->getLogFile()
|
||||||
|
) ?: '';
|
||||||
|
$log_level = $log->getLoggingLevel()->getName();
|
||||||
|
$this->assertMatchesRegularExpression(
|
||||||
|
"/" . self::REGEX_BASE
|
||||||
|
. "<$log_level>\s{1}" // log level / group id
|
||||||
|
. "$message" // message
|
||||||
|
. "/",
|
||||||
|
$file_content,
|
||||||
|
'log message regex'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check log level that writer writes in correct level
|
||||||
|
// also that non debug ignores prefix/group
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::log
|
||||||
|
* @testdox log() general call test
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testLoggingLog(): void
|
||||||
|
{
|
||||||
|
// init logger
|
||||||
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
|
'log_file_id' => 'testLoggingLog',
|
||||||
|
'log_folder' => self::LOG_FOLDER,
|
||||||
|
'log_per_level' => true,
|
||||||
|
]);
|
||||||
|
$log_ok = $log->log(Level::Debug, 'DEBUG', group_id: 'GROUP_ID', prefix: 'PREFIX:');
|
||||||
|
$this->assertTrue($log_ok, 'assert ::log (debug) OK');
|
||||||
|
$this->assertEquals(
|
||||||
|
$log->getLogFile(),
|
||||||
|
$log->getLogFileId() . '_DEBUG.log'
|
||||||
|
);
|
||||||
|
$log_ok = $log->log(Level::Info, 'INFO', group_id: 'GROUP_ID', prefix: 'PREFIX:');
|
||||||
|
$this->assertTrue($log_ok, 'assert ::log (info) OK');
|
||||||
|
$this->assertEquals(
|
||||||
|
$log->getLogFile(),
|
||||||
|
$log->getLogFileId() . '_INFO.log'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// must test flow:
|
||||||
|
// init normal
|
||||||
|
// log -> check file name
|
||||||
|
// set per date
|
||||||
|
// log -> check file name
|
||||||
|
// and same for per_run
|
||||||
|
|
||||||
|
// deprecated calls check?
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
3
4dev/tests/Logging/log/.gitignore
vendored
Normal file
3
4dev/tests/Logging/log/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*log
|
||||||
|
*LOG
|
||||||
|
!.gitignore
|
||||||
@@ -22,7 +22,7 @@ final class CoreLibsOutputFormElementsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testOutputFormElements()
|
public function testOutputFormElements()
|
||||||
{
|
{
|
||||||
$this->assertTrue(true, 'Output Form Elements Tests not implemented');
|
// $this->assertTrue(true, 'Output Form Elements Tests not implemented');
|
||||||
$this->markTestIncomplete(
|
$this->markTestIncomplete(
|
||||||
'Output\Form\Elements Tests have not yet been implemented'
|
'Output\Form\Elements Tests have not yet been implemented'
|
||||||
);
|
);
|
||||||
@@ -22,7 +22,7 @@ final class CoreLibsOutputFormTokenTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testOutputFormToken()
|
public function testOutputFormToken()
|
||||||
{
|
{
|
||||||
$this->assertTrue(true, 'Output Form Token Tests not implemented');
|
// $this->assertTrue(true, 'Output Form Token Tests not implemented');
|
||||||
$this->markTestIncomplete(
|
$this->markTestIncomplete(
|
||||||
'Output\Form\Token Tests have not yet been implemented'
|
'Output\Form\Token Tests have not yet been implemented'
|
||||||
);
|
);
|
||||||
105
4dev/tests/Output/CoreLibsOutputImageTest.php
Normal file
105
4dev/tests/Output/CoreLibsOutputImageTest.php
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Output\Image
|
||||||
|
* @coversDefaultClass \CoreLibs\Output\Image
|
||||||
|
* @testdox \CoreLibs\Output\Image method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsOutputImageTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::createThumbnail
|
||||||
|
* @testdox createThumbnail checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCreateThumbnail(): void
|
||||||
|
{
|
||||||
|
// CONVERT does not exist
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
|
\CoreLibs\Output\Image::createThumbnail('do_not_exist.png', 200, 200);
|
||||||
|
// set convert
|
||||||
|
$paths = [
|
||||||
|
'/bin',
|
||||||
|
'/usr/bin',
|
||||||
|
'/usr/local/bin',
|
||||||
|
];
|
||||||
|
// find convert
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
if (
|
||||||
|
file_exists($path . DIRECTORY_SEPARATOR . 'convert') &&
|
||||||
|
is_file($path . DIRECTORY_SEPARATOR . 'convert')
|
||||||
|
) {
|
||||||
|
// image magick convert location
|
||||||
|
define('CONVERT', $path . DIRECTORY_SEPARATOR . 'convert');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($paths);
|
||||||
|
// cannot set dummy file
|
||||||
|
$this->expectException(\Exception::class);
|
||||||
|
\CoreLibs\Output\Image::createThumbnail('do_not_exist.png', 200, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::createThumbnailSimple
|
||||||
|
* @testdox createThumbnailSimple checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCreateThumbnailSimple(): void
|
||||||
|
{
|
||||||
|
// file does not exist
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
\CoreLibs\Output\Image::createThumbnailSimple(
|
||||||
|
'do_not_exist.png',
|
||||||
|
200,
|
||||||
|
200,
|
||||||
|
cache_folder: '/tmp/',
|
||||||
|
web_folder: '/tmp/'
|
||||||
|
);
|
||||||
|
// cache folder is not dir
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
\CoreLibs\Output\Image::createThumbnailSimple(
|
||||||
|
'do_not_exist.png',
|
||||||
|
200,
|
||||||
|
200,
|
||||||
|
cache_folder: '/foo/bar/',
|
||||||
|
web_folder: '/tmp/'
|
||||||
|
);
|
||||||
|
// target cache folder is not writeable
|
||||||
|
|
||||||
|
// RuntimeException: imagecreatetruecolor failed
|
||||||
|
// RuntimeException: imagecolorallocatealpha failed
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::correctImageOrientation
|
||||||
|
* @testdox correctImageOrientation checks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCorrectImageOrientation(): void
|
||||||
|
{
|
||||||
|
// test file does not exist
|
||||||
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
\CoreLibs\Output\Image::correctImageOrientation('do_not_exist.png');
|
||||||
|
// test folder not writeable
|
||||||
|
// test exit_read_data not present (how)?
|
||||||
|
// test image rotate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -22,10 +22,10 @@ final class CoreLibsOutputProgressbarTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testOutputProgressbar()
|
public function testOutputProgressbar()
|
||||||
{
|
{
|
||||||
/* $this->assertTrue(true, 'Output Progressbar Tests not implemented');
|
// $this->assertTrue(true, 'Output Progressbar Tests not implemented');
|
||||||
$this->markTestIncomplete(
|
// $this->markTestIncomplete(
|
||||||
'Output\Progressbar Tests have not yet been implemented'
|
// 'Output\Progressbar Tests have not yet been implemented'
|
||||||
); */
|
// );
|
||||||
$this->markTestSkipped('No implementation for Output\Progressbar at the moment');
|
$this->markTestSkipped('No implementation for Output\Progressbar at the moment');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,11 +7,11 @@ namespace tests;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for Check\Password
|
* Test class for Security\Password
|
||||||
* @coversDefaultClass \CoreLibs\Check\Password
|
* @coversDefaultClass \CoreLibs\Security\Password
|
||||||
* @testdox \CoreLibs\Check\Password method tests
|
* @testdox \CoreLibs\Security\Password method tests
|
||||||
*/
|
*/
|
||||||
final class CoreLibsCheckPasswordTest extends TestCase
|
final class CoreLibsSecurityPasswordTest extends TestCase
|
||||||
{
|
{
|
||||||
public function passwordProvider(): array
|
public function passwordProvider(): array
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,7 @@ final class CoreLibsCheckPasswordTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Check\Password::passwordVerify($input, \CoreLibs\Check\Password::passwordSet($input_hash))
|
\CoreLibs\Security\Password::passwordVerify($input, \CoreLibs\Security\Password::passwordSet($input_hash))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ final class CoreLibsCheckPasswordTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Check\Password::passwordRehashCheck($input)
|
\CoreLibs\Security\Password::passwordRehashCheck($input)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
237
4dev/tests/Security/CoreLibsSecuritySymmetricEncryptionTest.php
Normal file
237
4dev/tests/Security/CoreLibsSecuritySymmetricEncryptionTest.php
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use CoreLibs\Security\CreateKey;
|
||||||
|
use CoreLibs\Security\SymmetricEncryption;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Security\SymmetricEncryption and Security\CreateKey
|
||||||
|
* @coversDefaultClass \CoreLibs\Security\SymmetricEncryption
|
||||||
|
* @testdox \CoreLibs\Security\SymmetricEncryption method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerEncryptDecryptSuccess(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'valid string' => [
|
||||||
|
'input' => 'I am a secret',
|
||||||
|
'expected' => 'I am a secret',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test encrypt/decrypt produce correct output
|
||||||
|
*
|
||||||
|
* @covers ::generateRandomKey
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerEncryptDecryptSuccess
|
||||||
|
* @testdox encrypt/decrypt $input must be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEncryptDecryptSuccess(string $input, string $expected): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
|
// test class
|
||||||
|
$crypt = new SymmetricEncryption($key);
|
||||||
|
$encrypted = $crypt->encrypt($input);
|
||||||
|
$decrypted = $crypt->decrypt($encrypted);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$decrypted,
|
||||||
|
'Class call',
|
||||||
|
);
|
||||||
|
|
||||||
|
// test indirect
|
||||||
|
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
||||||
|
$decrypted = SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$decrypted,
|
||||||
|
'Class Instance call',
|
||||||
|
);
|
||||||
|
|
||||||
|
// test static
|
||||||
|
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
||||||
|
$decrypted = SymmetricEncryption::decryptKey($encrypted, $key);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$decrypted,
|
||||||
|
'Static call',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerEncryptFailed(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'wrong decryption key' => [
|
||||||
|
'input' => 'I am a secret',
|
||||||
|
'excpetion_message' => 'Invalid Key'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test decryption with wrong key
|
||||||
|
*
|
||||||
|
* @covers ::generateRandomKey
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerEncryptFailed
|
||||||
|
* @testdox decrypt with wrong key $input throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEncryptFailed(string $input, string $exception_message): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
$wrong_key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
|
// wrong key in class call
|
||||||
|
$crypt = new SymmetricEncryption($key);
|
||||||
|
$encrypted = $crypt->encrypt($input);
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
$crypt->setKey($key);
|
||||||
|
$crypt->decrypt($encrypted);
|
||||||
|
|
||||||
|
// class instance
|
||||||
|
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::getInstance($wrong_key)->decrypt($encrypted);
|
||||||
|
|
||||||
|
// class static
|
||||||
|
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::decryptKey($encrypted, $wrong_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerWrongKey(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'not hex key' => [
|
||||||
|
'key' => 'not_a_hex_key',
|
||||||
|
'exception_message' => 'Invalid hex key'
|
||||||
|
],
|
||||||
|
'too short hex key' => [
|
||||||
|
'key' => '1cabd5cba9e042f12522f4ff2de5c31d233b',
|
||||||
|
'excpetion_message' => 'Key is not the correct size (must be '
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test invalid key provided to decrypt or encrypt
|
||||||
|
*
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerWrongKey
|
||||||
|
* @testdox wrong key $key throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testWrongKey(string $key, string $exception_message): void
|
||||||
|
{
|
||||||
|
$enc_key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
|
// class
|
||||||
|
$crypt = new SymmetricEncryption($key);
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
$crypt->encrypt('test');
|
||||||
|
$crypt->setKey($enc_key);
|
||||||
|
$encrypted = $crypt->encrypt('test');
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
$crypt->setKey($key);
|
||||||
|
$crypt->decrypt($encrypted);
|
||||||
|
|
||||||
|
// class instance
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::getInstance($key)->encrypt('test');
|
||||||
|
// we must encrypt valid thing first so we can fail with the wrong key
|
||||||
|
$encrypted = SymmetricEncryption::getInstance($enc_key)->encrypt('test');
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||||
|
|
||||||
|
// class static
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::encryptKey('test', $key);
|
||||||
|
// we must encrypt valid thing first so we can fail with the wrong key
|
||||||
|
$encrypted = SymmetricEncryption::encryptKey('test', $enc_key);
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::decryptKey($encrypted, $key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerWrongCiphertext(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'too short ciphertext' => [
|
||||||
|
'input' => 'short',
|
||||||
|
'exception_message' => 'Decipher message failed: '
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerWrongCiphertext
|
||||||
|
* @testdox too short ciphertext $input throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testWrongCiphertext(string $input, string $exception_message): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
// class
|
||||||
|
$crypt = new SymmetricEncryption($key);
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
$crypt->decrypt($input);
|
||||||
|
|
||||||
|
// class instance
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::getInstance($key)->decrypt($input);
|
||||||
|
|
||||||
|
// class static
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::decryptKey($input, $key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
34
4dev/tests/Template/CoreLibsTemplateHtmlBuilderBlockTest.php
Normal file
34
4dev/tests/Template/CoreLibsTemplateHtmlBuilderBlockTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use CoreLibs\Template\HtmlBuilder\Block;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Template\HtmlBuilder\Block
|
||||||
|
* @coversDefaultClass \CoreLibs\Template\HtmlBuilder\Block
|
||||||
|
* @testdox \CoreLibs\Template\HtmlBuilder\Block method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsTemplateHtmlBuilderBlockTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreateBlock(): void
|
||||||
|
{
|
||||||
|
$el = Block::cel('div', 'id', 'content', ['css'], ['onclick' => 'foo();']);
|
||||||
|
$this->assertEquals(
|
||||||
|
'<div id="id" class="css" onclick="foo();">content</div>',
|
||||||
|
Block::buildHtml($el)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ael
|
||||||
|
// aelx|addSub
|
||||||
|
// resetSub
|
||||||
|
// acssel/rcssel/scssel
|
||||||
|
// buildHtml
|
||||||
|
// buildHtmlFromList|printHtmlFromArray
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
546
4dev/tests/Template/CoreLibsTemplateHtmlBuilderElementTest.php
Normal file
546
4dev/tests/Template/CoreLibsTemplateHtmlBuilderElementTest.php
Normal file
@@ -0,0 +1,546 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use CoreLibs\Template\HtmlBuilder\Element;
|
||||||
|
use CoreLibs\Template\HtmlBuilder\General\Error;
|
||||||
|
use CoreLibs\Template\HtmlBuilder\General\HtmlBuilderExcpetion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Template\HtmlBuilder\Element
|
||||||
|
* @coversDefaultClass \CoreLibs\Template\HtmlBuilder\Element
|
||||||
|
* @testdox \CoreLibs\Template\HtmlBuilder\Element method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsTemplateHtmlBuilderElementTest extends TestCase
|
||||||
|
{
|
||||||
|
public function providerCreateElements(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'simple div' => [
|
||||||
|
'tag' => 'div',
|
||||||
|
'id' => 'id',
|
||||||
|
'content' => 'content',
|
||||||
|
'css' => ['css'],
|
||||||
|
'options' => ['onclick' => 'foo();'],
|
||||||
|
'expected' => '<div id="id" class="css" onclick="foo();">content</div>'
|
||||||
|
],
|
||||||
|
'simple input' => [
|
||||||
|
'tag' => 'input',
|
||||||
|
'id' => 'id',
|
||||||
|
'content' => null,
|
||||||
|
'css' => ['css'],
|
||||||
|
'options' => ['name' => 'name', 'onclick' => 'foo();'],
|
||||||
|
'expected' => '<input id="id" name="name" class="css" onclick="foo();">'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::Element
|
||||||
|
* @covers ::buildHtml
|
||||||
|
* @covers ::getTag
|
||||||
|
* @covers ::getId
|
||||||
|
* @covers ::getContent
|
||||||
|
* @covers ::getOptions
|
||||||
|
* @covers ::getCss
|
||||||
|
* @dataProvider providerCreateElements
|
||||||
|
* @testdox create single new Element test [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $tag
|
||||||
|
* @param string|null $id
|
||||||
|
* @param string|null $content
|
||||||
|
* @param array|null $css
|
||||||
|
* @param array|null $options
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCreateElement(
|
||||||
|
string $tag,
|
||||||
|
?string $id,
|
||||||
|
?string $content,
|
||||||
|
?array $css,
|
||||||
|
?array $options,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
|
$el = new Element($tag, $id ?? '', $content ?? '', $css ?? [], $options ?? []);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$el->buildHtml(),
|
||||||
|
'element creation failed'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$tag,
|
||||||
|
$el->getTag(),
|
||||||
|
'get tag failed'
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($id !== null) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$id,
|
||||||
|
$el->getId(),
|
||||||
|
'get id failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($content !== null) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$content,
|
||||||
|
$el->getContent(),
|
||||||
|
'get content failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($css !== null) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$css,
|
||||||
|
$el->getCss(),
|
||||||
|
'get css failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($options !== null) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$options,
|
||||||
|
$el->getOptions(),
|
||||||
|
'get options failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!empty($options['name'])) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$options['name'],
|
||||||
|
$el->getName(),
|
||||||
|
'get name failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* css add/remove
|
||||||
|
*
|
||||||
|
* @cover ::getCss
|
||||||
|
* @cover ::addCss
|
||||||
|
* @cover ::removeCss
|
||||||
|
* @testdox test handling of adding and removing css classes
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCssHandling(): void
|
||||||
|
{
|
||||||
|
$el = new Element('div', 'css-test', 'CSS content');
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
[],
|
||||||
|
$el->getCss(),
|
||||||
|
'check empty css'
|
||||||
|
);
|
||||||
|
$el->addCss('foo');
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
['foo'],
|
||||||
|
$el->getCss(),
|
||||||
|
'check added one css'
|
||||||
|
);
|
||||||
|
$el->removeCss('foo');
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
[],
|
||||||
|
$el->getCss(),
|
||||||
|
'check remove added css'
|
||||||
|
);
|
||||||
|
// add serveral
|
||||||
|
// remove some of them
|
||||||
|
$el->addCss('a', 'b', 'c');
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
$el->getCss(),
|
||||||
|
'check added some css'
|
||||||
|
);
|
||||||
|
$el->removeCss('a', 'c');
|
||||||
|
// $this->assertArray
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
['b'],
|
||||||
|
$el->getCss(),
|
||||||
|
'check remove some css'
|
||||||
|
);
|
||||||
|
// chained add and remove
|
||||||
|
$el->addCss('a', 'b', 'c', 'd')->removeCss('b', 'd');
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
['a', 'c'],
|
||||||
|
$el->getCss(),
|
||||||
|
'check chain add remove some css'
|
||||||
|
);
|
||||||
|
$el->resetCss();
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
[],
|
||||||
|
$el->getCss(),
|
||||||
|
'check reset css'
|
||||||
|
);
|
||||||
|
// remove something that does not eixst
|
||||||
|
$el->addCss('exists');
|
||||||
|
$el->removeCss('not');
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
['exists'],
|
||||||
|
$el->getCss(),
|
||||||
|
'check remove not exitsing'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nested test
|
||||||
|
*
|
||||||
|
* @testdox nested test and loop assign detection
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testBuildNested(): void
|
||||||
|
{
|
||||||
|
Error::resetMessages();
|
||||||
|
$el = new Element('div', 'build-test');
|
||||||
|
$el_sub = new Element('div', 'sub-1');
|
||||||
|
$el->addSub($el_sub);
|
||||||
|
$this->assertEquals(
|
||||||
|
'<div id="build-test"><div id="sub-1"></div></div>',
|
||||||
|
$el->buildHtml(),
|
||||||
|
'nested build failed'
|
||||||
|
);
|
||||||
|
// this would create a loop, throws error
|
||||||
|
$this->expectException(HtmlBuilderExcpetion::class);
|
||||||
|
$this->expectExceptionMessage("Cannot assign Element to itself, this would create an infinite loop");
|
||||||
|
$el_sub->addSub($el_sub);
|
||||||
|
$this->assertEquals(
|
||||||
|
'<div id="sub-1"></div>',
|
||||||
|
$el_sub->buildHtml(),
|
||||||
|
'loop detection failed'
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
Error::hasError(),
|
||||||
|
'failed to throw error post loop detection'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[[
|
||||||
|
'level' => 'Error',
|
||||||
|
'id' => '100',
|
||||||
|
'message' => 'Cannot assign Element to itself, this would create an infinite loop',
|
||||||
|
'context' => ['tag' => 'div', 'id' => 'sub-1']
|
||||||
|
]],
|
||||||
|
Error::getMessages(),
|
||||||
|
'check error is 100 failed'
|
||||||
|
);
|
||||||
|
// get sub
|
||||||
|
$this->assertEquals(
|
||||||
|
[$el_sub],
|
||||||
|
$el->getSub(),
|
||||||
|
'get sub failed'
|
||||||
|
);
|
||||||
|
// reset sub
|
||||||
|
$el->resetSub();
|
||||||
|
$this->assertEquals(
|
||||||
|
[],
|
||||||
|
$el->getSub(),
|
||||||
|
'reset sub failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox updated nested connection
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testNestedChangeContent(): void
|
||||||
|
{
|
||||||
|
$el = new Element('div', 'build-test');
|
||||||
|
$el_s_1 = new Element('div', 'sub-1');
|
||||||
|
$el_s_2 = new Element('div', 'sub-2');
|
||||||
|
$el_s_3 = new Element('div', 'sub-3');
|
||||||
|
$el_s_4 = new Element('div', 'sub-4');
|
||||||
|
|
||||||
|
$el->addSub($el_s_1, $el_s_2);
|
||||||
|
// only sub -1, -2
|
||||||
|
$this->assertEquals(
|
||||||
|
'<div id="build-test"><div id="sub-1"></div><div id="sub-2"></div></div>',
|
||||||
|
$el->buildHtml(),
|
||||||
|
'check basic nested'
|
||||||
|
);
|
||||||
|
|
||||||
|
// now add -3, -4 to both -1 and -2
|
||||||
|
$el_s_1->addSub($el_s_3, $el_s_4);
|
||||||
|
$el_s_2->addSub($el_s_3, $el_s_4);
|
||||||
|
$this->assertEquals(
|
||||||
|
'<div id="build-test"><div id="sub-1"><div id="sub-3"></div><div id="sub-4">'
|
||||||
|
. '</div></div><div id="sub-2"><div id="sub-3"></div><div id="sub-4"></div>'
|
||||||
|
. '</div></div>',
|
||||||
|
$el->buildHtml(),
|
||||||
|
'check nested added'
|
||||||
|
);
|
||||||
|
|
||||||
|
// now add some css to el_s_3, will update in both sets
|
||||||
|
$el_s_3->addCss('red');
|
||||||
|
$this->assertEquals(
|
||||||
|
'<div id="build-test"><div id="sub-1"><div id="sub-3" class="red"></div><div id="sub-4">'
|
||||||
|
. '</div></div><div id="sub-2"><div id="sub-3" class="red"></div><div id="sub-4"></div>'
|
||||||
|
. '</div></div>',
|
||||||
|
$el->buildHtml(),
|
||||||
|
'check nested u@dated'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox test change tag/id/content
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testChangeElementData(): void
|
||||||
|
{
|
||||||
|
$el = new Element('div', 'id', 'Content');
|
||||||
|
// content change
|
||||||
|
$this->assertEquals(
|
||||||
|
'Content',
|
||||||
|
$el->getContent(),
|
||||||
|
'set content'
|
||||||
|
);
|
||||||
|
$el->setContent('New Content');
|
||||||
|
$this->assertEquals(
|
||||||
|
'New Content',
|
||||||
|
$el->getContent(),
|
||||||
|
'changed content'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'div',
|
||||||
|
$el->getTag(),
|
||||||
|
'set tag'
|
||||||
|
);
|
||||||
|
$el->setTag('span');
|
||||||
|
$this->assertEquals(
|
||||||
|
'span',
|
||||||
|
$el->getTag(),
|
||||||
|
'changed tag'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'id',
|
||||||
|
$el->getId(),
|
||||||
|
'set id'
|
||||||
|
);
|
||||||
|
$el->setId('id-2');
|
||||||
|
$this->assertEquals(
|
||||||
|
'id-2',
|
||||||
|
$el->getId(),
|
||||||
|
'changed id'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox test change options
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testChangeOptions(): void
|
||||||
|
{
|
||||||
|
$el = new Element('button', 'id', 'Action', ['css'], ['value' => '3']);
|
||||||
|
$this->assertEquals(
|
||||||
|
['value' => '3'],
|
||||||
|
$el->getOptions(),
|
||||||
|
'set option'
|
||||||
|
);
|
||||||
|
$el->setOptions([
|
||||||
|
'value' => '2'
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
['value' => '2'],
|
||||||
|
$el->getOptions(),
|
||||||
|
'changed option'
|
||||||
|
);
|
||||||
|
// add a new one
|
||||||
|
$el->setOptions([
|
||||||
|
'Foo' => 'bar',
|
||||||
|
'Moo' => 'cow'
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'value' => '2',
|
||||||
|
'Foo' => 'bar',
|
||||||
|
'Moo' => 'cow'
|
||||||
|
],
|
||||||
|
$el->getOptions(),
|
||||||
|
'changed option'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// build output
|
||||||
|
// build from array list
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox build element tree from object
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testBuildHtmlObject(): void
|
||||||
|
{
|
||||||
|
// build a simple block
|
||||||
|
// div -> div -> button
|
||||||
|
// -> div -> span
|
||||||
|
// -> div -> input
|
||||||
|
$el = new Element('div', 'master', '', ['master']);
|
||||||
|
$el->addSub(
|
||||||
|
Element::addElement(
|
||||||
|
new Element('div', 'div-button', '', ['dv-bt']),
|
||||||
|
new Element('button', 'button-id', 'Click me', ['bt-red'], [
|
||||||
|
'OnClick' => 'action();',
|
||||||
|
'value' => 'click',
|
||||||
|
'type' => 'button'
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
Element::addElement(
|
||||||
|
new Element('div', 'div-span', '', ['dv-sp']),
|
||||||
|
new Element('span', 'span-id', 'Big important message<br>other', ['red']),
|
||||||
|
),
|
||||||
|
Element::addElement(
|
||||||
|
new Element('div', 'div-input', '', ['dv-in']),
|
||||||
|
new Element('input', 'input-id', '', ['in-blue'], [
|
||||||
|
'OnClick' => 'otherAction();',
|
||||||
|
'value' => 'Touch',
|
||||||
|
'type' => 'button'
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'<div id="master" class="master">'
|
||||||
|
. '<div id="div-button" class="dv-bt">'
|
||||||
|
. '<button id="button-id" name="button-id" class="bt-red" OnClick="action();" '
|
||||||
|
. 'value="click" type="button">Click me</button>'
|
||||||
|
. '</div>'
|
||||||
|
. '<div id="div-span" class="dv-sp">'
|
||||||
|
. '<span id="span-id" class="red">Big important message<br>other</span>'
|
||||||
|
. '</div>'
|
||||||
|
. '<div id="div-input" class="dv-in">'
|
||||||
|
. '<input id="input-id" name="input-id" '
|
||||||
|
. 'class="in-blue" OnClick="otherAction();" value="Touch" type="button">'
|
||||||
|
. '</div>'
|
||||||
|
. '</div>',
|
||||||
|
$el->buildHtml()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox build elements from array list
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testbuildHtmlArray(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
'<div id="id-1">A</div>'
|
||||||
|
. '<div id="id-2">B</div>'
|
||||||
|
. '<div id="id-3">C</div>',
|
||||||
|
Element::buildHtmlFromList([
|
||||||
|
new Element('div', 'id-1', 'A'),
|
||||||
|
new Element('div', 'id-2', 'B'),
|
||||||
|
new Element('div', 'id-3', 'C'),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox check for invalid tag detection, possible invalid id, possible invalid css
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testInvalidElement(): void
|
||||||
|
{
|
||||||
|
Error::resetMessages();
|
||||||
|
$this->expectException(HtmlBuilderExcpetion::class);
|
||||||
|
$this->expectExceptionMessage("Could not create Element");
|
||||||
|
$el = new Element('');
|
||||||
|
$this->assertTrue(
|
||||||
|
Error::hasError(),
|
||||||
|
'failed to set error invalid tag detection'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[[
|
||||||
|
'level' => 'Error',
|
||||||
|
'id' => '201',
|
||||||
|
'message' => 'invalid or empty tag',
|
||||||
|
'context' => ['tag' => '']
|
||||||
|
]],
|
||||||
|
Error::getMessages(),
|
||||||
|
'check error message failed'
|
||||||
|
);
|
||||||
|
|
||||||
|
// if we set invalid tag
|
||||||
|
$el = new Element('div');
|
||||||
|
$this->expectException(HtmlBuilderExcpetion::class);
|
||||||
|
$this->expectExceptionMessageMatches("/^Invalid or empty tag: /");
|
||||||
|
$this->expectExceptionMessage("Invalid or empty tag: 123123");
|
||||||
|
$el->setTag('123123');
|
||||||
|
$this->assertTrue(
|
||||||
|
Error::hasError(),
|
||||||
|
'failed to set error invalid tag detection'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[[
|
||||||
|
'level' => 'Error',
|
||||||
|
'id' => '201',
|
||||||
|
'message' => 'invalid or empty tag',
|
||||||
|
'context' => ['tag' => '']
|
||||||
|
]],
|
||||||
|
Error::getMessages(),
|
||||||
|
'check error message failed'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// invalid id (warning)
|
||||||
|
Error::resetMessages();
|
||||||
|
$el = new Element('div', '-$a15');
|
||||||
|
$this->assertTrue(
|
||||||
|
Error::hasWarning(),
|
||||||
|
'failed to set warning invalid id detection'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[[
|
||||||
|
'level' => 'Warning',
|
||||||
|
'id' => '202',
|
||||||
|
'message' => 'possible invalid id',
|
||||||
|
'context' => ['id' => '-$a15', 'tag' => 'div']
|
||||||
|
]],
|
||||||
|
Error::getMessages(),
|
||||||
|
'check error message failed'
|
||||||
|
);
|
||||||
|
|
||||||
|
// invalid name
|
||||||
|
Error::resetMessages();
|
||||||
|
$el = new Element('div', 'valid', '', [], ['name' => '-$asdf&']);
|
||||||
|
$this->assertTrue(
|
||||||
|
Error::hasWarning(),
|
||||||
|
'failed to set warning invalid name detection'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[[
|
||||||
|
'level' => 'Warning',
|
||||||
|
'id' => '203',
|
||||||
|
'message' => 'possible invalid name',
|
||||||
|
'context' => ['name' => '-$asdf&', 'id' => 'valid', 'tag' => 'div']
|
||||||
|
]],
|
||||||
|
Error::getMessages(),
|
||||||
|
'check error message failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static add element
|
||||||
|
// print object/array
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use CoreLibs\Template\HtmlBuilder\StringReplace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Template\HtmlBuilder\StringReplace
|
||||||
|
* @coversDefaultClass \CoreLibs\Template\HtmlBuilder\StringReplace
|
||||||
|
* @testdox \CoreLibs\Template\HtmlBuilder\StringReplace method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsTemplateHtmlBuilderStringReplaceTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::replaceData
|
||||||
|
* @testdox test basic replaceData
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReplaceData(): void
|
||||||
|
{
|
||||||
|
$html_block = <<<HTML
|
||||||
|
<div id="{ID}" class="{CSS}">
|
||||||
|
{CONTENT}
|
||||||
|
</div>
|
||||||
|
HTML;
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
<<<HTML
|
||||||
|
<div id="block-id" class="blue,red">
|
||||||
|
Some content here<br>with bla bla inside
|
||||||
|
</div>
|
||||||
|
HTML,
|
||||||
|
StringReplace::replaceData(
|
||||||
|
$html_block,
|
||||||
|
[
|
||||||
|
'ID' => 'block-id',
|
||||||
|
'CSS' => join(',', ['blue', 'red']),
|
||||||
|
'{CONTENT}' => 'Some content here<br>with bla bla inside',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @testdox replaceData error
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
/* public function testReplaceDataErrors(): void
|
||||||
|
{
|
||||||
|
$this->expectException(HtmlBuilderExcpetion::class);
|
||||||
|
$this->expectExceptionMessage("Replace and content array count differ");
|
||||||
|
StringReplace::replaceData('<span>{FOO}</span>', ['{FOO}', '{BAR}'], ['foo']);
|
||||||
|
} */
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
1232
4dev/tests/UrlRequests/CoreLibsUrlRequestsCurlTest.php
Normal file
1232
4dev/tests/UrlRequests/CoreLibsUrlRequestsCurlTest.php
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user