Compare commits
455 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38b2ffe82a | ||
|
|
6e547abccb | ||
|
|
676af5e1a4 | ||
|
|
118aacee28 | ||
|
|
564e23ecd7 | ||
|
|
2889012592 | ||
|
|
cd65604073 | ||
|
|
a3cf5f45f9 | ||
|
|
6f3dacdec0 | ||
|
|
2ab1ee90ef | ||
|
|
b8c0aff975 | ||
|
|
c5fed66237 | ||
|
|
157169d3ba | ||
|
|
60fe0e0def | ||
|
|
e473e7899d | ||
|
|
8af71b70a3 | ||
|
|
7d10b4c5af | ||
|
|
c81b602657 | ||
|
|
59cc5f2060 | ||
|
|
e072aaf4d6 | ||
|
|
259f9cebf3 | ||
|
|
bd4f674f0f | ||
|
|
87293bf633 | ||
|
|
be46d6e101 | ||
|
|
433bc3d539 | ||
|
|
4ed645bac3 | ||
|
|
908376c1a5 | ||
|
|
c329e7a2da | ||
|
|
ad7b59e26a | ||
|
|
c43bb0662d | ||
|
|
c4e83f94e9 | ||
|
|
a292abc2c5 | ||
|
|
6c5af91386 | ||
|
|
73fc74a43a | ||
|
|
b89238b922 | ||
|
|
9115fc9557 | ||
|
|
62d9cda3d0 | ||
|
|
dbc72472f9 | ||
|
|
3be3519e45 | ||
|
|
4707427ff4 | ||
|
|
73ac0b68b6 | ||
|
|
a501fa25de | ||
|
|
d4db235e5b | ||
|
|
c70cdf457f | ||
|
|
57aae073d7 | ||
|
|
4bebec2b47 | ||
|
|
991750aa5f | ||
| 426afdc1ff | |||
| ffff65a76d | |||
|
|
c22e68f19a | ||
|
|
074d5bed4c | ||
|
|
93cb7e0cab | ||
|
|
7fbce6529b | ||
|
|
6e086fe7b3 | ||
|
|
0ec19d5b75 | ||
|
|
8134da349f | ||
|
|
8396f7856b | ||
|
|
b18866077e | ||
|
|
a66cc09095 | ||
|
|
1cfdc45107 | ||
|
|
07e46c91ab | ||
|
|
8aee448c59 | ||
|
|
37367db878 | ||
|
|
2d30d1d160 | ||
|
|
531229e8b7 | ||
|
|
d09c20ff9d | ||
|
|
f4ddc5a5fc | ||
|
|
1791ec3908 | ||
|
|
3d13f55c35 | ||
|
|
cf1989819a | ||
|
|
b302fb4053 | ||
|
|
32decdd037 | ||
|
|
46cda40d37 | ||
|
|
e71df90144 | ||
|
|
bbcc642fde | ||
|
|
558694aa6c | ||
|
|
f3bd09529a | ||
|
|
816bb7c9ee | ||
|
|
fc7b705355 | ||
|
|
7b96c1f9ca | ||
|
|
26c6ebcea7 | ||
|
|
32dee1692e | ||
|
|
6291ed88c0 | ||
|
|
5e21ead6fa | ||
|
|
07fbd13213 | ||
|
|
44b825310a | ||
|
|
2c234ccef6 | ||
|
|
b493b3c4fd | ||
|
|
e7dd96b5d9 | ||
|
|
bcde36ac17 | ||
|
|
8bde34ec7d | ||
|
|
a345d71306 | ||
|
|
0ff6294faa | ||
|
|
757d7ae01d | ||
|
|
4e78b21c67 | ||
|
|
d7e6434808 | ||
|
|
443cc2751d | ||
|
|
cf6500b55a | ||
|
|
09c2ec653f | ||
|
|
fc105f9295 | ||
|
|
053ab69330 | ||
|
|
fd079316f5 | ||
|
|
08664e9834 | ||
|
|
e063162161 | ||
|
|
7fbc449a5c | ||
|
|
72912c8c90 | ||
|
|
de2ed8be3d | ||
|
|
9d65f5d7c1 | ||
|
|
fbe827e989 | ||
|
|
c778a4eb81 | ||
|
|
ce1c72a0bc | ||
|
|
10319ef728 | ||
|
|
8d0036eaac | ||
|
|
d1e65c702e | ||
|
|
7248906da7 | ||
|
|
7f9a4dc04f | ||
|
|
10935214eb | ||
|
|
41e116f7d4 | ||
|
|
881c93c343 | ||
|
|
185d044a0b | ||
|
|
cc067cc202 | ||
|
|
37e2e54b2a | ||
|
|
711b3bfe97 | ||
|
|
3bd21c75d8 | ||
|
|
4971f62490 | ||
|
|
1cf4fdf31a | ||
|
|
d16b920966 | ||
|
|
ab52bf59b5 | ||
|
|
a8dd076aac | ||
|
|
c17ca1f847 | ||
|
|
e349613d60 | ||
|
|
e9cfdb4bf0 | ||
|
|
f966209e0a | ||
|
|
c13934de99 | ||
|
|
1e90bb677e | ||
|
|
540269e61f | ||
|
|
e793c3975b | ||
|
|
7d4c9724fe | ||
|
|
d1c4611431 | ||
|
|
8d3882a6fe | ||
|
|
2b0434e36b | ||
|
|
ba11a936db | ||
|
|
df591659cb | ||
|
|
5343034768 | ||
|
|
dec56c9559 | ||
|
|
880f15ac6f | ||
|
|
a46601fe03 | ||
|
|
022c39e791 | ||
|
|
fdefaca301 | ||
|
|
46e44c19bf | ||
|
|
41cb6358f9 | ||
|
|
23142a4549 | ||
|
|
a7742bd5c8 | ||
|
|
50f83b822c | ||
|
|
78591d6ba4 | ||
|
|
e8299a123b | ||
|
|
10c320f60c | ||
|
|
eeca138192 | ||
|
|
65715ea9c3 | ||
|
|
a56cbd8e97 | ||
|
|
fe50a988a0 | ||
|
|
a84ab86e31 | ||
|
|
b044999772 | ||
|
|
98bf3a40cd | ||
|
|
cbd47fb015 | ||
|
|
5f89917abd | ||
|
|
eeaff3042e | ||
|
|
d070c4e461 | ||
|
|
e57c336dba | ||
|
|
075fe967d5 | ||
|
|
0e5f637052 | ||
|
|
2e1b767a85 | ||
|
|
f78c67c378 | ||
|
|
75e69932fc | ||
|
|
7354632479 | ||
|
|
5a21d22c7b | ||
|
|
cee3b5c2d1 | ||
|
|
47e44c15cc | ||
|
|
83738adcb6 | ||
|
|
5454133239 | ||
|
|
87f35f23c3 | ||
|
|
3c4c5d3106 | ||
|
|
b080727ff3 | ||
|
|
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 | ||
|
|
545279b9fe | ||
|
|
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 |
10
.gitignore
vendored
10
.gitignore
vendored
@@ -0,0 +1,10 @@
|
||||
.libs
|
||||
node_modules/
|
||||
composer.lock
|
||||
vendor/
|
||||
tools/
|
||||
www/composer.lock
|
||||
www/vendor
|
||||
**/.env
|
||||
**/.target
|
||||
package-lock.json
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
use Phan\Config;
|
||||
|
||||
return [
|
||||
// "target_php_version" => "8.2",
|
||||
// "target_php_version" => "8.3",
|
||||
"minimum_target_php_version" => "8.3",
|
||||
// turn color on (-C)
|
||||
"color_issue_messages_if_supported" => true,
|
||||
// If true, missing properties will be created when
|
||||
@@ -95,8 +96,6 @@ return [
|
||||
"exclude_analysis_directory_list" => [
|
||||
'www/vendor',
|
||||
'www/tests',
|
||||
'www/lib/Smarty',
|
||||
'www/lib/smarty-4.3.0',
|
||||
'www/templates_c',
|
||||
'www/log',
|
||||
'www/tmp',
|
||||
@@ -117,10 +116,6 @@ return [
|
||||
// ignore the old qq tests
|
||||
'www/admin/qq_file_upload_front.php',
|
||||
'www/admin/qq_file_upload_ajax.php',
|
||||
// symlink ignore
|
||||
'www/lib/smarty-4.3.0/libs/Smarty.class.php',
|
||||
// legacy edit base (until removal)
|
||||
'www/includes/edit_base.LEGACY.php'
|
||||
],
|
||||
|
||||
// what not to show as problem
|
||||
@@ -133,7 +128,12 @@ return [
|
||||
'PhanWriteOnlyPublicProperty',
|
||||
'PhanUnreferencedConstant',
|
||||
'PhanWriteOnlyPublicProperty',
|
||||
'PhanReadOnlyPublicProperty'
|
||||
'PhanReadOnlyPublicProperty',
|
||||
// start ignore annotations
|
||||
'PhanUnextractableAnnotationElementName',
|
||||
'PhanUnextractableAnnotationSuffix',
|
||||
// enum problems in comments
|
||||
'PhanCommentObjectInClassConstantType'
|
||||
],
|
||||
|
||||
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
|
||||
|
||||
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.31" location="./tools/phpunit" copy="false"/>
|
||||
<phar name="phpcbf" version="4" installed="4.0.1" location="./tools/phpcbf" copy="false"/>
|
||||
<phar name="phpcs" version="4" installed="4.0.1" location="./tools/phpcs" copy="false"/>
|
||||
<phar name="phpstan" version="^2.0" installed="2.1.33" location="./tools/phpstan" copy="false"/>
|
||||
<phar name="phan" version="^5.4.3" installed="5.5.2" location="./tools/phan" copy="false"/>
|
||||
<phar name="psalm" version="^5.26.1" installed="5.26.1" 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.9.1" location="./tools/phpDocumentor" copy="false"/>
|
||||
<phar name="php-cs-fixer" version="^3.34.1" installed="3.92.4" 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,19 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||
# Assume script is in 4dev/bin
|
||||
base_folder="${BASE_FOLDER}../../www/";
|
||||
|
||||
# locale gettext po to mo translator master
|
||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
||||
file=$(basename $file .po);
|
||||
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}../4dev/locale/${locale}-${domain}.po;
|
||||
msgfmt -o "${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo" "${base_folder}../4dev/locale/${locale}-${domain}.po";
|
||||
done;
|
||||
|
||||
# __END__
|
||||
|
||||
@@ -2,16 +2,18 @@
|
||||
|
||||
# read source mo files and writes target js files in object form
|
||||
|
||||
# check for ARG 1 is "mv"
|
||||
# then move the files directly and don't do manual check (don't create temp files)
|
||||
FILE_MOVE=0;
|
||||
if [ "${1}" = "mv" ]; then
|
||||
# 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 ***";
|
||||
FILE_MOVE=1;
|
||||
fi;
|
||||
|
||||
target='';
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||
# Assume script is in 4dev/bin
|
||||
base_folder="${BASE_FOLDER}../../www/";
|
||||
po_folder='../4dev/locale/'
|
||||
@@ -26,9 +28,9 @@ if [ "${target}" == '' ]; then
|
||||
echo "*** Non smarty ***";
|
||||
TEXTDOMAINDIR=${base_folder}${mo_folder}.
|
||||
# default is admin
|
||||
TEXTDOMAIN=admin;
|
||||
TEXTDOMAIN="admin";
|
||||
fi;
|
||||
js_folder="layout/${TEXTDOMAIN}/javascript/";
|
||||
js_folder="${TEXTDOMAIN}/layout/javascript/";
|
||||
|
||||
error=0;
|
||||
# this checks if the TEXTDOMAIN target actually exists
|
||||
@@ -44,15 +46,16 @@ if [ ${error} -eq 1 ]; then
|
||||
fi;
|
||||
|
||||
# locale gettext po to mo translator master
|
||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
||||
file=$(basename $file .po);
|
||||
echo "Translate language ${file}";
|
||||
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;
|
||||
msgfmt -o "${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo" "${base_folder}${po_folder}${locale}-${domain}.po";
|
||||
done;
|
||||
|
||||
rx_msgid_empty="^msgid \"\"";
|
||||
@@ -62,7 +65,7 @@ rx_msgstr="^msgstr \""
|
||||
# quick copy string at the end
|
||||
quick_copy='';
|
||||
|
||||
for language in ${language_list[*]}; do
|
||||
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)
|
||||
@@ -79,7 +82,8 @@ for language in ${language_list[*]}; do
|
||||
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=$(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
|
||||
@@ -88,16 +92,18 @@ for language in ${language_list[*]}; do
|
||||
echo "===> Write translation file ${file}";
|
||||
echo ". = normal, : = escape, x = skip";
|
||||
# init line [aka don't touch this file]
|
||||
echo "// AUTO FILL, changes will be overwritten" > $file;
|
||||
echo "// source: ${suffix}, language: ${language}" >> $file;
|
||||
echo "// Translation strings in the format" >> $file;
|
||||
echo "// \"Original\":\"Translated\""$'\n' >> $file;
|
||||
echo "var i18n = {" >> $file;
|
||||
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 str; do
|
||||
while read -r str; do
|
||||
# echo "S: ${str}";
|
||||
# skip empty
|
||||
if [[ "${str}" =~ ${rx_msgid_empty} ]]; then
|
||||
@@ -112,12 +118,13 @@ for language in ${language_list[*]}; do
|
||||
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;
|
||||
echo -n "," >> "$file";
|
||||
fi;
|
||||
# all " inside string need to be escaped
|
||||
str_source=$(echo "${str_source}" | sed -e 's/"/\\"/g');
|
||||
# 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;
|
||||
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)
|
||||
@@ -128,8 +135,8 @@ for language in ${language_list[*]}; do
|
||||
fi;
|
||||
done;
|
||||
|
||||
echo "" >> $file;
|
||||
echo "};" >> $file;
|
||||
echo "" >> "$file";
|
||||
echo "};" >> "$file";
|
||||
echo " [DONE]";
|
||||
|
||||
# on no move
|
||||
@@ -140,19 +147,19 @@ for language in ${language_list[*]}; do
|
||||
fi;
|
||||
|
||||
# symlink to master file
|
||||
for suffix in ${source_list[*]}; do
|
||||
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
|
||||
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}";
|
||||
cd "${target_folder}" || exit;
|
||||
ln -sf "${original_file}" "${template_file}";
|
||||
cd - >/dev/null;
|
||||
cd - >/dev/null || exit;
|
||||
fi;
|
||||
done;
|
||||
done;
|
||||
|
||||
@@ -1,3 +1,100 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# must be run in ${base}www/
|
||||
phan --progress-bar -C --analyze-twice
|
||||
#!/bin/env bash
|
||||
|
||||
function error() {
|
||||
if [ -t 1 ]; then echo "[MAK] ERROR: $*" >&2; fi; exit 0;
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "${BASH_SOURCE[0]}") [-h | --help] [-p | --php VERSION] [-c | --composer]
|
||||
|
||||
Runs phan static analyzer.
|
||||
|
||||
If -p is not set, the default intalled PHP is used.
|
||||
|
||||
Available options:
|
||||
|
||||
-h, --help Print this help and exit
|
||||
-p, --php VERSION Chose PHP version in the form of "N.N", if not found will exit
|
||||
-c, --composer Use composer version and not the default phives bundle
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
BASE_PATH=$(pwd)"/";
|
||||
PHP_BIN_PATH=$(which php);
|
||||
if [ -z "${PHP_BIN_PATH}" ]; then
|
||||
echo "Cannot find php binary";
|
||||
exit;
|
||||
fi;
|
||||
DEFAULT_PHP_VERSION=$(${PHP_BIN_PATH} -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;");
|
||||
if [ -z "${DEFAULT_PHP_VERSION}" ]; then
|
||||
echo "Cannot set default PHP version";
|
||||
exit;
|
||||
fi;
|
||||
php_version="";
|
||||
no_php_version=0;
|
||||
use_composer=0;
|
||||
while [ -n "${1-}" ]; do
|
||||
case "${1}" in
|
||||
-p | --php)
|
||||
php_version="${2-}";
|
||||
shift
|
||||
;;
|
||||
-c | --composer)
|
||||
use_composer=1;
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
;;
|
||||
# invalid option
|
||||
-?*)
|
||||
error "[!] Unknown option: '$1'."
|
||||
;;
|
||||
esac
|
||||
shift;
|
||||
done;
|
||||
if [ -z "${php_version}" ]; then
|
||||
php_version="${DEFAULT_PHP_VERSION}";
|
||||
no_php_version=1;
|
||||
fi;
|
||||
php_bin="${PHP_BIN_PATH}${php_version}";
|
||||
echo "Use PHP Version: ${php_version}";
|
||||
if [ "${use_composer}" -eq 1 ]; then
|
||||
echo "Use composer installed";
|
||||
else
|
||||
echo "Use phive installed";
|
||||
fi;
|
||||
|
||||
if [ ! -f "${php_bin}" ]; then
|
||||
echo "Set php ${php_bin} does not exist";
|
||||
exit;
|
||||
fi;
|
||||
|
||||
# must be run in ${base}
|
||||
cd "$BASE_PATH" || exit;
|
||||
export PHAN_DISABLE_XDEBUG_WARN=1;
|
||||
PHAN_CALL=(
|
||||
"${php_bin}"
|
||||
);
|
||||
if [ "${use_composer}" -eq 1 ]; then
|
||||
PHAN_CALL+=("${BASE_PATH}vendor/bin/phan");
|
||||
else
|
||||
PHAN_CALL+=("${BASE_PATH}tools/phan");
|
||||
fi;
|
||||
PHAN_CALL+=(
|
||||
"--progress-bar"
|
||||
"-C"
|
||||
"--analyze-twice"
|
||||
)
|
||||
"${PHAN_CALL[@]}";
|
||||
if [ "${no_php_version}" -eq 0 ]; then
|
||||
echo "*** CALLED WITH PHP ${php_bin} ***";
|
||||
${php_bin} --version;
|
||||
else
|
||||
echo "Default PHP used: $(php --version)";
|
||||
fi;
|
||||
cd ~ || exit;
|
||||
|
||||
# __END__
|
||||
|
||||
@@ -1,3 +1,92 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# must be run in ${base}www/
|
||||
phpstan
|
||||
#!/bin/env bash
|
||||
|
||||
function error() {
|
||||
if [ -t 1 ]; then echo "[MAK] ERROR: $*" >&2; fi; exit 0;
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-h | --help] [-p | --php VERSION] [-c | --composer]
|
||||
|
||||
Runs phan static analyzer.
|
||||
|
||||
If -p is not set, the default intalled PHP is used.
|
||||
|
||||
Available options:
|
||||
|
||||
-h, --help Print this help and exit
|
||||
-p, --php VERSION Chose PHP version in the form of "N.N", if not found will exit
|
||||
-c, --composer Use composer version and not the default phives bundle
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
BASE_PATH=$(pwd)"/";
|
||||
PHP_BIN_PATH=$(which php);
|
||||
if [ -z "${PHP_BIN_PATH}" ]; then
|
||||
echo "Cannot find php binary";
|
||||
exit;
|
||||
fi;
|
||||
DEFAULT_PHP_VERSION=$(${PHP_BIN_PATH} -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;");
|
||||
if [ -z "${DEFAULT_PHP_VERSION}" ]; then
|
||||
echo "Cannot set default PHP version";
|
||||
exit;
|
||||
fi;
|
||||
php_version="";
|
||||
no_php_version=0;
|
||||
use_composer=0;
|
||||
while [ -n "${1-}" ]; do
|
||||
case "${1}" in
|
||||
-p | --php)
|
||||
php_version="${2-}";
|
||||
shift
|
||||
;;
|
||||
-c | --composer)
|
||||
use_composer=1;
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
;;
|
||||
# invalid option
|
||||
-?*)
|
||||
error "[!] Unknown option: '$1'."
|
||||
;;
|
||||
esac
|
||||
shift;
|
||||
done;
|
||||
if [ -z "${php_version}" ]; then
|
||||
php_version="${DEFAULT_PHP_VERSION}";
|
||||
no_php_version=1;
|
||||
fi;
|
||||
php_bin="${PHP_BIN_PATH}${php_version}";
|
||||
echo "Use PHP Version: ${php_version}";
|
||||
if [ "${use_composer}" -eq 1 ]; then
|
||||
echo "Use composer installed";
|
||||
else
|
||||
echo "Use phive installed";
|
||||
fi;
|
||||
|
||||
if [ ! -f "${php_bin}" ]; then
|
||||
echo "Set php ${php_bin} does not exist";
|
||||
exit;
|
||||
fi;
|
||||
|
||||
BASE_PATH=$(pwd)"/";
|
||||
cd "$BASE_PATH" || exit;
|
||||
PHPSTAN_CALL=(
|
||||
"${php_bin}"
|
||||
);
|
||||
if [ "${use_composer}" -eq 1 ]; then
|
||||
PHPSTAN_CALL+=("${BASE_PATH}vendor/bin/phpstan");
|
||||
else
|
||||
PHPSTAN_CALL+=("${BASE_PATH}tools/phpstan");
|
||||
fi;
|
||||
"${PHPSTAN_CALL[@]}";
|
||||
if [ "${no_php_version}" -eq 0 ]; then
|
||||
echo "*** CALLED WITH PHP ${php_bin} ***";
|
||||
${php_bin} --version;
|
||||
else
|
||||
echo "Default PHP used: $(php --version)";
|
||||
fi;
|
||||
cd ~ || exit;
|
||||
|
||||
@@ -1,44 +1,119 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
#!/bin/env bash
|
||||
|
||||
function error() {
|
||||
if [ -t 1 ]; then echo "[MAK] ERROR: $*" >&2; fi; exit 0;
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "${BASH_SOURCE[0]}") [-h | --help] [-p | --php VERSION] [-c | --composer] [-t | --testdox] [-v | --verbose]
|
||||
|
||||
Runs all the PHP unit tests.
|
||||
|
||||
If -p is not set, the default intalled PHP is used.
|
||||
|
||||
Available options:
|
||||
|
||||
-h, --help Print this help and exit
|
||||
-t, --testdox Enable testdox output for PHPunit
|
||||
-v, --verbose Enable verbose output for PHPunit
|
||||
-c, --composer Use composer version and not the default phives bundle
|
||||
-p, --php VERSION Chose PHP version in the form of "N.N", if not found will exit
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
# set base variables
|
||||
BASE_PATH=$(pwd)"/";
|
||||
PHPUNIT_CONFIG="${BASE_PATH}phpunit.xml";
|
||||
PHP_BIN_PATH=$(which php);
|
||||
if [ -z "${PHP_BIN_PATH}" ]; then
|
||||
echo "Cannot find php binary";
|
||||
exit;
|
||||
fi;
|
||||
DEFAULT_PHP_VERSION=$(${PHP_BIN_PATH} -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;");
|
||||
if [ -z "${DEFAULT_PHP_VERSION}" ]; then
|
||||
echo "Cannot set default PHP version";
|
||||
exit;
|
||||
fi;
|
||||
# -c phpunit.xml
|
||||
# --testdox
|
||||
# call with "t" to give verbose testdox output
|
||||
# call with "-tt" to give verbose testdox output
|
||||
# SUPPORTED: https://www.php.net/supported-versions.php
|
||||
# call with 7.4, 8.0, 8.1 to force a certain php version
|
||||
# call with -p <php version number> to force a certain php version
|
||||
|
||||
opt_testdox="";
|
||||
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
||||
opt_testdox="--testdox";
|
||||
fi;
|
||||
php_bin="";
|
||||
if [ ! -z "${1}" ]; then
|
||||
opt_verbose="";
|
||||
php_version="";
|
||||
no_php_version=0;
|
||||
use_composer=0;
|
||||
while [ -n "${1-}" ]; do
|
||||
case "${1}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
-t | --testdox)
|
||||
opt_testdox="--testdox";
|
||||
;;
|
||||
-v | --verbose)
|
||||
opt_verbose="--verbose";
|
||||
;;
|
||||
-c | --composer)
|
||||
use_composer=1;
|
||||
shift
|
||||
;;
|
||||
-p | --php)
|
||||
php_version="${2-}";
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
;;
|
||||
# invalid option
|
||||
-?*)
|
||||
error "[!] Unknown option: '$1'."
|
||||
;;
|
||||
esac
|
||||
shift;
|
||||
done;
|
||||
|
||||
if [ -z "${php_version}" ]; then
|
||||
php_version="${DEFAULT_PHP_VERSION}";
|
||||
no_php_version=1;
|
||||
fi;
|
||||
if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
|
||||
case "${2}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
|
||||
phpunit_call="${php_bin}${base}www/vendor/bin/phpunit ${opt_testdox} -c ${base}phpunit.xml ${base}4dev/tests/";
|
||||
|
||||
${phpunit_call};
|
||||
|
||||
if [ ! -z "${php_bin}" ]; then
|
||||
echo "CALLED WITH PHP: ${php_bin}"$(${php_bin} --version);
|
||||
php_bin="${PHP_BIN_PATH}${php_version}";
|
||||
echo "Use PHP Version: ${php_version}";
|
||||
if [ "${use_composer}" -eq 1 ]; then
|
||||
echo "Use composer installed";
|
||||
else
|
||||
echo "Default PHP used: "$(php --version);
|
||||
echo "Use phive installed";
|
||||
fi;
|
||||
|
||||
if [ ! -f "${php_bin}" ]; then
|
||||
echo "Set php ${php_bin} does not exist";
|
||||
exit;
|
||||
fi;
|
||||
|
||||
# Note 4dev/tests/bootstrap.php has to be set as bootstrap file in phpunit.xml
|
||||
PHPUNIT_CALL=(
|
||||
"${php_bin}"
|
||||
);
|
||||
if [ "${use_composer}" -eq 1 ]; then
|
||||
PHPUNIT_CALL+=("${BASE_PATH}vendor/bin/phpunit");
|
||||
else
|
||||
PHPUNIT_CALL+=("${BASE_PATH}tools/phpunit");
|
||||
fi;
|
||||
PHPUNIT_CALL+=(
|
||||
"${opt_testdox}"
|
||||
"${opt_verbose}"
|
||||
"-c" "${PHPUNIT_CONFIG}"
|
||||
"${BASE_PATH}4dev/tests/"
|
||||
);
|
||||
"${PHPUNIT_CALL[@]}" || exit;
|
||||
|
||||
echo -e "\nPHPUnit Config: ${PHPUNIT_CONFIG}";
|
||||
if [ "${no_php_version}" -eq 0 ]; then
|
||||
echo "*** CALLED WITH PHP ${php_bin} ***";
|
||||
${php_bin} --version;
|
||||
else
|
||||
echo "Default PHP used: $(php --version)";
|
||||
fi;
|
||||
|
||||
# __END__
|
||||
|
||||
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/master/"
|
||||
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__
|
||||
@@ -5,9 +5,9 @@ RETURNS TRIGGER AS
|
||||
$$
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
NEW.date_created := clock_timestamp();
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
NEW.date_updated := clock_timestamp();
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
|
||||
@@ -7,10 +7,11 @@ DECLARE
|
||||
random_length INT = 25; -- that should be long enough
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
NEW.date_created := clock_timestamp();
|
||||
NEW.cuid := random_string(random_length);
|
||||
NEW.cuuid := gen_random_uuid();
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
NEW.date_updated := clock_timestamp();
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
|
||||
@@ -8,12 +8,12 @@ DECLARE
|
||||
random_length INT = 32; -- long for massive data
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
NEW.date_created := 'now';
|
||||
NEW.date_created := clock_timestamp();
|
||||
IF NEW.uid IS NULL THEN
|
||||
NEW.uid := random_string(random_length);
|
||||
END IF;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
NEW.date_updated := 'now';
|
||||
NEW.date_updated := clock_timestamp();
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
-- adds the created or updated date tags
|
||||
|
||||
-- OLD, DEPRECATED, use set_generic.sql
|
||||
|
||||
-- CREATE OR REPLACE FUNCTION set_generic()
|
||||
-- RETURNS TRIGGER AS
|
||||
-- $$
|
||||
-- BEGIN
|
||||
-- IF TG_OP = 'INSERT' THEN
|
||||
-- NEW.date_created := clock_timestamp();
|
||||
-- NEW.user_created := current_user;
|
||||
-- ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- NEW.date_updated := clock_timestamp();
|
||||
-- NEW.user_updated := current_user;
|
||||
-- END IF;
|
||||
-- RETURN NEW;
|
||||
-- END;
|
||||
-- $$
|
||||
-- LANGUAGE 'plpgsql';
|
||||
110
4dev/database/function/upgrade_serial_to_identity.sql
Normal file
110
4dev/database/function/upgrade_serial_to_identity.sql
Normal file
@@ -0,0 +1,110 @@
|
||||
-- Upgrade serial to identity type
|
||||
--
|
||||
-- Original: https://www.enterprisedb.com/blog/postgresql-10-identity-columns-explained#section-6
|
||||
--
|
||||
-- @param reclass tbl The table where the column is located, prefix with 'schema.' if different schema
|
||||
-- @param name col The column to be changed
|
||||
-- @param varchar identity_type [default=a] Allowed a, d, assigned, default
|
||||
-- @param varchar col_type [default=''] Allowed smallint, int, bigint, int2, int4, int8
|
||||
-- @returns varchar status tring
|
||||
-- @raises EXCEPTON on column not found, no linked sequence, more than one linked sequence found, invalid col type
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION upgrade_serial_to_identity(
|
||||
tbl regclass,
|
||||
col name,
|
||||
identity_type varchar = 'a',
|
||||
col_type varchar = ''
|
||||
)
|
||||
RETURNS varchar
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
colnum SMALLINT;
|
||||
seqid OID;
|
||||
count INT;
|
||||
col_type_oid INT;
|
||||
col_type_len INT;
|
||||
current_col_atttypid OID;
|
||||
current_col_attlen INT;
|
||||
status_string VARCHAR;
|
||||
BEGIN
|
||||
-- switch between always (default) or default identiy type
|
||||
IF identity_type NOT IN ('a', 'd', 'assigned', 'default') THEN
|
||||
identity_type := 'a';
|
||||
ELSE
|
||||
IF identity_type = 'default' THEN
|
||||
identity_type := 'd';
|
||||
ELSIF identity_type = 'assigned' THEN
|
||||
identity_type := 'a';
|
||||
END IF;
|
||||
END IF;
|
||||
-- find column number, attribute oid and attribute len
|
||||
SELECT attnum, atttypid, attlen
|
||||
INTO colnum, current_col_atttypid, current_col_attlen
|
||||
FROM pg_attribute
|
||||
WHERE attrelid = tbl AND attname = col;
|
||||
IF NOT FOUND THEN
|
||||
RAISE EXCEPTION 'column does not exist';
|
||||
END IF;
|
||||
|
||||
-- find sequence
|
||||
SELECT INTO seqid objid
|
||||
FROM pg_depend
|
||||
WHERE (refclassid, refobjid, refobjsubid) = ('pg_class'::regclass, tbl, colnum)
|
||||
AND classid = 'pg_class'::regclass AND objsubid = 0
|
||||
AND deptype = 'a';
|
||||
|
||||
GET DIAGNOSTICS count = ROW_COUNT;
|
||||
IF count < 1 THEN
|
||||
RAISE EXCEPTION 'no linked sequence found';
|
||||
ELSIF count > 1 THEN
|
||||
RAISE EXCEPTION 'more than one linked sequence found';
|
||||
END IF;
|
||||
|
||||
IF col_type <> '' AND col_type NOT IN ('smallint', 'int', 'bigint', 'int2', 'int4', 'int8') THEN
|
||||
RAISE EXCEPTION 'Invalid col type: %', col_type;
|
||||
END IF;
|
||||
|
||||
-- drop the default
|
||||
EXECUTE 'ALTER TABLE ' || tbl || ' ALTER COLUMN ' || quote_ident(col) || ' DROP DEFAULT';
|
||||
|
||||
-- change the dependency between column and sequence to internal
|
||||
UPDATE pg_depend
|
||||
SET deptype = 'i'
|
||||
WHERE (classid, objid, objsubid) = ('pg_class'::regclass, seqid, 0)
|
||||
AND deptype = 'a';
|
||||
|
||||
-- mark the column as identity column
|
||||
UPDATE pg_attribute
|
||||
-- set to 'd' for default
|
||||
SET attidentity = identity_type
|
||||
WHERE attrelid = tbl
|
||||
AND attname = col;
|
||||
status_string := 'Updated to identity for table "' || tbl || '" and columen "' || col || '" with type "' || identity_type || '"';
|
||||
|
||||
-- set type if requested and not empty
|
||||
IF col_type <> '' THEN
|
||||
-- rewrite smallint, int, bigint
|
||||
IF col_type = 'smallint' THEN
|
||||
col_type := 'int2';
|
||||
ELSIF col_type = 'int' THEN
|
||||
col_type := 'int4';
|
||||
ELSIF col_type = 'bigint' THEN
|
||||
col_type := 'int8';
|
||||
END IF;
|
||||
-- get the length and oid for selected
|
||||
SELECT oid, typlen INTO col_type_oid, col_type_len FROM pg_type WHERE typname = col_type;
|
||||
-- set only if diff or hight
|
||||
IF current_col_atttypid <> col_type_oid AND col_type_len > current_col_attlen THEN
|
||||
status_string := status_string || '. Change col type: ' || col_type;
|
||||
-- update type
|
||||
UPDATE pg_attribute
|
||||
SET
|
||||
atttypid = col_type_oid, attlen = col_type_len
|
||||
WHERE attrelid = tbl
|
||||
AND attname = col;
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN status_string;
|
||||
END;
|
||||
$$;
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_access;
|
||||
CREATE TABLE edit_access (
|
||||
edit_access_id SERIAL PRIMARY KEY,
|
||||
edit_access_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
protected SMALLINT DEFAULT 0,
|
||||
deleted SMALLINT DEFAULT 0,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_access_data;
|
||||
CREATE TABLE edit_access_data (
|
||||
edit_access_data_id SERIAL PRIMARY KEY,
|
||||
edit_access_data_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
-- DROP TABLE edit_access_right;
|
||||
CREATE TABLE edit_access_right (
|
||||
edit_access_right_id SERIAL PRIMARY KEY,
|
||||
edit_access_right_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
level SMALLINT,
|
||||
type VARCHAR,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_access_user;
|
||||
CREATE TABLE edit_access_user (
|
||||
edit_access_user_id SERIAL PRIMARY KEY,
|
||||
edit_access_user_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_user_id INT NOT NULL,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
-- DROP TABLE edit_generic;
|
||||
CREATE TABLE edit_generic (
|
||||
cuid VARCHAR,
|
||||
cuuid UUID DEFAULT gen_random_uuid(),
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE
|
||||
);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_group;
|
||||
CREATE TABLE edit_group (
|
||||
edit_group_id SERIAL PRIMARY KEY,
|
||||
edit_group_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_scheme_id INT,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
-- DROP TABLE edit_language;
|
||||
CREATE TABLE edit_language (
|
||||
edit_language_id SERIAL PRIMARY KEY,
|
||||
edit_language_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
lang_default SMALLINT NOT NULL DEFAULT 0,
|
||||
long_name VARCHAR,
|
||||
|
||||
@@ -7,35 +7,54 @@
|
||||
|
||||
-- DROP TABLE edit_log;
|
||||
CREATE TABLE edit_log (
|
||||
edit_log_id SERIAL PRIMARY KEY,
|
||||
edit_log_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
euid INT, -- this is a foreign key, but I don't nedd to reference to it
|
||||
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
username VARCHAR,
|
||||
password VARCHAR,
|
||||
eucuid VARCHAR,
|
||||
eucuuid UUID, -- this is the one we want to use, full UUIDv4 from the edit user table
|
||||
-- date_created equal, but can be overridden
|
||||
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
ip VARCHAR,
|
||||
-- session ID if set
|
||||
session_id VARCHAR,
|
||||
-- username
|
||||
username VARCHAR,
|
||||
-- DEPRECATED [password]
|
||||
password VARCHAR,
|
||||
ip_address JSONB, -- REMOTE_IP and all other IPs (X_FORWARD, etc) as JSON block
|
||||
-- DEPRECATED [ip]
|
||||
ip VARCHAR, -- just the REMOTE_IP, full set see ip_address
|
||||
-- string blocks, general
|
||||
error TEXT,
|
||||
event TEXT,
|
||||
-- bytea or string type storage of any data
|
||||
data_binary BYTEA,
|
||||
data TEXT,
|
||||
-- set page name only
|
||||
page VARCHAR,
|
||||
action VARCHAR,
|
||||
action_id VARCHAR,
|
||||
action_yes VARCHAR,
|
||||
action_flag VARCHAR,
|
||||
action_menu VARCHAR,
|
||||
action_loaded VARCHAR,
|
||||
action_value VARCHAR,
|
||||
action_type VARCHAR,
|
||||
action_error VARCHAR,
|
||||
-- various info data sets
|
||||
user_agent VARCHAR,
|
||||
referer VARCHAR,
|
||||
script_name VARCHAR,
|
||||
query_string VARCHAR,
|
||||
request_scheme VARCHAR, -- http or https
|
||||
server_name VARCHAR,
|
||||
http_host VARCHAR,
|
||||
http_accept VARCHAR,
|
||||
http_accept_charset VARCHAR,
|
||||
http_accept_encoding VARCHAR,
|
||||
session_id VARCHAR
|
||||
http_data JSONB,
|
||||
-- DEPRECATED [http*]
|
||||
http_accept VARCHAR, -- in http_data
|
||||
http_accept_charset VARCHAR, -- in http_data
|
||||
http_accept_encoding VARCHAR, -- in http_data
|
||||
-- any action var, -> same set in action_data as JSON
|
||||
action_data JSONB,
|
||||
-- DEPRECATED [action*]
|
||||
action VARCHAR, -- in action_data
|
||||
action_id VARCHAR, -- in action_data
|
||||
action_sub_id VARCHAR, -- in action_data
|
||||
action_yes VARCHAR, -- in action_data
|
||||
action_flag VARCHAR, -- in action_data
|
||||
action_menu VARCHAR, -- in action_data
|
||||
action_loaded VARCHAR, -- in action_data
|
||||
action_value VARCHAR, -- in action_data
|
||||
action_type VARCHAR, -- in action_data
|
||||
action_error VARCHAR -- in action_data
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
|
||||
-- DROP TABLE edit_menu_group;
|
||||
CREATE TABLE edit_menu_group (
|
||||
edit_menu_group_id SERIAL PRIMARY KEY,
|
||||
edit_menu_group_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
flag VARCHAR,
|
||||
order_number INT NOT NULL
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_page;
|
||||
CREATE TABLE edit_page (
|
||||
edit_page_id SERIAL PRIMARY KEY,
|
||||
edit_page_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
content_alias_edit_page_id INT, -- alias for page content, if the page content is defined on a different page, ege for ajax backend pages
|
||||
FOREIGN KEY (content_alias_edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
filename VARCHAR,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_page_access;
|
||||
CREATE TABLE edit_page_access (
|
||||
edit_page_access_id SERIAL PRIMARY KEY,
|
||||
edit_page_access_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_page_id INT NOT NULL,
|
||||
@@ -16,5 +16,3 @@ CREATE TABLE edit_page_access (
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
-- DROP TABLE edit_page_content;
|
||||
CREATE TABLE edit_page_content (
|
||||
edit_page_content_id SERIAL PRIMARY KEY,
|
||||
edit_page_content_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_query_string;
|
||||
CREATE TABLE edit_query_string (
|
||||
edit_query_string_id SERIAL PRIMARY KEY,
|
||||
edit_query_string_id SERIAINT GENERATED ALWAYS AS IDENTITYL PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_scheme;
|
||||
CREATE TABLE edit_scheme (
|
||||
edit_scheme_id SERIAL PRIMARY KEY,
|
||||
edit_scheme_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
header_color VARCHAR,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_user;
|
||||
CREATE TABLE edit_user (
|
||||
edit_user_id SERIAL PRIMARY KEY,
|
||||
edit_user_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
connect_edit_user_id INT, -- possible reference to other user
|
||||
FOREIGN KEY (connect_edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_language_id INT NOT NULL,
|
||||
@@ -35,11 +35,10 @@ CREATE TABLE edit_user (
|
||||
strict SMALLINT DEFAULT 0,
|
||||
locked SMALLINT DEFAULT 0,
|
||||
protected SMALLINT NOT NULL DEFAULT 0,
|
||||
-- legacy, debug flags
|
||||
debug SMALLINT NOT NULL DEFAULT 0,
|
||||
db_debug SMALLINT NOT NULL DEFAULT 0,
|
||||
-- is admin user
|
||||
admin SMALLINT NOT NULL DEFAULT 0,
|
||||
-- force lgout counter
|
||||
force_logout INT DEFAULT 0,
|
||||
-- last login log
|
||||
last_login TIMESTAMP WITHOUT TIME ZONE,
|
||||
-- login error
|
||||
@@ -76,9 +75,8 @@ COMMENT ON COLUMN edit_user.deleted IS 'Login is deleted (master switch), overri
|
||||
COMMENT ON COLUMN edit_user.strict IS 'If too many failed logins user will be locked, default off';
|
||||
COMMENT ON COLUMN edit_user.locked IS 'Locked from too many wrong password logins';
|
||||
COMMENT ON COLUMN edit_user.protected IS 'User can only be chnaged by admin user';
|
||||
COMMENT ON COLUMN edit_user.debug IS 'Turn debug flag on (legacy)';
|
||||
COMMENT ON COLUMN edit_user.db_debug IS 'Turn DB debug flag on (legacy)';
|
||||
COMMENT ON COLUMN edit_user.admin IS 'If set, this user is SUPER admin';
|
||||
COMMENT ON COLUMN edit_user.force_logout IS 'Counter for forced log out, if this one is higher than the session set one the session gets terminated';
|
||||
COMMENT ON COLUMN edit_user.last_login IS 'Last succesfull login tiemstamp';
|
||||
COMMENT ON COLUMN edit_user.login_error_count IS 'Number of failed logins, reset on successful login';
|
||||
COMMENT ON COLUMN edit_user.login_error_date_last IS 'Last login error date';
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_visible_group;
|
||||
CREATE TABLE edit_visible_group (
|
||||
edit_visible_group_id SERIAL PRIMARY KEY,
|
||||
edit_visible_group_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR,
|
||||
flag VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -9,5 +9,6 @@
|
||||
CREATE TABLE generic (
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE,
|
||||
uuid UUID DEFAULT gen_random_uuid(),
|
||||
uid VARCHAR
|
||||
);
|
||||
|
||||
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
|
||||
path=$(pwd)"/"$0;
|
||||
@@ -10,6 +10,11 @@ TARGET_HOST_WEB="<user>@<host>";
|
||||
TMP_DIR=$LOCAL_BASE_DIR"/4dev/tmp/";
|
||||
tmpf_web=$TMP_DIR"sync.exclude.tmp";
|
||||
|
||||
if [ ! -d "$LOCAL_BASE_DIR" ]; then
|
||||
echo "Folder: $LOCAL_BASE_DIR not found";
|
||||
exit;
|
||||
fi;
|
||||
|
||||
# if vendor be sure group folder is +x
|
||||
chmod -R ug+rX ${LOCAL_DIR}/vender/
|
||||
|
||||
|
||||
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(1);
|
||||
}
|
||||
|
||||
// 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(1);
|
||||
}
|
||||
|
||||
print buildContent($http_headers, $file_get);
|
||||
|
||||
// __END__
|
||||
@@ -7,6 +7,16 @@ namespace tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
/*
|
||||
Not yet covered tests:
|
||||
- loginGetLocale
|
||||
- loginGetHeaderColor
|
||||
- loginGetPages
|
||||
- loginGetPageLookupList
|
||||
- loginPageAccessAllowed
|
||||
- loginGetEuid
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for ACL\Login
|
||||
* @coversDefaultClass \CoreLibs\ACL\Login
|
||||
@@ -14,8 +24,12 @@ use PHPUnit\Framework\MockObject\MockObject;
|
||||
*/
|
||||
final class CoreLibsACLLoginTest extends TestCase
|
||||
{
|
||||
private static $db;
|
||||
private static $log;
|
||||
private static \CoreLibs\DB\IO $db;
|
||||
private static \CoreLibs\Logging\Logging $log;
|
||||
|
||||
private static string $edit_access_cuid;
|
||||
private static string $edit_user_cuid;
|
||||
private static string $edit_user_cuuid;
|
||||
|
||||
/**
|
||||
* start DB conneciton, setup DB, etc
|
||||
@@ -60,13 +74,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
|
||||
// logger is always needed
|
||||
// define basic connection set valid and one invalid
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
self::$log = new \CoreLibs\Logging\Logging([
|
||||
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-ACL-Login-Test',
|
||||
'debug_all' => true,
|
||||
'echo_all' => false,
|
||||
'print_all' => true,
|
||||
'log_file_id' => 'CoreLibs-ACL-Login-Test',
|
||||
]);
|
||||
// test database we need to connect do, if not possible this test is skipped
|
||||
self::$db = new \CoreLibs\DB\IO(
|
||||
@@ -103,25 +114,48 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
self::$db->dbSetMaxQueryCall(-1);
|
||||
// insert additional content for testing (locked user, etc)
|
||||
$queries = [
|
||||
"INSERT INTO edit_access_data "
|
||||
. "(edit_access_id, name, value, enabled) VALUES "
|
||||
. "((SELECT edit_access_id FROM edit_access WHERE uid = 'AdminAccess'), "
|
||||
. "'test', 'value', 1)"
|
||||
<<<SQL
|
||||
INSERT INTO edit_access_data (
|
||||
edit_access_id, name, value, enabled
|
||||
) VALUES (
|
||||
(SELECT edit_access_id FROM edit_access WHERE uid = 'AdminAccess'),
|
||||
'test', 'value', 1
|
||||
)
|
||||
SQL
|
||||
];
|
||||
foreach ($queries as $query) {
|
||||
self::$db->dbExec($query);
|
||||
}
|
||||
// read edit access cuid, edit user cuid and edit user cuuid
|
||||
$row = self::$db->dbReturnRowParams(
|
||||
"SELECT cuid FROM edit_access WHERE uid = $1",
|
||||
["AdminAccess"]
|
||||
);
|
||||
self::$edit_access_cuid = $row['cuid'] ?? '';
|
||||
if (empty(self::$edit_access_cuid)) {
|
||||
self::markTestIncomplete(
|
||||
'Cannot read edit access cuid for "AdminAccess".'
|
||||
);
|
||||
}
|
||||
$row = self::$db->dbReturnRowParams(
|
||||
"SELECT cuid, cuuid FROM edit_user WHERE username = $1",
|
||||
["admin"]
|
||||
);
|
||||
self::$edit_user_cuid = $row['cuid'] ?? '';
|
||||
self::$edit_user_cuuid = $row['cuuid'] ?? '';
|
||||
if (empty(self::$edit_user_cuid) || empty(self::$edit_user_cuuid)) {
|
||||
self::markTestIncomplete(
|
||||
'Cannot read edit user cuid or cuuid for "admin".'
|
||||
);
|
||||
}
|
||||
|
||||
// define mandatory constant
|
||||
// must set
|
||||
// TARGET
|
||||
define('TARGET', 'test');
|
||||
// LOGIN DB SCHEMA
|
||||
// define('LOGIN_DB_SCHEMA', '');
|
||||
|
||||
// SHOULD SET
|
||||
// PASSWORD_MIN_LENGTH (d9)
|
||||
// PASSWORD_MAX_LENGTH (d255)
|
||||
// DEFAULT_ACL_LEVEL (d80)
|
||||
|
||||
// OPT:
|
||||
@@ -164,8 +198,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
// change_password, pw_username, pw_old_password, pw_new_password,
|
||||
// pw_new_password_confirm
|
||||
// 3[session]: override session set
|
||||
// 4[error] : expected error code, 0 for all ok, 3000 for login page view
|
||||
// note that 1000 (no db), 2000 (no session) must be tested too
|
||||
// 4[error] : expected error code, 0 for all ok, 100 for login page view
|
||||
// note that 1000 (no db), 2000 (no session), 3000 (options set error)
|
||||
// must be tested too
|
||||
// <1000 info, >=1000 critical error
|
||||
// 5[return] : expected return array, eg login_error code,
|
||||
// or other info data to match
|
||||
$tests = [
|
||||
@@ -177,7 +213,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -195,7 +231,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -218,7 +254,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 0,
|
||||
'error_string' => 'Success: <b>No error</b>',
|
||||
@@ -230,22 +266,25 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'ajax_post_action' => 'login',
|
||||
],
|
||||
],
|
||||
'load, session euid set only, php error' => [
|
||||
'load, session eucuuid set only, php error' => [
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
],
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'EUID' => 1,
|
||||
'LOGIN_EUID' => 1,
|
||||
'LOGIN_EUCUID' => 'abc',
|
||||
'LOGIN_EUCUUID' => '1233456-1234-1234-1234-123456789012',
|
||||
],
|
||||
2,
|
||||
[],
|
||||
],
|
||||
'load, session euid set, all set' => [
|
||||
'load, session eucuuid set, all set' => [
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -254,18 +293,23 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'EUID' => 1,
|
||||
'USER_NAME' => '',
|
||||
'GROUP_NAME' => '',
|
||||
'ADMIN' => 1,
|
||||
'GROUP_ACL_LEVEL' => -1,
|
||||
'PAGES_ACL_LEVEL' => [],
|
||||
'USER_ACL_LEVEL' => -1,
|
||||
'UNIT_UID' => [
|
||||
'AdminAccess' => 1,
|
||||
'LOGIN_EUID' => 1,
|
||||
'LOGIN_EUCUID' => 'abc',
|
||||
'LOGIN_EUCUUID' => 'SET_EUCUUID_IN_TEST',
|
||||
'LOGIN_USER_NAME' => '',
|
||||
'LOGIN_GROUP_NAME' => '',
|
||||
'LOGIN_ADMIN' => 1,
|
||||
'LOGIN_GROUP_ACL_LEVEL' => -1,
|
||||
'LOGIN_PAGES_ACL_LEVEL' => [],
|
||||
'LOGIN_USER_ACL_LEVEL' => -1,
|
||||
'LOGIN_USER_ADDITIONAL_ACL' => [],
|
||||
'LOGIN_GROUP_ADDITIONAL_ACL' => [],
|
||||
'LOGIN_UNIT_UID' => [
|
||||
'AdminAccess' => '123456789012',
|
||||
],
|
||||
'UNIT' => [
|
||||
1 => [
|
||||
'LOGIN_UNIT' => [
|
||||
'123456789012' => [
|
||||
'id' => 1,
|
||||
'acl_level' => 80,
|
||||
'name' => 'Admin Access',
|
||||
'uid' => 'AdminAccess',
|
||||
@@ -274,10 +318,11 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'data' => [
|
||||
'test' => 'value',
|
||||
],
|
||||
'additional_acl' => []
|
||||
],
|
||||
],
|
||||
// 'UNIT_DEFAULT' => '',
|
||||
// 'DEFAULT_ACL_LIST' => [],
|
||||
// 'LOGIN_UNIT_DEFAULT' => '',
|
||||
// 'LOGIN_DEFAULT_ACL_LIST' => [],
|
||||
],
|
||||
0,
|
||||
[
|
||||
@@ -285,6 +330,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -302,7 +348,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => '',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -323,7 +369,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -344,7 +390,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => '',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -365,7 +411,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1010,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -389,7 +435,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'abc',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
// default password is plain text
|
||||
'login_error' => 1012,
|
||||
@@ -404,6 +450,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_deleted' => true
|
||||
@@ -415,7 +462,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 106,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -429,6 +476,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_enabled' => true
|
||||
@@ -440,7 +488,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 104,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -454,6 +502,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_locked' => true
|
||||
@@ -465,7 +514,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 105,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -479,6 +528,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_get_locked' => true,
|
||||
@@ -503,6 +553,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_locked_period_until' => 'on'
|
||||
@@ -514,7 +565,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -528,6 +579,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -547,6 +599,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -557,6 +610,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_locked_period_after' => 'on'
|
||||
@@ -568,7 +622,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -582,6 +636,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_locked_period_until' => 'on',
|
||||
@@ -594,7 +649,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 107,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -608,6 +663,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_locked' => true
|
||||
@@ -619,7 +675,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'login_password' => 'admin',
|
||||
],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 108,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -633,6 +689,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -651,6 +708,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -661,6 +719,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -680,6 +739,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -690,6 +750,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -709,6 +770,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -719,6 +781,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -738,6 +801,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -755,7 +819,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1010,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -769,6 +833,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -792,6 +857,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -802,6 +868,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -825,6 +892,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -835,6 +903,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_revalidate_after' => 'on',
|
||||
@@ -847,7 +916,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1101,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -861,6 +930,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -881,6 +951,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -891,6 +962,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_valid_from' => 'on',
|
||||
@@ -903,7 +975,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -917,6 +989,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -937,6 +1010,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -947,6 +1021,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_valid_until' => 'on',
|
||||
@@ -959,7 +1034,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -973,6 +1048,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'base_access' => 'list',
|
||||
'page_access' => 'list',
|
||||
'test_login_user_id_valid_from' => 'on',
|
||||
@@ -986,7 +1062,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
3000,
|
||||
100,
|
||||
[
|
||||
'login_error' => 1102,
|
||||
'error_string' => '<span style="color: red;">Fatal Error:</span> '
|
||||
@@ -1000,6 +1076,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
[
|
||||
'page_name' => 'edit_users.php',
|
||||
'edit_access_id' => 1,
|
||||
'edit_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'edit_access_uid' => 'AdminAccess',
|
||||
'edit_access_data' => 'test',
|
||||
'base_access' => 'list',
|
||||
@@ -1030,6 +1107,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'admin_flag' => true,
|
||||
'check_access' => true,
|
||||
'check_access_id' => 1,
|
||||
'check_access_cuid' => 'SET_EDIT_ACCESS_CUID_IN_TEST',
|
||||
'check_access_data' => 'value',
|
||||
'base_access' => true,
|
||||
'page_access' => true,
|
||||
@@ -1077,9 +1155,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST12');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST12');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -1099,20 +1177,39 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$_POST[$post_var] = $post_value;
|
||||
}
|
||||
|
||||
// set ingoing session cuuid if requested
|
||||
if (isset($session['LOGIN_EUCUUID']) && $session['LOGIN_EUCUUID'] == 'SET_EUCUUID_IN_TEST') {
|
||||
$session['LOGIN_EUCUUID'] = self::$edit_user_cuuid;
|
||||
}
|
||||
|
||||
// set _SESSION data
|
||||
foreach ($session as $session_var => $session_value) {
|
||||
$_SESSION[$session_var] = $session_value;
|
||||
}
|
||||
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->onlyMethods(['loginTerminate', 'loginReadPageName', 'loginPrintLogin'])
|
||||
->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', 'loginEnhanceHttpSecurity'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1125,6 +1222,10 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
->method('loginPrintLogin')
|
||||
->willReturnCallback(function () {
|
||||
});
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginEnhanceHttpSecurity')
|
||||
->willReturnCallback(function () {
|
||||
});
|
||||
|
||||
// if mock_settings: enabled OFF
|
||||
// run DB update and set off
|
||||
@@ -1206,7 +1307,11 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->loginSetMaxLoginErrorCount($mock_settings['max_login_error_count']);
|
||||
// temporary wrong password
|
||||
$_POST['login_password'] = 'wrong';
|
||||
for ($run = 1, $max_run = $login_mock->loginGetMaxLoginErrorCount(); $run <= $max_run; $run++) {
|
||||
for (
|
||||
$run = 1, $max_run = $login_mock->loginGetMaxLoginErrorCount();
|
||||
$run <= $max_run;
|
||||
$run++
|
||||
) {
|
||||
try {
|
||||
$login_mock->loginMainCall();
|
||||
} catch (\Exception $e) {
|
||||
@@ -1338,6 +1443,19 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
|
||||
// run test
|
||||
try {
|
||||
// preset, we cannot set that in the provider
|
||||
if (
|
||||
isset($expected['check_access_cuid']) &&
|
||||
$expected['check_access_cuid'] == 'SET_EDIT_ACCESS_CUID_IN_TEST'
|
||||
) {
|
||||
$expected['check_access_cuid'] = self::$edit_access_cuid;
|
||||
}
|
||||
if (
|
||||
isset($mock_settings['edit_access_cuid']) &&
|
||||
$mock_settings['edit_access_cuid'] == 'SET_EDIT_ACCESS_CUID_IN_TEST'
|
||||
) {
|
||||
$mock_settings['edit_access_cuid'] = self::$edit_access_cuid;
|
||||
}
|
||||
// if ajax call
|
||||
// check if parameter, or globals (old type)
|
||||
// else normal call
|
||||
@@ -1396,6 +1514,31 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$login_mock->loginCheckAccessPage($mock_settings['page_access']),
|
||||
'Assert page access'
|
||||
);
|
||||
// - loginCheckEditAccessCuid
|
||||
$this->assertEquals(
|
||||
$expected['check_access'],
|
||||
$login_mock->loginCheckEditAccessCuid($mock_settings['edit_access_cuid']),
|
||||
'Assert check access'
|
||||
);
|
||||
// - loginCheckEditAccessValidCuid
|
||||
$this->assertEquals(
|
||||
$expected['check_access_cuid'],
|
||||
$login_mock->loginCheckEditAccessValidCuid($mock_settings['edit_access_cuid']),
|
||||
'Assert check access cuid valid'
|
||||
);
|
||||
// - loginGetEditAccessCuidFromUid
|
||||
$this->assertEquals(
|
||||
$expected['check_access_cuid'],
|
||||
$login_mock->loginGetEditAccessCuidFromUid($mock_settings['edit_access_uid']),
|
||||
'Assert check access uid to cuid valid'
|
||||
);
|
||||
// - loginGetEditAccessCuidFromId
|
||||
$this->assertEquals(
|
||||
$expected['check_access_cuid'],
|
||||
$login_mock->loginGetEditAccessCuidFromUid($mock_settings['edit_access_id']),
|
||||
'Assert check access id to cuid valid'
|
||||
);
|
||||
// Deprecated
|
||||
// - loginCheckEditAccess
|
||||
$this->assertEquals(
|
||||
$expected['check_access'],
|
||||
@@ -1418,7 +1561,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$this->assertEquals(
|
||||
$expected['check_access_data'],
|
||||
$login_mock->loginGetEditAccessData(
|
||||
$mock_settings['edit_access_id'],
|
||||
$mock_settings['edit_access_uid'],
|
||||
$mock_settings['edit_access_data']
|
||||
),
|
||||
'Assert check access id data value valid'
|
||||
@@ -1449,15 +1592,16 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
// - loginCheckPermissions
|
||||
// - loginGetPermissionOkay
|
||||
} catch (\Exception $e) {
|
||||
// print "[E]: " . $e->getCode() . ", ERROR: " . $login_mock->loginGetLastErrorCode() . "/"
|
||||
// . ($expected['login_error'] ?? 0) . "\n";
|
||||
// print "AJAX: " . $login_mock->loginGetAjaxFlag() . "\n";
|
||||
// print "AJAX GLOBAL: " . ($GLOBALS['AJAX_PAGE'] ?? '{f}') . "\n";
|
||||
// print "Login error expext: " . ($expected['login_error'] ?? '{0}') . "\n";
|
||||
// if this is 3000, then we do further error checks
|
||||
/* print "[E]: " . $e->getCode() . ", ERROR: " . $login_mock->loginGetLastErrorCode() . "/"
|
||||
. ($expected['login_error'] ?? 0) . "\n";
|
||||
print "AJAX: " . $login_mock->loginGetAjaxFlag() . "\n";
|
||||
print "AJAX GLOBAL: " . ($GLOBALS['AJAX_PAGE'] ?? '{f}') . "\n";
|
||||
print "Login error expext: " . ($expected['login_error'] ?? '{0}') . "\n";
|
||||
print "POST exit: " . ($_POST['login_exit'] ?? '{0}') . "\n"; */
|
||||
// if this is 100, then we do further error checks
|
||||
if (
|
||||
$e->getCode() == 3000 ||
|
||||
!empty($_POST['login_exit']) && $_POST['login_exit'] == 3000
|
||||
$e->getCode() == 100 ||
|
||||
!empty($_POST['login_exit']) && $_POST['login_exit'] == 100
|
||||
) {
|
||||
$this->assertEquals(
|
||||
$expected['login_error'],
|
||||
@@ -1729,7 +1873,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
],
|
||||
20
|
||||
],
|
||||
'invalud search' => [
|
||||
'invalid search' => [
|
||||
12,
|
||||
'foo',
|
||||
[],
|
||||
@@ -1761,9 +1905,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -1774,13 +1918,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
);
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1860,9 +2019,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -1873,13 +2032,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
);
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -1933,9 +2107,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -1946,13 +2120,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
);
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
@@ -2014,9 +2203,9 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
/** @var \CoreLibs\Create\Session&MockObject */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
['startSession', 'checkActiveSession', 'sessionDestroy']
|
||||
['getSessionId', 'checkActiveSession', 'sessionDestroy']
|
||||
);
|
||||
$session_mock->method('startSession')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('getSessionId')->willReturn('ACLLOGINTEST34');
|
||||
$session_mock->method('checkActiveSession')->willReturn(true);
|
||||
$session_mock->method('sessionDestroy')->will(
|
||||
$this->returnCallback(function () {
|
||||
@@ -2027,13 +2216,28 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
);
|
||||
/** @var \CoreLibs\ACL\Login&MockObject */
|
||||
$login_mock = $this->getMockBuilder(\CoreLibs\ACL\Login::class)
|
||||
->setConstructorArgs([self::$db, self::$log, $session_mock, false])
|
||||
->setConstructorArgs([
|
||||
self::$db,
|
||||
self::$log,
|
||||
$session_mock,
|
||||
[
|
||||
'auto_login' => false,
|
||||
'default_acl_level' => 80,
|
||||
'logout_target' => '',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_domain' => 'admin',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
|
||||
. 'includes' . DIRECTORY_SEPARATOR
|
||||
. 'locale' . DIRECTORY_SEPARATOR,
|
||||
]
|
||||
])
|
||||
->onlyMethods(['loginTerminate'])
|
||||
->getMock();
|
||||
$login_mock->expects($this->any())
|
||||
->method('loginTerminate')
|
||||
->will(
|
||||
$this->returnCallback(function ($code) {
|
||||
$this->returnCallback(function ($message, $code) {
|
||||
throw new \Exception('', $code);
|
||||
})
|
||||
);
|
||||
File diff suppressed because it is too large
Load Diff
1
4dev/tests/ACL/includes
Symbolic link
1
4dev/tests/ACL/includes
Symbolic link
@@ -0,0 +1 @@
|
||||
../AAASetupData/includes
|
||||
@@ -13,6 +13,11 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsCheckColorsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function validateColorProvider(): array
|
||||
{
|
||||
/*
|
||||
@@ -321,7 +326,7 @@ final class CoreLibsCheckColorsTest extends TestCase
|
||||
*/
|
||||
public function testValidateColorException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
\CoreLibs\Check\Colors::validateColor('#ffffff', $flag);
|
||||
}
|
||||
}
|
||||
@@ -24,12 +24,12 @@ final class CoreLibsCheckEmailTest extends TestCase
|
||||
'get email regex invalid -1, will be 0' => [
|
||||
-1,
|
||||
"^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
. "(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,6}$"
|
||||
],
|
||||
'get email regex invalid 10, will be 0' => [
|
||||
10,
|
||||
"^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
. "(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,6}$"
|
||||
],
|
||||
'get email regex valid 1, will be 1' => [
|
||||
1,
|
||||
@@ -157,7 +157,7 @@ final class CoreLibsCheckEmailTest extends TestCase
|
||||
'error' => 0,
|
||||
'message' => 'Invalid email address',
|
||||
'regex' => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
. "(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,6}$"
|
||||
]
|
||||
],
|
||||
'error 1 will return double @ error' => [
|
||||
@@ -181,7 +181,7 @@ final class CoreLibsCheckEmailTest extends TestCase
|
||||
[
|
||||
'error' => 3,
|
||||
'message' => 'Invalid domain part after @ sign',
|
||||
'regex' => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
'regex' => "@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,6}$"
|
||||
]
|
||||
],
|
||||
'error 4 will be invalid domain' => [
|
||||
@@ -189,7 +189,7 @@ final class CoreLibsCheckEmailTest extends TestCase
|
||||
[
|
||||
'error' => 4,
|
||||
'message' => 'Invalid domain name part',
|
||||
'regex' => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\."
|
||||
'regex' => "@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\."
|
||||
]
|
||||
],
|
||||
'error 5 will be invalid domain top level only' => [
|
||||
@@ -197,7 +197,7 @@ final class CoreLibsCheckEmailTest extends TestCase
|
||||
[
|
||||
'error' => 5,
|
||||
'message' => 'Wrong domain top level part',
|
||||
'regex' => "\.([a-zA-Z]{2,6}){1}$"
|
||||
'regex' => "\.[a-zA-Z]{2,6}$"
|
||||
]
|
||||
],
|
||||
'error 6 will be domain double dot' => [
|
||||
@@ -28,10 +28,10 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
public function filesList(): array
|
||||
{
|
||||
return [
|
||||
['filename.txt', 'txt', 5],
|
||||
['filename.csv', 'csv', 15],
|
||||
['filename.tsv', 'tsv', 0],
|
||||
['file_does_not_exits', '', -1],
|
||||
['filename.txt', 'txt', 5, 'text/plain'],
|
||||
['filename.csv', 'csv', 15, 'text/csv'],
|
||||
['filename.tsv', 'tsv', 0, 'text/plain'],
|
||||
['file_does_not_exits', '', -1, ''],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -63,6 +63,15 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
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
|
||||
*
|
||||
@@ -115,6 +124,51 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
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__
|
||||
@@ -0,0 +1,404 @@
|
||||
<?php
|
||||
|
||||
// This code was created by Claude Sonnet 4
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Combined\ArrayHandler;
|
||||
|
||||
class CoreLibsCombinedArrayHandlerFindArraysMissingKeyTest extends TestCase
|
||||
{
|
||||
private const DATA_SEPARATOR = ':'; // Updated to match your class's separator
|
||||
|
||||
/**
|
||||
* Test finding missing single key when searching by value without specific key
|
||||
*/
|
||||
public function testFindMissingSingleKeyWithValueSearch()
|
||||
{
|
||||
$array = [
|
||||
'item1' => [
|
||||
'name' => 'John',
|
||||
'age' => 25
|
||||
// missing 'email' key
|
||||
],
|
||||
'item2' => [
|
||||
'name' => 'Jane',
|
||||
'age' => 30,
|
||||
'email' => 'jane@example.com'
|
||||
],
|
||||
'item3' => [
|
||||
'name' => 'John', // same value as item1
|
||||
'age' => 35,
|
||||
'email' => 'john2@example.com'
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'John', 'email');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals($array['item1'], $result[0]['content']);
|
||||
$this->assertEquals('item1', $result[0]['path']);
|
||||
$this->assertEquals(['email'], $result[0]['missing_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test finding missing single key when searching by specific key-value pair
|
||||
*/
|
||||
public function testFindMissingSingleKeyWithKeyValueSearch()
|
||||
{
|
||||
$array = [
|
||||
'user1' => [
|
||||
'id' => 1,
|
||||
'name' => 'Alice'
|
||||
// missing 'status' key
|
||||
],
|
||||
'user2' => [
|
||||
'id' => 2,
|
||||
'name' => 'Bob',
|
||||
'status' => 'active'
|
||||
],
|
||||
'user3' => [
|
||||
'id' => 1, // same id as user1
|
||||
'name' => 'Charlie',
|
||||
'status' => 'inactive'
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 1, 'status', 'id');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals($array['user1'], $result[0]['content']);
|
||||
$this->assertEquals('user1', $result[0]['path']);
|
||||
$this->assertEquals(['status'], $result[0]['missing_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test finding missing multiple keys
|
||||
*/
|
||||
public function testFindMissingMultipleKeys()
|
||||
{
|
||||
$array = [
|
||||
'record1' => [
|
||||
'name' => 'Test',
|
||||
'value' => 100
|
||||
// missing both 'date' and 'status' keys
|
||||
],
|
||||
'record2' => [
|
||||
'name' => 'Test',
|
||||
'value' => 200,
|
||||
'date' => '2023-01-01'
|
||||
// missing 'status' key
|
||||
],
|
||||
'record3' => [
|
||||
'name' => 'Test',
|
||||
'value' => 300,
|
||||
'date' => '2023-01-02',
|
||||
'status' => 'complete'
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'Test', ['date', 'status']);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
// First result should be record1 missing both keys
|
||||
$this->assertEquals($array['record1'], $result[0]['content']);
|
||||
$this->assertEquals('record1', $result[0]['path']);
|
||||
$this->assertContains('date', $result[0]['missing_key']);
|
||||
$this->assertContains('status', $result[0]['missing_key']);
|
||||
$this->assertCount(2, $result[0]['missing_key']);
|
||||
|
||||
// Second result should be record2 missing status key
|
||||
$this->assertEquals($array['record2'], $result[1]['content']);
|
||||
$this->assertEquals('record2', $result[1]['path']);
|
||||
$this->assertEquals(['status'], $result[1]['missing_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with nested arrays
|
||||
*/
|
||||
public function testFindMissingKeyInNestedArrays()
|
||||
{
|
||||
$array = [
|
||||
'section1' => [
|
||||
'items' => [
|
||||
'item1' => [
|
||||
'name' => 'Product A',
|
||||
'price' => 99.99
|
||||
// missing 'category' key
|
||||
],
|
||||
'item2' => [
|
||||
'name' => 'Product B',
|
||||
'price' => 149.99,
|
||||
'category' => 'electronics'
|
||||
]
|
||||
]
|
||||
],
|
||||
'section2' => [
|
||||
'data' => [
|
||||
'name' => 'Product A', // same name as nested item
|
||||
'category' => 'books'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'Product A', 'category');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals($array['section1']['items']['item1'], $result[0]['content']);
|
||||
$this->assertEquals('section1:items:item1', $result[0]['path']);
|
||||
$this->assertEquals(['category'], $result[0]['missing_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test when no arrays are missing the required key
|
||||
*/
|
||||
public function testNoMissingKeys()
|
||||
{
|
||||
$array = [
|
||||
'item1' => [
|
||||
'name' => 'John',
|
||||
'email' => 'john@example.com'
|
||||
],
|
||||
'item2' => [
|
||||
'name' => 'Jane',
|
||||
'email' => 'jane@example.com'
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'John', 'email');
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test when search value is not found in any array
|
||||
*/
|
||||
public function testSearchValueNotFound()
|
||||
{
|
||||
$array = [
|
||||
'item1' => [
|
||||
'name' => 'John',
|
||||
'age' => 25
|
||||
],
|
||||
'item2' => [
|
||||
'name' => 'Jane',
|
||||
'age' => 30
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'Bob', 'email');
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with different data types for search value
|
||||
*/
|
||||
public function testDifferentSearchValueTypes()
|
||||
{
|
||||
$array = [
|
||||
'item1' => [
|
||||
'active' => true,
|
||||
'count' => 5
|
||||
// missing 'label' key
|
||||
],
|
||||
'item2' => [
|
||||
'active' => false,
|
||||
'count' => 10,
|
||||
'label' => 'test'
|
||||
],
|
||||
'item3' => [
|
||||
'active' => true, // same boolean as item1
|
||||
'count' => 15,
|
||||
'label' => 'another'
|
||||
]
|
||||
];
|
||||
|
||||
// Test with boolean
|
||||
$result = ArrayHandler::findArraysMissingKey($array, true, 'label', 'active');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals('item1', $result[0]['path']);
|
||||
|
||||
// Test with integer
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 5, 'label', 'count');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals('item1', $result[0]['path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with empty array
|
||||
*/
|
||||
public function testEmptyArray()
|
||||
{
|
||||
$array = [];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'test', 'key');
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with array containing non-array values
|
||||
*/
|
||||
public function testMixedArrayTypes()
|
||||
{
|
||||
$array = [
|
||||
'string_value' => 'hello',
|
||||
'numeric_value' => 123,
|
||||
'array_value' => [
|
||||
'name' => 'test',
|
||||
// missing 'type' key
|
||||
],
|
||||
'another_array' => [
|
||||
'name' => 'test',
|
||||
'type' => 'example'
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'test', 'type');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals($array['array_value'], $result[0]['content']);
|
||||
$this->assertEquals('array_value', $result[0]['path']);
|
||||
$this->assertEquals(['type'], $result[0]['missing_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test path building with deeper nesting
|
||||
*/
|
||||
public function testDeepNestingPathBuilding()
|
||||
{
|
||||
$array = [
|
||||
'level1' => [
|
||||
'level2' => [
|
||||
'level3' => [
|
||||
'items' => [
|
||||
'target_item' => [
|
||||
'name' => 'deep_test',
|
||||
// missing 'required_field'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'deep_test', 'required_field');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals('level1:level2:level3:items:target_item', $result[0]['path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with custom path separator
|
||||
*/
|
||||
public function testCustomPathSeparator()
|
||||
{
|
||||
$array = [
|
||||
'level1' => [
|
||||
'level2' => [
|
||||
'item' => [
|
||||
'name' => 'test',
|
||||
// missing 'type' key
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'test', 'type', null, '/');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals('level1/level2/item', $result[0]['path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test default path separator behavior
|
||||
*/
|
||||
public function testDefaultPathSeparator()
|
||||
{
|
||||
$array = [
|
||||
'parent' => [
|
||||
'child' => [
|
||||
'name' => 'test',
|
||||
// missing 'value' key
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// Using default separator (should be ':')
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 'test', 'value');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals('parent:child', $result[0]['path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test different path separators don't affect search logic
|
||||
*/
|
||||
public function testPathSeparatorDoesNotAffectSearchLogic()
|
||||
{
|
||||
$array = [
|
||||
'section' => [
|
||||
'data' => [
|
||||
'id' => 123,
|
||||
'name' => 'item'
|
||||
// missing 'status'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// Test with different separators - results should be identical except for path
|
||||
$result1 = ArrayHandler::findArraysMissingKey($array, 123, 'status', 'id', ':');
|
||||
$result2 = ArrayHandler::findArraysMissingKey($array, 123, 'status', 'id', '.');
|
||||
$result3 = ArrayHandler::findArraysMissingKey($array, 123, 'status', 'id', '/');
|
||||
|
||||
$this->assertCount(1, $result1);
|
||||
$this->assertCount(1, $result2);
|
||||
$this->assertCount(1, $result3);
|
||||
|
||||
// Content and missing_key should be the same
|
||||
$this->assertEquals($result1[0]['content'], $result2[0]['content']);
|
||||
$this->assertEquals($result1[0]['content'], $result3[0]['content']);
|
||||
$this->assertEquals($result1[0]['missing_key'], $result2[0]['missing_key']);
|
||||
$this->assertEquals($result1[0]['missing_key'], $result3[0]['missing_key']);
|
||||
|
||||
// Paths should be different based on separator
|
||||
$this->assertEquals('section:data', $result1[0]['path']);
|
||||
$this->assertEquals('section.data', $result2[0]['path']);
|
||||
$this->assertEquals('section/data', $result3[0]['path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test type checking
|
||||
*/
|
||||
public function testStrictTypeChecking()
|
||||
{
|
||||
$array = [
|
||||
'item1' => [
|
||||
'id' => '123', // string
|
||||
'name' => 'test'
|
||||
// missing 'status'
|
||||
],
|
||||
'item2' => [
|
||||
'id' => 123, // integer
|
||||
'name' => 'test2',
|
||||
'status' => 'active'
|
||||
]
|
||||
];
|
||||
|
||||
// Search for integer 123 - should only match item2
|
||||
$result = ArrayHandler::findArraysMissingKey($array, 123, 'status', 'id');
|
||||
$this->assertEmpty($result); // item2 has the status key
|
||||
|
||||
// Search for string '123' - should only match item1
|
||||
$result = ArrayHandler::findArraysMissingKey($array, '123', 'status', 'id');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals('item1', $result[0]['path']);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
|
||||
// This code was created by Claude Sonnet 4
|
||||
// modification for value checks with assertEqualsCanonicalizing
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Combined\ArrayHandler;
|
||||
|
||||
class CoreLibsCombinedArrayHandlerKsortArrayTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test basic ascending sort (default behavior)
|
||||
*/
|
||||
public function testKsortArrayBasicAscending(): void
|
||||
{
|
||||
$input = [
|
||||
'zebra' => 'value1',
|
||||
'apple' => 'value2',
|
||||
'banana' => 'value3',
|
||||
'cherry' => 'value4'
|
||||
];
|
||||
|
||||
$expected = [
|
||||
'apple' => 'value2',
|
||||
'banana' => 'value3',
|
||||
'cherry' => 'value4',
|
||||
'zebra' => 'value1'
|
||||
];
|
||||
|
||||
$result = ArrayHandler::ksortArray($input);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals(array_keys($expected), array_keys($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test descending sort with reverse=true
|
||||
*/
|
||||
public function testKsortArrayDescending(): void
|
||||
{
|
||||
$input = [
|
||||
'zebra' => 'value1',
|
||||
'apple' => 'value2',
|
||||
'banana' => 'value3',
|
||||
'cherry' => 'value4'
|
||||
];
|
||||
|
||||
$expected = [
|
||||
'zebra' => 'value1',
|
||||
'cherry' => 'value4',
|
||||
'banana' => 'value3',
|
||||
'apple' => 'value2'
|
||||
];
|
||||
|
||||
$result = ArrayHandler::ksortArray($input, false, true);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals(array_keys($expected), array_keys($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case-insensitive ascending sort
|
||||
*/
|
||||
public function testKsortArrayCaseInsensitiveAscending(): void
|
||||
{
|
||||
$input = [
|
||||
'Zebra' => 'value1',
|
||||
'apple' => 'value2',
|
||||
'Banana' => 'value3',
|
||||
'cherry' => 'value4'
|
||||
];
|
||||
|
||||
$expected = [
|
||||
'apple' => 'value2',
|
||||
'Banana' => 'value3',
|
||||
'cherry' => 'value4',
|
||||
'Zebra' => 'value1'
|
||||
];
|
||||
|
||||
$result = ArrayHandler::ksortArray($input, true);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals(array_keys($expected), array_keys($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case-insensitive descending sort
|
||||
*/
|
||||
public function testKsortArrayCaseInsensitiveDescending(): void
|
||||
{
|
||||
$input = [
|
||||
'Zebra' => 'value1',
|
||||
'apple' => 'value2',
|
||||
'Banana' => 'value3',
|
||||
'cherry' => 'value4'
|
||||
];
|
||||
|
||||
$expected = [
|
||||
'Zebra' => 'value1',
|
||||
'cherry' => 'value4',
|
||||
'Banana' => 'value3',
|
||||
'apple' => 'value2'
|
||||
];
|
||||
|
||||
$result = ArrayHandler::ksortArray($input, true, true);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals(array_keys($expected), array_keys($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with mixed case keys to verify case sensitivity behavior
|
||||
*/
|
||||
public function testKsortArrayCaseSensitivityComparison(): void
|
||||
{
|
||||
$input = [
|
||||
'B' => 'value1',
|
||||
'a' => 'value2',
|
||||
'C' => 'value3',
|
||||
'b' => 'value4'
|
||||
];
|
||||
|
||||
// Case-sensitive sort (uppercase comes before lowercase in ASCII)
|
||||
$expectedCaseSensitive = [
|
||||
'B' => 'value1',
|
||||
'C' => 'value3',
|
||||
'a' => 'value2',
|
||||
'b' => 'value4'
|
||||
];
|
||||
|
||||
// Case-insensitive sort
|
||||
$expectedCaseInsensitive = [
|
||||
'a' => 'value2',
|
||||
'B' => 'value1',
|
||||
'b' => 'value4',
|
||||
'C' => 'value3'
|
||||
];
|
||||
|
||||
$resultCaseSensitive = ArrayHandler::ksortArray($input, false);
|
||||
$resultCaseInsensitive = ArrayHandler::ksortArray($input, true);
|
||||
|
||||
$this->assertEquals($expectedCaseSensitive, $resultCaseSensitive);
|
||||
$this->assertEquals($expectedCaseInsensitive, $resultCaseInsensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with numeric string keys
|
||||
*/
|
||||
public function testKsortArrayNumericStringKeys(): void
|
||||
{
|
||||
$input = [
|
||||
'10' => 'value1',
|
||||
'2' => 'value2',
|
||||
'1' => 'value3',
|
||||
'20' => 'value4'
|
||||
];
|
||||
|
||||
// String comparison, not numeric
|
||||
$expected = [
|
||||
'1' => 'value3',
|
||||
'10' => 'value1',
|
||||
'2' => 'value2',
|
||||
'20' => 'value4'
|
||||
];
|
||||
|
||||
$result = ArrayHandler::ksortArray($input);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with special characters in keys
|
||||
*/
|
||||
public function testKsortArraySpecialCharacters(): void
|
||||
{
|
||||
$input = [
|
||||
'key_with_underscore' => 'value1',
|
||||
'key-with-dash' => 'value2',
|
||||
'key.with.dot' => 'value3',
|
||||
'key with space' => 'value4',
|
||||
'keyWithCamelCase' => 'value5'
|
||||
];
|
||||
|
||||
$result = ArrayHandler::ksortArray($input);
|
||||
|
||||
// Verify it doesn't throw an error and maintains all keys
|
||||
$this->assertCount(5, $result);
|
||||
$this->assertArrayHasKey('key_with_underscore', $result);
|
||||
$this->assertArrayHasKey('key-with-dash', $result);
|
||||
$this->assertArrayHasKey('key.with.dot', $result);
|
||||
$this->assertArrayHasKey('key with space', $result);
|
||||
$this->assertArrayHasKey('keyWithCamelCase', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with empty array
|
||||
*/
|
||||
public function testKsortArrayEmpty(): void
|
||||
{
|
||||
$input = [];
|
||||
$result = ArrayHandler::ksortArray($input);
|
||||
$this->assertEquals([], $result);
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with single element array
|
||||
*/
|
||||
public function testKsortArraySingleElement(): void
|
||||
{
|
||||
$input = ['onlykey' => 'onlyvalue'];
|
||||
$result = ArrayHandler::ksortArray($input);
|
||||
$this->assertEquals($input, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that original array is not modified (function returns new array)
|
||||
*/
|
||||
public function testKsortArrayDoesNotModifyOriginal(): void
|
||||
{
|
||||
$original = [
|
||||
'zebra' => 'value1',
|
||||
'apple' => 'value2',
|
||||
'banana' => 'value3'
|
||||
];
|
||||
|
||||
$originalCopy = $original; // Keep a copy for comparison
|
||||
$result = ArrayHandler::ksortArray($original);
|
||||
|
||||
// Original array should remain unchanged
|
||||
$this->assertEquals($originalCopy, $original);
|
||||
$this->assertNotEquals(array_keys($original), array_keys($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with complex mixed data types as values
|
||||
*/
|
||||
public function testKsortArrayMixedValueTypes(): void
|
||||
{
|
||||
$input = [
|
||||
'string_key' => 'string_value',
|
||||
'array_key' => ['nested', 'array'],
|
||||
'int_key' => 42,
|
||||
'bool_key' => true,
|
||||
'null_key' => null
|
||||
];
|
||||
|
||||
$result = ArrayHandler::ksortArray($input);
|
||||
|
||||
// Check that all keys are preserved and sorted
|
||||
$expectedKeys = ['array_key', 'bool_key', 'int_key', 'null_key', 'string_key'];
|
||||
$this->assertEquals($expectedKeys, array_keys($result));
|
||||
|
||||
// Check that values are preserved correctly
|
||||
$this->assertEquals('string_value', $result['string_key']);
|
||||
$this->assertEquals(['nested', 'array'], $result['array_key']);
|
||||
$this->assertEquals(42, $result['int_key']);
|
||||
$this->assertTrue($result['bool_key']);
|
||||
$this->assertNull($result['null_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test all parameter combinations
|
||||
*/
|
||||
public function testKsortArrayAllParameterCombinations(): void
|
||||
{
|
||||
$input = [
|
||||
'Delta' => 'value1',
|
||||
'alpha' => 'value2',
|
||||
'Charlie' => 'value3',
|
||||
'bravo' => 'value4'
|
||||
];
|
||||
|
||||
// Test all 4 combinations
|
||||
$result1 = ArrayHandler::ksortArray($input, false, false); // default
|
||||
$result2 = ArrayHandler::ksortArray($input, false, true); // reverse only
|
||||
$result3 = ArrayHandler::ksortArray($input, true, false); // lowercase only
|
||||
$result4 = ArrayHandler::ksortArray($input, true, true); // both
|
||||
|
||||
// Each should produce different ordering
|
||||
$this->assertNotEquals(array_keys($result1), array_keys($result2));
|
||||
$this->assertNotEquals(array_keys($result1), array_keys($result3));
|
||||
$this->assertNotEquals(array_keys($result1), array_keys($result4));
|
||||
$this->assertNotEquals(array_keys($result2), array_keys($result3));
|
||||
$this->assertNotEquals(array_keys($result2), array_keys($result4));
|
||||
$this->assertNotEquals(array_keys($result3), array_keys($result4));
|
||||
|
||||
// But all should have same keys and values, just different order
|
||||
$this->assertEqualsCanonicalizing(array_values($input), array_values($result1));
|
||||
$this->assertEqualsCanonicalizing(array_values($input), array_values($result2));
|
||||
$this->assertEqualsCanonicalizing(array_values($input), array_values($result3));
|
||||
$this->assertEqualsCanonicalizing(array_values($input), array_values($result4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for comprehensive testing
|
||||
*/
|
||||
public function sortingParametersProvider(): array
|
||||
{
|
||||
return [
|
||||
'default' => [false, false],
|
||||
'reverse' => [false, true],
|
||||
'lowercase' => [true, false],
|
||||
'lowercase_reverse' => [true, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that function works with all parameter combinations using data provider
|
||||
*
|
||||
* @dataProvider sortingParametersProvider
|
||||
*/
|
||||
public function testKsortArrayWithDataProvider(bool $lowerCase, bool $reverse): void
|
||||
{
|
||||
$input = [
|
||||
'Zebra' => 'animal1',
|
||||
'apple' => 'fruit1',
|
||||
'Banana' => 'fruit2',
|
||||
'cat' => 'animal2'
|
||||
];
|
||||
|
||||
$result = ArrayHandler::ksortArray($input, $lowerCase, $reverse);
|
||||
|
||||
// Basic assertions that apply to all combinations
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertArrayHasKey('Zebra', $result);
|
||||
$this->assertArrayHasKey('apple', $result);
|
||||
$this->assertArrayHasKey('Banana', $result);
|
||||
$this->assertArrayHasKey('cat', $result);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -0,0 +1,383 @@
|
||||
<?php
|
||||
|
||||
// created by Claude Sonnet 4
|
||||
|
||||
// testRecursiveSearchWithFlatResult had wrong retunr count
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Combined\ArrayHandler;
|
||||
|
||||
class CoreLibsCombinedArrayHandlerSelectArrayFromOptionTest extends TestCase
|
||||
{
|
||||
private array $testData;
|
||||
private array $nestedTestData;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->testData = [
|
||||
'item1' => [
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
'status' => 'active',
|
||||
'score' => 85.5
|
||||
],
|
||||
'item2' => [
|
||||
'name' => 'jane',
|
||||
'age' => 30,
|
||||
'status' => 'inactive',
|
||||
'score' => 92.0
|
||||
],
|
||||
'item3' => [
|
||||
'name' => 'Bob',
|
||||
'age' => 25,
|
||||
'status' => 'active',
|
||||
'score' => 78.3
|
||||
],
|
||||
'item4' => [
|
||||
'name' => 'Alice',
|
||||
'age' => 35,
|
||||
'status' => 'pending',
|
||||
'score' => 88.7
|
||||
]
|
||||
];
|
||||
|
||||
$this->nestedTestData = [
|
||||
'level1_a' => [
|
||||
'name' => 'Level1A',
|
||||
'type' => 'parent',
|
||||
'children' => [
|
||||
'child1' => [
|
||||
'name' => 'Child1',
|
||||
'type' => 'child',
|
||||
'active' => true
|
||||
],
|
||||
'child2' => [
|
||||
'name' => 'Child2',
|
||||
'type' => 'child',
|
||||
'active' => false
|
||||
]
|
||||
]
|
||||
],
|
||||
'level1_b' => [
|
||||
'name' => 'Level1B',
|
||||
'type' => 'parent',
|
||||
'children' => [
|
||||
'child3' => [
|
||||
'name' => 'Child3',
|
||||
'type' => 'child',
|
||||
'active' => true,
|
||||
'nested' => [
|
||||
'deep1' => [
|
||||
'name' => 'Deep1',
|
||||
'type' => 'deep',
|
||||
'active' => true
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'item5' => [
|
||||
'name' => 'Direct',
|
||||
'type' => 'child',
|
||||
'active' => false
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function testEmptyArrayReturnsEmpty(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption([], 'name', 'John');
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testBasicStringSearch(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption($this->testData, 'name', 'John');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertArrayHasKey('item1', $result);
|
||||
$this->assertEquals('John', $result['item1']['name']);
|
||||
}
|
||||
|
||||
public function testBasicIntegerSearch(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption($this->testData, 'age', 25);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertArrayHasKey('item1', $result);
|
||||
$this->assertArrayHasKey('item3', $result);
|
||||
}
|
||||
|
||||
public function testBasicFloatSearch(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption($this->testData, 'score', 85.5);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertArrayHasKey('item1', $result);
|
||||
$this->assertEquals(85.5, $result['item1']['score']);
|
||||
}
|
||||
|
||||
public function testBasicBooleanSearch(): void
|
||||
{
|
||||
$data = [
|
||||
'item1' => ['enabled' => true, 'name' => 'Test1'],
|
||||
'item2' => ['enabled' => false, 'name' => 'Test2'],
|
||||
'item3' => ['enabled' => true, 'name' => 'Test3']
|
||||
];
|
||||
|
||||
$result = ArrayHandler::selectArrayFromOption($data, 'enabled', true);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertArrayHasKey('item1', $result);
|
||||
$this->assertArrayHasKey('item3', $result);
|
||||
}
|
||||
|
||||
public function testStrictComparison(): void
|
||||
{
|
||||
$data = [
|
||||
'item1' => ['value' => '25', 'name' => 'String25'],
|
||||
'item2' => ['value' => 25, 'name' => 'Int25'],
|
||||
'item3' => ['value' => 25.0, 'name' => 'Float25']
|
||||
];
|
||||
|
||||
// Non-strict should match all
|
||||
$nonStrictResult = ArrayHandler::selectArrayFromOption($data, 'value', 25, false);
|
||||
$this->assertCount(3, $nonStrictResult);
|
||||
|
||||
// Strict should only match exact type
|
||||
$strictResult = ArrayHandler::selectArrayFromOption($data, 'value', 25, true);
|
||||
$this->assertCount(1, $strictResult);
|
||||
$this->assertArrayHasKey('item2', $strictResult);
|
||||
}
|
||||
|
||||
public function testCaseInsensitiveSearch(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption($this->testData, 'name', 'JANE', false, true);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertArrayHasKey('item2', $result);
|
||||
$this->assertEquals('jane', $result['item2']['name']);
|
||||
}
|
||||
|
||||
public function testCaseSensitiveSearch(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption($this->testData, 'name', 'JANE', false, false);
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testRecursiveSearchWithFlatResult(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption(
|
||||
$this->nestedTestData,
|
||||
'type',
|
||||
'child',
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
':*'
|
||||
);
|
||||
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertArrayHasKey('level1_a:*children:*child1', $result);
|
||||
$this->assertArrayHasKey('level1_a:*children:*child2', $result);
|
||||
$this->assertArrayHasKey('level1_b:*children:*child3', $result);
|
||||
$this->assertArrayHasKey('item5', $result);
|
||||
}
|
||||
|
||||
public function testRecursiveSearchWithNestedResult(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption(
|
||||
$this->nestedTestData,
|
||||
'type',
|
||||
'child',
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertArrayHasKey('level1_a', $result);
|
||||
$this->assertArrayHasKey('level1_b', $result);
|
||||
$this->assertArrayHasKey('item5', $result);
|
||||
|
||||
// Check nested structure is preserved
|
||||
$this->assertArrayHasKey('children', $result['level1_a']);
|
||||
$this->assertArrayHasKey('child1', $result['level1_a']['children']);
|
||||
$this->assertArrayHasKey('child2', $result['level1_a']['children']);
|
||||
}
|
||||
|
||||
public function testRecursiveSearchDeepNesting(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption(
|
||||
$this->nestedTestData,
|
||||
'type',
|
||||
'deep',
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
':*'
|
||||
);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertArrayHasKey('level1_b:*children:*child3:*nested:*deep1', $result);
|
||||
$this->assertEquals('Deep1', $result['level1_b:*children:*child3:*nested:*deep1']['name']);
|
||||
}
|
||||
|
||||
public function testCustomFlatSeparator(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption(
|
||||
$this->nestedTestData,
|
||||
'type',
|
||||
'child',
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
'|'
|
||||
);
|
||||
|
||||
$this->assertArrayHasKey('level1_a|children|child1', $result);
|
||||
$this->assertArrayHasKey('level1_a|children|child2', $result);
|
||||
$this->assertArrayHasKey('level1_b|children|child3', $result);
|
||||
}
|
||||
|
||||
public function testNonRecursiveSearch(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption(
|
||||
$this->nestedTestData,
|
||||
'type',
|
||||
'child',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
// Should only find direct matches, not nested ones
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertArrayHasKey('item5', $result);
|
||||
}
|
||||
|
||||
public function testNoMatchesFound(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption($this->testData, 'name', 'NonExistent');
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testMissingLookupKey(): void
|
||||
{
|
||||
$result = ArrayHandler::selectArrayFromOption($this->testData, 'nonexistent_key', 'value');
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testCombinedStrictAndCaseInsensitive(): void
|
||||
{
|
||||
$data = [
|
||||
'item1' => ['name' => 'Test', 'id' => '123'],
|
||||
'item2' => ['name' => 'test', 'id' => 123],
|
||||
'item3' => ['name' => 'TEST', 'id' => '123']
|
||||
];
|
||||
|
||||
// Case insensitive but strict type matching
|
||||
$result = ArrayHandler::selectArrayFromOption($data, 'id', '123', true, true);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertArrayHasKey('item1', $result);
|
||||
$this->assertArrayHasKey('item3', $result);
|
||||
}
|
||||
|
||||
public function testBooleanWithCaseInsensitive(): void
|
||||
{
|
||||
$data = [
|
||||
'item1' => ['active' => true, 'name' => 'Test1'],
|
||||
'item2' => ['active' => false, 'name' => 'Test2']
|
||||
];
|
||||
|
||||
// Case insensitive flag should not affect boolean comparison
|
||||
$result = ArrayHandler::selectArrayFromOption($data, 'active', true, false, true);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertArrayHasKey('item1', $result);
|
||||
}
|
||||
|
||||
public function testArrayWithNumericKeys(): void
|
||||
{
|
||||
$data = [
|
||||
0 => ['name' => 'First', 'type' => 'test'],
|
||||
1 => ['name' => 'Second', 'type' => 'test'],
|
||||
2 => ['name' => 'Third', 'type' => 'other']
|
||||
];
|
||||
|
||||
$result = ArrayHandler::selectArrayFromOption($data, 'type', 'test');
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertArrayHasKey(0, $result);
|
||||
$this->assertArrayHasKey(1, $result);
|
||||
}
|
||||
|
||||
public function testRecursiveWithMixedKeyTypes(): void
|
||||
{
|
||||
$data = [
|
||||
'string_key' => [
|
||||
'name' => 'Parent',
|
||||
'type' => 'parent',
|
||||
0 => [
|
||||
'name' => 'Child0',
|
||||
'type' => 'child'
|
||||
],
|
||||
'child_key' => [
|
||||
'name' => 'ChildKey',
|
||||
'type' => 'child'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::selectArrayFromOption($data, 'type', 'child', false, false, true, true, ':*');
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertArrayHasKey('string_key:*0', $result);
|
||||
$this->assertArrayHasKey('string_key:*child_key', $result);
|
||||
}
|
||||
|
||||
public function testAllParametersCombined(): void
|
||||
{
|
||||
$data = [
|
||||
'parent1' => [
|
||||
'name' => 'Parent1',
|
||||
'status' => 'ACTIVE',
|
||||
'children' => [
|
||||
'child1' => [
|
||||
'name' => 'Child1',
|
||||
'status' => 'active'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$result = ArrayHandler::selectArrayFromOption(
|
||||
$data,
|
||||
'status',
|
||||
'active',
|
||||
false, // not strict
|
||||
true, // case insensitive
|
||||
true, // recursive
|
||||
true, // flat result
|
||||
'|' // custom separator
|
||||
);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertArrayHasKey('parent1', $result);
|
||||
$this->assertArrayHasKey('parent1|children|child1', $result);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
|
||||
// This code was created by Claude Sonnet 4
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Combined\ArrayHandler;
|
||||
|
||||
class CoreLibsCombinedArrayHandlerSortArrayTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test basic ascending sort without maintaining keys
|
||||
*/
|
||||
public function testBasicAscendingSort()
|
||||
{
|
||||
$input = [3, 1, 4, 1, 5, 9];
|
||||
$expected = [1, 1, 3, 4, 5, 9];
|
||||
|
||||
$result = ArrayHandler::sortArray($input);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals(array_keys($expected), array_keys($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic descending sort without maintaining keys
|
||||
*/
|
||||
public function testBasicDescendingSort()
|
||||
{
|
||||
$input = [3, 1, 4, 1, 5, 9];
|
||||
$expected = [9, 5, 4, 3, 1, 1];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, false, true);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals(array_keys($expected), array_keys($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ascending sort with key maintenance
|
||||
*/
|
||||
public function testAscendingSortWithKeyMaintenance()
|
||||
{
|
||||
$input = ['c' => 3, 'a' => 1, 'd' => 4, 'b' => 1, 'e' => 5];
|
||||
$expected = ['a' => 1, 'b' => 1, 'c' => 3, 'd' => 4, 'e' => 5];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, false, false, true);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test descending sort with key maintenance
|
||||
*/
|
||||
public function testDescendingSortWithKeyMaintenance()
|
||||
{
|
||||
$input = ['c' => 3, 'a' => 1, 'd' => 4, 'b' => 1, 'e' => 5];
|
||||
$expected = ['e' => 5, 'd' => 4, 'c' => 3, 'a' => 1, 'b' => 1];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, false, true, true);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test string sorting with lowercase conversion
|
||||
*/
|
||||
public function testStringLowerCaseSort()
|
||||
{
|
||||
$input = ['Banana', 'apple', 'Cherry', 'date'];
|
||||
$expected = ['apple', 'Banana', 'Cherry', 'date'];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, true);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test string sorting with lowercase conversion in reverse
|
||||
*/
|
||||
public function testStringLowerCaseSortReverse()
|
||||
{
|
||||
$input = ['Banana', 'apple', 'Cherry', 'date'];
|
||||
$expected = ['date', 'Cherry', 'Banana', 'apple'];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, true, true);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test string sorting with lowercase conversion and key maintenance
|
||||
*/
|
||||
public function testStringLowerCaseSortWithKeys()
|
||||
{
|
||||
$input = ['b' => 'Banana', 'a' => 'apple', 'c' => 'Cherry', 'd' => 'date'];
|
||||
$expected = ['a' => 'apple', 'b' => 'Banana', 'c' => 'Cherry', 'd' => 'date'];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, true, false, true);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test string sorting with lowercase conversion, reverse, and key maintenance
|
||||
*/
|
||||
public function testStringLowerCaseSortReverseWithKeys()
|
||||
{
|
||||
$input = ['b' => 'Banana', 'a' => 'apple', 'c' => 'Cherry', 'd' => 'date'];
|
||||
$expected = ['d' => 'date', 'c' => 'Cherry', 'b' => 'Banana', 'a' => 'apple'];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, true, true, true);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test numeric string sorting with SORT_NUMERIC flag
|
||||
*/
|
||||
public function testNumericStringSorting()
|
||||
{
|
||||
$input = ['10', '2', '1', '20'];
|
||||
$expected = ['1', '2', '10', '20'];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, false, false, false, SORT_NUMERIC);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test natural string sorting with SORT_NATURAL flag
|
||||
*/
|
||||
public function testNaturalStringSorting()
|
||||
{
|
||||
$input = ['img1.png', 'img10.png', 'img2.png', 'img20.png'];
|
||||
$expected = ['img1.png', 'img2.png', 'img10.png', 'img20.png'];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, false, false, false, SORT_NATURAL);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with empty array
|
||||
*/
|
||||
public function testEmptyArray()
|
||||
{
|
||||
$input = [];
|
||||
$expected = [];
|
||||
|
||||
$result = ArrayHandler::sortArray($input);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with single element array
|
||||
*/
|
||||
public function testSingleElementArray()
|
||||
{
|
||||
$input = [42];
|
||||
$expected = [42];
|
||||
|
||||
$result = ArrayHandler::sortArray($input);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with array containing null values
|
||||
*/
|
||||
public function testArrayWithNullValues()
|
||||
{
|
||||
$input = [3, null, 1, null, 2];
|
||||
$expected = [null, null, 1, 2, 3];
|
||||
|
||||
$result = ArrayHandler::sortArray($input);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with mixed data types
|
||||
*/
|
||||
public function testMixedDataTypes()
|
||||
{
|
||||
$input = [3, '1', 4.5, '2', 1];
|
||||
|
||||
$result = ArrayHandler::sortArray($input);
|
||||
|
||||
// Should sort according to PHP's natural comparison rules
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(5, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that original array is not modified (immutability)
|
||||
*/
|
||||
public function testOriginalArrayNotModified()
|
||||
{
|
||||
$original = [3, 1, 4, 1, 5, 9];
|
||||
$input = $original;
|
||||
|
||||
$result = ArrayHandler::sortArray($input);
|
||||
|
||||
$this->assertEquals($original, $input);
|
||||
$this->assertNotEquals($input, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case sensitivity without lowercase flag
|
||||
*/
|
||||
public function testCaseSensitivityWithoutLowercase()
|
||||
{
|
||||
$input = ['Banana', 'apple', 'Cherry'];
|
||||
|
||||
$result = ArrayHandler::sortArray($input);
|
||||
|
||||
// Capital letters should come before lowercase in ASCII sort
|
||||
$this->assertEquals('Banana', $result[0]);
|
||||
$this->assertEquals('Cherry', $result[1]);
|
||||
$this->assertEquals('apple', $result[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test all parameters combination
|
||||
*/
|
||||
public function testAllParametersCombination()
|
||||
{
|
||||
$input = ['z' => 'Zebra', 'a' => 'apple', 'b' => 'Banana'];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, true, true, true, SORT_REGULAR);
|
||||
|
||||
// Should be sorted by lowercase, reversed, with keys maintained
|
||||
$keys = array_keys($result);
|
||||
$values = array_values($result);
|
||||
|
||||
$this->assertEquals(['z', 'b', 'a'], $keys);
|
||||
$this->assertEquals(['Zebra', 'Banana', 'apple'], $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test floating point numbers
|
||||
*/
|
||||
public function testFloatingPointNumbers()
|
||||
{
|
||||
$input = [3.14, 2.71, 1.41, 1.73];
|
||||
$expected = [1.41, 1.73, 2.71, 3.14];
|
||||
|
||||
$result = ArrayHandler::sortArray($input);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with duplicate values and key maintenance
|
||||
*/
|
||||
public function testDuplicateValuesWithKeyMaintenance()
|
||||
{
|
||||
$input = ['first' => 1, 'second' => 2, 'third' => 1, 'fourth' => 2];
|
||||
|
||||
$result = ArrayHandler::sortArray($input, false, false, true);
|
||||
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertEquals([1, 1, 2, 2], array_values($result));
|
||||
// Keys should be preserved
|
||||
$this->assertArrayHasKey('first', $result);
|
||||
$this->assertArrayHasKey('second', $result);
|
||||
$this->assertArrayHasKey('third', $result);
|
||||
$this->assertArrayHasKey('fourth', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for comprehensive parameter testing
|
||||
*/
|
||||
public function sortParameterProvider(): array
|
||||
{
|
||||
return [
|
||||
'basic_ascending' => [
|
||||
[3, 1, 4, 2],
|
||||
false, false, false, SORT_REGULAR,
|
||||
[1, 2, 3, 4]
|
||||
],
|
||||
'basic_descending' => [
|
||||
[3, 1, 4, 2],
|
||||
false, true, false, SORT_REGULAR,
|
||||
[4, 3, 2, 1]
|
||||
],
|
||||
'lowercase_ascending' => [
|
||||
['Banana', 'apple', 'Cherry'],
|
||||
true, false, false, SORT_REGULAR,
|
||||
['apple', 'Banana', 'Cherry']
|
||||
],
|
||||
'lowercase_descending' => [
|
||||
['Banana', 'apple', 'Cherry'],
|
||||
true, true, false, SORT_REGULAR,
|
||||
['Cherry', 'Banana', 'apple']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test various parameter combinations using data provider
|
||||
*
|
||||
* @dataProvider sortParameterProvider
|
||||
*/
|
||||
public function testSortParameterCombinations(
|
||||
array $input,
|
||||
bool $lowercase,
|
||||
bool $reverse,
|
||||
bool $maintainKeys,
|
||||
int $params,
|
||||
array $expected
|
||||
) {
|
||||
$result = ArrayHandler::sortArray($input, $lowercase, $reverse, $maintainKeys, $params);
|
||||
|
||||
if (!$maintainKeys) {
|
||||
$this->assertEquals($expected, $result);
|
||||
} else {
|
||||
$this->assertEquals($expected, array_values($result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
2383
4dev/tests/Combined/CoreLibsCombinedArrayHandlerTest.php
Normal file
2383
4dev/tests/Combined/CoreLibsCombinedArrayHandlerTest.php
Normal file
File diff suppressed because it is too large
Load Diff
1608
4dev/tests/Combined/CoreLibsCombinedDateTimeTest.php
Normal file
1608
4dev/tests/Combined/CoreLibsCombinedDateTimeTest.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -40,7 +40,7 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
4 => '1.00 KB',
|
||||
5 => '1.02KiB',
|
||||
],
|
||||
'invalud string number' => [
|
||||
'invalid string number' => [
|
||||
0 => '1024 MB',
|
||||
1 => '1024 MB',
|
||||
2 => '1024 MB',
|
||||
@@ -123,47 +123,6 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byteStringProvider(): array
|
||||
{
|
||||
return [
|
||||
'negative number' => [
|
||||
0 => '-117.42 MB',
|
||||
1 => -123123794,
|
||||
2 => -117420000,
|
||||
],
|
||||
'megabyte' => [
|
||||
0 => '242.98 MB',
|
||||
1 => 254782996,
|
||||
2 => 242980000
|
||||
],
|
||||
'megabyte si' => [
|
||||
0 => '254.78 MiB',
|
||||
1 => 267156193,
|
||||
2 => 254780000
|
||||
],
|
||||
'petabyte' => [
|
||||
0 => '1 EiB',
|
||||
1 => 1152921504606846976,
|
||||
2 => 1000000000000000000,
|
||||
],
|
||||
'max int' => [
|
||||
0 => '8 EB',
|
||||
1 => -9223372036854775807 - 1,
|
||||
2 => 8000000000000000000,
|
||||
],
|
||||
'exabyte, overflow' => [
|
||||
0 => '867.36EB',
|
||||
1 => 3873816255479021568,
|
||||
2 => 363028535651074048,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -180,7 +139,7 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
* @return void
|
||||
*/
|
||||
public function testHumanReadableByteFormat(
|
||||
$input,
|
||||
string|int|float $input,
|
||||
string $expected,
|
||||
string $expected_si,
|
||||
string $expected_no_space,
|
||||
@@ -217,6 +176,73 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byteStringProvider(): array
|
||||
{
|
||||
return [
|
||||
'negative number' => [
|
||||
0 => '-117.42 MB',
|
||||
1 => -123123794,
|
||||
2 => -117420000,
|
||||
3 => "-123123793",
|
||||
4 => "-117420000",
|
||||
5 => null,
|
||||
],
|
||||
'megabyte' => [
|
||||
0 => '242.98 MB',
|
||||
1 => 254782996,
|
||||
2 => 242980000,
|
||||
3 => "254782996",
|
||||
4 => "242980000",
|
||||
5 => null,
|
||||
],
|
||||
'megabyte si' => [
|
||||
0 => '254.78 MiB',
|
||||
1 => 267156193,
|
||||
2 => 254780000,
|
||||
3 => "267156193",
|
||||
4 => "254780000",
|
||||
5 => null,
|
||||
],
|
||||
'petabyte' => [
|
||||
0 => '1 EiB',
|
||||
1 => 1152921504606846976,
|
||||
2 => 1000000000000000000,
|
||||
3 => "1152921504606846976",
|
||||
4 => "1000000000000000000",
|
||||
5 => null,
|
||||
],
|
||||
'max int' => [
|
||||
0 => '8 EB',
|
||||
1 => 0,
|
||||
2 => 0,
|
||||
3 => "9223372036854775808",
|
||||
4 => "8000000000000000000",
|
||||
5 => \LengthException::class,
|
||||
],
|
||||
'exabyte, overflow' => [
|
||||
0 => '867.36EB',
|
||||
1 => 0,
|
||||
2 => 0,
|
||||
3 => "999997996235794808832",
|
||||
4 => "867360000000000000000",
|
||||
5 => \LengthException::class,
|
||||
],
|
||||
'huge exabyte, overflow' => [
|
||||
0 => '1000EB',
|
||||
1 => 0,
|
||||
2 => 0,
|
||||
3 => "1152921504606846976000",
|
||||
4 => "1000000000000000000000",
|
||||
5 => \LengthException::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -227,10 +253,22 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
* @param string|int|float $input
|
||||
* @param string|int|float $expected
|
||||
* @param string|int|float $expected_si
|
||||
* @param string|int|float $expected_string
|
||||
* @param string|int|float $expected_string_si
|
||||
* @param ?string $exception
|
||||
* @return void
|
||||
*/
|
||||
public function testStringByteFormat($input, $expected, $expected_si): void
|
||||
{
|
||||
public function testStringByteFormat(
|
||||
string|int|float $input,
|
||||
string|int|float $expected,
|
||||
string|int|float $expected_si,
|
||||
string|int|float $expected_string,
|
||||
string|int|float $expected_string_si,
|
||||
?string $exception
|
||||
): void {
|
||||
if ($exception !== null) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Byte::stringByteFormat($input)
|
||||
@@ -239,6 +277,17 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
$expected_si,
|
||||
\CoreLibs\Convert\Byte::stringByteFormat($input, \CoreLibs\Convert\Byte::BYTE_FORMAT_SI)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_string,
|
||||
\CoreLibs\Convert\Byte::stringByteFormat($input, \CoreLibs\Convert\Byte::RETURN_AS_STRING)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_string_si,
|
||||
\CoreLibs\Convert\Byte::stringByteFormat(
|
||||
$input,
|
||||
\CoreLibs\Convert\Byte::BYTE_FORMAT_SI | \CoreLibs\Convert\Byte::RETURN_AS_STRING
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +302,8 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
*/
|
||||
public function testHumanReadableByteFormatException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionCode(1);
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat(12, $flag);
|
||||
}
|
||||
|
||||
@@ -272,7 +322,8 @@ final class CoreLibsConvertByteTest extends TestCase
|
||||
*/
|
||||
public function testStringByteFormatException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionCode(1);
|
||||
\CoreLibs\Convert\Byte::stringByteFormat(12, $flag);
|
||||
}
|
||||
}
|
||||
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
|
||||
* @coversDefaultClass \CoreLibs\Convert\Colors
|
||||
* @testdox \CoreLibs\Convert\Colors method tests
|
||||
* @testdox \CoreLibs\Convert\Colors legacy method tests
|
||||
*/
|
||||
final class CoreLibsConvertColorsTest extends TestCase
|
||||
{
|
||||
@@ -21,7 +21,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hexColorProvider(): array
|
||||
public function providerRgb2hexColor(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
@@ -59,6 +59,27 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color red ' => [
|
||||
0 => -12,
|
||||
1 => 12,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color green ' => [
|
||||
0 => 12,
|
||||
1 => -12,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
'invalid color blue ' => [
|
||||
0 => 12,
|
||||
1 => 12,
|
||||
2 => -12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -67,7 +88,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hex2rgbColorProvider(): array
|
||||
public function providerHex2rgbColor(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
@@ -150,10 +171,40 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
'valid' => true,
|
||||
],
|
||||
// invalid values
|
||||
'invalid color' => [
|
||||
'rgb' => [-12, 300, 12],
|
||||
'hsb' => [-12, 300, 12],
|
||||
'hsl' => [-12, 300, 12],
|
||||
'invalid color r/h/h low' => [
|
||||
'rgb' => [-1, 12, 12],
|
||||
'hsb' => [-1, 50, 50],
|
||||
'hsl' => [-1, 50, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color r/h/h high' => [
|
||||
'rgb' => [256, 12, 12],
|
||||
'hsb' => [361, 50, 50],
|
||||
'hsl' => [361, 50, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color g/s/s low' => [
|
||||
'rgb' => [12, -1, 12],
|
||||
'hsb' => [1, -1, 50],
|
||||
'hsl' => [1, -1, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color g/s/s high' => [
|
||||
'rgb' => [12, 256, 12],
|
||||
'hsb' => [1, 101, 50],
|
||||
'hsl' => [1, 101, 50],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color b/b/l low' => [
|
||||
'rgb' => [12, 12, -1],
|
||||
'hsb' => [1, 50, -1],
|
||||
'hsl' => [1, 50, -1],
|
||||
'valid' => false,
|
||||
],
|
||||
'invalid color b/b/l high' => [
|
||||
'rgb' => [12, 12, 256],
|
||||
'hsb' => [1, 50, 101],
|
||||
'hsl' => [1, 50, 101],
|
||||
'valid' => false,
|
||||
],
|
||||
];
|
||||
@@ -164,7 +215,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hsbColorProvider(): array
|
||||
public function providerRgb2hsbColor(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
@@ -183,7 +234,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsb2rgbColorProvider(): array
|
||||
public function providerHsb2rgbColor(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
@@ -202,7 +253,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hslColorProvider(): array
|
||||
public function providerRgb2hslColor(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
@@ -221,7 +272,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsl2rgbColorProvider(): array
|
||||
public function providerHsl2rgbColor(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
@@ -240,17 +291,28 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* TODO: add cross convert check
|
||||
*
|
||||
* @covers ::rgb2hex
|
||||
* @dataProvider rgb2hexColorProvider
|
||||
* @dataProvider providerRgb2hexColor
|
||||
* @testdox rgb2hex $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input_r
|
||||
* @param int $input_g
|
||||
* @param int $input_b
|
||||
* @param string|bool $expected_hash
|
||||
* @param string|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hex(int $input_r, int $input_g, int $input_b, $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 #
|
||||
$this->assertEquals(
|
||||
$expected_hash,
|
||||
@@ -280,7 +342,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hex2rgb
|
||||
* @dataProvider hex2rgbColorProvider
|
||||
* @dataProvider providerHex2rgbColor
|
||||
* @testdox hex2rgb $input will be $expected, $expected_str str[,], $expected_str_sep str[$separator] [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
@@ -292,11 +354,19 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*/
|
||||
public function testHex2rgb(
|
||||
string $input,
|
||||
$expected,
|
||||
$expected_str,
|
||||
array|bool $expected,
|
||||
string|bool $expected_str,
|
||||
string $separator,
|
||||
$expected_str_sep
|
||||
string|bool $expected_str_sep
|
||||
): void {
|
||||
if ($expected === false || $expected_str === false || $expected_str_sep === false) {
|
||||
$hex_string = preg_replace("/[^0-9A-Fa-f]/", '', $input);
|
||||
if (!is_string($hex_string)) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
} else {
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
}
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input)
|
||||
@@ -315,7 +385,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsb
|
||||
* @dataProvider rgb2hsbColorProvider
|
||||
* @dataProvider providerRgb2hsbColor
|
||||
* @testdox rgb2hsb $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
@@ -324,8 +394,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @param array|bool $expected
|
||||
* @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(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsb($input_r, $input_g, $input_b)
|
||||
@@ -336,7 +409,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsb2rgb
|
||||
* @dataProvider hsb2rgbColorProvider
|
||||
* @dataProvider providerHsb2rgbColor
|
||||
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param float $input_h
|
||||
@@ -345,8 +418,12 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @param array|bool $expected
|
||||
* @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(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsb2rgb($input_h, $input_s, $input_b)
|
||||
@@ -357,7 +434,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsl
|
||||
* @dataProvider rgb2hslColorProvider
|
||||
* @dataProvider providerRgb2hslColor
|
||||
* @testdox rgb2hsl $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
@@ -366,8 +443,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @param array|bool $expected
|
||||
* @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(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsl($input_r, $input_g, $input_b)
|
||||
@@ -378,7 +458,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsl2rgb
|
||||
* @dataProvider hsl2rgbColorProvider
|
||||
* @dataProvider providerHsl2rgbColor
|
||||
* @testdox hsl2rgb $input_h,$input_s,$input_l will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer|float $input_h
|
||||
@@ -387,8 +467,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
* @param array|bool $expected
|
||||
* @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(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsl2rgb($input_h, $input_s, $input_l)
|
||||
@@ -406,11 +489,11 @@ final class CoreLibsConvertColorsTest extends TestCase
|
||||
*/
|
||||
public function testHslHsb360hue(): void
|
||||
{
|
||||
$this->assertNotFalse(
|
||||
$this->assertIsArray(
|
||||
\CoreLibs\Convert\Colors::hsl2rgb(360.0, 90.5, 41.2),
|
||||
'HSL to RGB with 360 hue'
|
||||
);
|
||||
$this->assertNotFalse(
|
||||
$this->assertIsArray(
|
||||
\CoreLibs\Convert\Colors::hsb2rgb(360, 95, 78.0),
|
||||
'HSB to RGB with 360 hue'
|
||||
);
|
||||
@@ -16,7 +16,7 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
/**
|
||||
* test list for json convert tests
|
||||
*
|
||||
* @return array
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function jsonProvider(): array
|
||||
{
|
||||
@@ -54,10 +54,36 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function jsonArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid json' => [
|
||||
[
|
||||
'm' => 2,
|
||||
'f' => 'sub_2'
|
||||
],
|
||||
'{"m":2,"f":"sub_2"}',
|
||||
],
|
||||
'empty json array' => [
|
||||
[],
|
||||
'[]'
|
||||
],
|
||||
'empty json hash' => [
|
||||
['' => ''],
|
||||
'{"":""}'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* json error list
|
||||
*
|
||||
* @return array JSON error list
|
||||
* @return array<mixed> JSON error list
|
||||
*/
|
||||
public function jsonErrorProvider(): array
|
||||
{
|
||||
@@ -127,7 +153,7 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param bool $flag
|
||||
* @param array $expected
|
||||
* @param array<mixed> $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonConvertToArray(?string $input, bool $flag, array $expected): void
|
||||
@@ -138,6 +164,51 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test with flags
|
||||
*
|
||||
* @covers ::jsonConvertToArray
|
||||
* @testdox jsonConvertToArray flag test, if flag is used
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonConvertToArrayWithFlags(): void
|
||||
{
|
||||
$input = '{"valid":"json","invalid":"\xB1\x31"}';
|
||||
/* $expected_without_flag = [
|
||||
'valid' => 'json'
|
||||
];
|
||||
$expected_with_flag = [
|
||||
'valid' => 'json',
|
||||
'invalid' => "\xB1\x31"
|
||||
]; */
|
||||
// no idea why in both it throws an erro
|
||||
$expected_without_flag = [];
|
||||
$expected_with_flag = [];
|
||||
$this->assertEquals(
|
||||
$expected_without_flag,
|
||||
\CoreLibs\Convert\Json::jsonConvertToArray($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_with_flag,
|
||||
\CoreLibs\Convert\Json::jsonConvertToArray($input, flags:JSON_INVALID_UTF8_IGNORE)
|
||||
);
|
||||
}
|
||||
|
||||
public function testJsonConvertToArrayRemoveThrowFlag(): void
|
||||
{
|
||||
$input = '{"valid":"json","invalid":"\xB1\x31"}';
|
||||
// show NOT throw an exception
|
||||
try {
|
||||
$this->assertEquals(
|
||||
[],
|
||||
\CoreLibs\Convert\Json::jsonConvertToArray($input, flags:JSON_THROW_ON_ERROR)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->fail('Exception was thrown despite flag removal');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test json error states
|
||||
*
|
||||
@@ -146,7 +217,8 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
* @testdox jsonGetLastError $input will be $expected_i/$expected_s [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected
|
||||
* @param int $expected_i
|
||||
* @param string $expected_s
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonGetLastError(?string $input, int $expected_i, string $expected_s): void
|
||||
@@ -161,6 +233,68 @@ final class CoreLibsConvertJsonTest extends TestCase
|
||||
\CoreLibs\Convert\Json::jsonGetLastError(true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test json error states
|
||||
*
|
||||
* @covers ::jsonValidate
|
||||
* @dataProvider jsonErrorProvider
|
||||
* @testdox jsonValidate $input will be $expected_i/$expected_s [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param int $expected_i
|
||||
* @param string $expected_s
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonValidateGetLastError(?string $input, int $expected_i, string $expected_s): void
|
||||
{
|
||||
\CoreLibs\Convert\Json::jsonValidate($input);
|
||||
$this->assertEquals(
|
||||
$expected_i,
|
||||
\CoreLibs\Convert\Json::jsonGetLastError()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_s,
|
||||
\CoreLibs\Convert\Json::jsonGetLastError(true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test json validation
|
||||
*
|
||||
* @covers ::jsonValidate
|
||||
* @testdox jsonValidate test valid and invalid json
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonValidate(): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
\CoreLibs\Convert\Json::jsonValidate('{"valid": "json"}')
|
||||
);
|
||||
$this->assertFalse(
|
||||
\CoreLibs\Convert\Json::jsonValidate('not valid json')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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__
|
||||
504
4dev/tests/Convert/CoreLibsConvertMathTest.php
Normal file
504
4dev/tests/Convert/CoreLibsConvertMathTest.php
Normal file
@@ -0,0 +1,504 @@
|
||||
<?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, null],
|
||||
'cube root of 3' => [3, 1.44225, 5, null],
|
||||
'cube root of -1' => [-1, 'NAN', 0, \InvalidArgumentException::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param ?string $exception
|
||||
* @return void
|
||||
*/
|
||||
public function testCbrt(float|int $number, float|string $expected, int $round_to, ?string $exception): void
|
||||
{
|
||||
if ($exception !== null) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
$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 '
|
||||
. 'and has no idea what is going on here',
|
||||
'UTF-8',
|
||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||
. 'and has no idea what is going on here'
|
||||
"The quick brown fox jumps over the lazy sheep that sleeps in the ravine and\r\n"
|
||||
. ' has no idea what is going on here'
|
||||
],
|
||||
'standard with special chars UTF-8' => [
|
||||
'This is ümläßtと漢字もカタカナ!!^$%&',
|
||||
'UTF-8',
|
||||
'This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?='
|
||||
. "\r\n"
|
||||
. ' =?UTF-8?B?JQ==?=&'
|
||||
"This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?=\r\n"
|
||||
. ' =?UTF-8?B?JSY=?='
|
||||
],
|
||||
'35 chars and space at the end UTF-8' => [
|
||||
'12345678901234567890123456789012345 '
|
||||
@@ -62,9 +61,8 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
||||
. 'is there a space?',
|
||||
'UTF-8',
|
||||
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
||||
. " =?UTF-8?B?44K/44Kr44OK?=\r\n"
|
||||
. " =?UTF-8?B?44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr?=\r\n"
|
||||
. " =?UTF-8?B?44OK44Kr44K/?= is there a =?UTF-8?B?c3BhY2U/?="
|
||||
. " =?UTF-8?B?44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq?=\r\n"
|
||||
. " =?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/IGlzIHRoZXJlIGEgc3BhY2U/?="
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -85,16 +83,28 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
|
||||
// print "MIME: -" . $encoded . "-\n";
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$encoded
|
||||
$encoded,
|
||||
"__mbMimeEncode"
|
||||
);
|
||||
$decoded = mb_decode_mimeheader($encoded);
|
||||
// print "INPUT : " . $input . "\n";
|
||||
// print "DECODED: " . $decoded . "\n";
|
||||
// print "ENCODED: " . $encoded . "\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
|
||||
$this->assertEquals(
|
||||
$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__
|
||||
283
4dev/tests/Convert/CoreLibsConvertStringsRegexValidateTest.php
Normal file
283
4dev/tests/Convert/CoreLibsConvertStringsRegexValidateTest.php
Normal file
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
// This code was created by Claude Sonnet 4
|
||||
// FIX:
|
||||
// '/test{/', // Unmatched brace -> this is valid
|
||||
// '/test{1,}/', // Invalid quantifier -> this is valid
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Convert\Strings;
|
||||
|
||||
/**
|
||||
* Test class for CoreLibs\Convert\Strings regex validation methods
|
||||
*/
|
||||
class CoreLibsConvertStringsRegexValidateTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test isValidRegex with valid regex patterns
|
||||
*/
|
||||
public function testIsValidRegexWithValidPatterns(): void
|
||||
{
|
||||
$validPatterns = [
|
||||
'/^[a-zA-Z0-9]+$/',
|
||||
'/test/',
|
||||
'/\d+/',
|
||||
'/^hello.*world$/',
|
||||
'/[0-9]{3}-[0-9]{3}-[0-9]{4}/',
|
||||
'#^https?://.*#i',
|
||||
'~^[a-z]+~',
|
||||
'|test|',
|
||||
'/^$/m',
|
||||
'/\w+/u',
|
||||
];
|
||||
|
||||
foreach ($validPatterns as $pattern) {
|
||||
$this->assertTrue(
|
||||
Strings::isValidRegex($pattern),
|
||||
"Pattern '{$pattern}' should be valid"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test isValidRegex with invalid regex patterns
|
||||
*/
|
||||
public function testIsValidRegexWithInvalidPatterns(): void
|
||||
{
|
||||
$invalidPatterns = [
|
||||
'/[/', // Unmatched bracket
|
||||
'/test[/', // Unmatched bracket
|
||||
'/(?P<name>/', // Unmatched parenthesis
|
||||
'/(?P<>test)/', // Invalid named group
|
||||
'/test\\/', // Invalid escape at end
|
||||
'/(test/', // Unmatched parenthesis
|
||||
'/test)/', // Unmatched parenthesis
|
||||
// '/test{/', // Unmatched brace -> this is valid
|
||||
// '/test{1,}/', // Invalid quantifier -> this is valid
|
||||
'/[z-a]/', // Invalid character range
|
||||
'invalid', // No delimiters
|
||||
'', // Empty string
|
||||
'/(?P<123>test)/', // Invalid named group name
|
||||
];
|
||||
|
||||
foreach ($invalidPatterns as $pattern) {
|
||||
$this->assertFalse(
|
||||
Strings::isValidRegex($pattern),
|
||||
"Pattern '{$pattern}' should be invalid"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getLastRegexErrorString returns correct error messages
|
||||
*/
|
||||
public function testGetLastRegexErrorStringReturnsCorrectMessages(): void
|
||||
{
|
||||
// Test with a valid regex first to ensure clean state
|
||||
Strings::isValidRegex('/valid/');
|
||||
$this->assertEquals('No error', Strings::getLastRegexErrorString());
|
||||
|
||||
// Test with invalid regex to trigger an error
|
||||
Strings::isValidRegex('/[/');
|
||||
$errorMessage = Strings::getLastRegexErrorString();
|
||||
|
||||
// The error message should be one of the defined messages
|
||||
$this->assertContains($errorMessage, array_values(Strings::PREG_ERROR_MESSAGES));
|
||||
$this->assertNotEquals('Unknown error', $errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getLastRegexErrorString with unknown error
|
||||
*/
|
||||
public function testGetLastRegexErrorStringWithUnknownError(): void
|
||||
{
|
||||
// This is harder to test directly since we can't easily mock preg_last_error()
|
||||
// but we can test the fallback behavior by reflection or assume it works
|
||||
|
||||
// At minimum, ensure it returns a string
|
||||
$result = Strings::getLastRegexErrorString();
|
||||
$this->assertIsString($result);
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validateRegex with valid patterns
|
||||
*/
|
||||
public function testValidateRegexWithValidPatterns(): void
|
||||
{
|
||||
$validPatterns = [
|
||||
'/^test$/',
|
||||
'/\d+/',
|
||||
'/[a-z]+/i',
|
||||
];
|
||||
|
||||
foreach ($validPatterns as $pattern) {
|
||||
$result = Strings::validateRegex($pattern);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertArrayHasKey('valid', $result);
|
||||
$this->assertArrayHasKey('preg_error', $result);
|
||||
$this->assertArrayHasKey('error', $result);
|
||||
|
||||
$this->assertTrue($result['valid'], "Pattern '{$pattern}' should be valid");
|
||||
$this->assertEquals(PREG_NO_ERROR, $result['preg_error']);
|
||||
$this->assertNull($result['error']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validateRegex with invalid patterns
|
||||
*/
|
||||
public function testValidateRegexWithInvalidPatterns(): void
|
||||
{
|
||||
$invalidPatterns = [
|
||||
'/[/', // Unmatched bracket
|
||||
'/(?P<name>/', // Unmatched parenthesis
|
||||
'/test\\/', // Invalid escape at end
|
||||
'/(test/', // Unmatched parenthesis
|
||||
];
|
||||
|
||||
foreach ($invalidPatterns as $pattern) {
|
||||
$result = Strings::validateRegex($pattern);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertArrayHasKey('valid', $result);
|
||||
$this->assertArrayHasKey('preg_error', $result);
|
||||
$this->assertArrayHasKey('error', $result);
|
||||
$this->assertArrayHasKey('pcre_error', $result);
|
||||
|
||||
$this->assertFalse($result['valid'], "Pattern '{$pattern}' should be invalid");
|
||||
$this->assertNotEquals(PREG_NO_ERROR, $result['preg_error']);
|
||||
$this->assertIsString($result['error']);
|
||||
$this->assertNotNull($result['error']);
|
||||
$this->assertNotEmpty($result['error']);
|
||||
|
||||
// Verify error message is from our defined messages or 'Unknown error'
|
||||
$this->assertTrue(
|
||||
in_array($result['error'], array_values(Strings::PREG_ERROR_MESSAGES)) ||
|
||||
$result['error'] === 'Unknown error'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validateRegex array structure
|
||||
*/
|
||||
public function testValidateRegexArrayStructure(): void
|
||||
{
|
||||
$result = Strings::validateRegex('/test/');
|
||||
|
||||
// Test array structure for valid regex
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertArrayHasKey('valid', $result);
|
||||
$this->assertArrayHasKey('preg_error', $result);
|
||||
$this->assertArrayHasKey('error', $result);
|
||||
|
||||
$result = Strings::validateRegex('/[/');
|
||||
|
||||
// Test array structure for invalid regex
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertArrayHasKey('valid', $result);
|
||||
$this->assertArrayHasKey('preg_error', $result);
|
||||
$this->assertArrayHasKey('error', $result);
|
||||
$this->assertArrayHasKey('pcre_error', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that methods handle edge cases properly
|
||||
*/
|
||||
public function testEdgeCases(): void
|
||||
{
|
||||
// Empty string
|
||||
$this->assertFalse(Strings::isValidRegex(''));
|
||||
|
||||
$result = Strings::validateRegex('');
|
||||
$this->assertFalse($result['valid']);
|
||||
|
||||
// Very long pattern
|
||||
$longPattern = '/' . str_repeat('a', 1000) . '/';
|
||||
$this->assertTrue(Strings::isValidRegex($longPattern));
|
||||
|
||||
// Unicode patterns
|
||||
$this->assertTrue(Strings::isValidRegex('/\p{L}+/u'));
|
||||
$this->assertTrue(Strings::isValidRegex('/[α-ω]+/u'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test PREG_ERROR_MESSAGES constant accessibility
|
||||
*/
|
||||
public function testPregErrorMessagesConstant(): void
|
||||
{
|
||||
$this->assertIsArray(Strings::PREG_ERROR_MESSAGES);
|
||||
$this->assertNotEmpty(Strings::PREG_ERROR_MESSAGES);
|
||||
|
||||
// Check that all expected PREG constants are defined
|
||||
$expectedKeys = [
|
||||
PREG_NO_ERROR,
|
||||
PREG_INTERNAL_ERROR,
|
||||
PREG_BACKTRACK_LIMIT_ERROR,
|
||||
PREG_RECURSION_LIMIT_ERROR,
|
||||
PREG_BAD_UTF8_ERROR,
|
||||
PREG_BAD_UTF8_OFFSET_ERROR,
|
||||
PREG_JIT_STACKLIMIT_ERROR,
|
||||
];
|
||||
|
||||
foreach ($expectedKeys as $key) {
|
||||
$this->assertArrayHasKey($key, Strings::PREG_ERROR_MESSAGES);
|
||||
$this->assertIsString(Strings::PREG_ERROR_MESSAGES[$key]);
|
||||
$this->assertNotEmpty(Strings::PREG_ERROR_MESSAGES[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error state isolation between method calls
|
||||
*/
|
||||
public function testErrorStateIsolation(): void
|
||||
{
|
||||
// Start with invalid regex
|
||||
Strings::isValidRegex('/[/');
|
||||
$firstError = Strings::getLastRegexErrorString();
|
||||
$this->assertNotEquals('No error', $firstError);
|
||||
|
||||
// Use valid regex
|
||||
Strings::isValidRegex('/valid/');
|
||||
$secondError = Strings::getLastRegexErrorString();
|
||||
$this->assertEquals('No error', $secondError);
|
||||
|
||||
// Verify validateRegex clears previous errors
|
||||
$result = Strings::validateRegex('/valid/');
|
||||
$this->assertTrue($result['valid']);
|
||||
$this->assertEquals(PREG_NO_ERROR, $result['preg_error']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test various regex delimiters
|
||||
*/
|
||||
public function testDifferentDelimiters(): void
|
||||
{
|
||||
$patterns = [
|
||||
'/test/', // forward slash
|
||||
'#test#', // hash
|
||||
'~test~', // tilde
|
||||
'|test|', // pipe
|
||||
'@test@', // at symbol
|
||||
'!test!', // exclamation
|
||||
'%test%', // percent
|
||||
];
|
||||
|
||||
foreach ($patterns as $pattern) {
|
||||
$this->assertTrue(
|
||||
Strings::isValidRegex($pattern),
|
||||
"Pattern with delimiter '{$pattern}' should be valid"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
786
4dev/tests/Convert/CoreLibsConvertStringsTest.php
Normal file
786
4dev/tests/Convert/CoreLibsConvertStringsTest.php
Normal file
@@ -0,0 +1,786 @@
|
||||
<?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
|
||||
// 3: expected
|
||||
return [
|
||||
'all empty string' => [
|
||||
'',
|
||||
'',
|
||||
''
|
||||
],
|
||||
'empty input string' => [
|
||||
'',
|
||||
'2-2',
|
||||
''
|
||||
],
|
||||
'empty format string string' => [
|
||||
'1234',
|
||||
'',
|
||||
'1234'
|
||||
],
|
||||
'string format match' => [
|
||||
'1234',
|
||||
'2-2',
|
||||
'12-34'
|
||||
],
|
||||
'string format trailing match' => [
|
||||
'1234',
|
||||
'2-2-',
|
||||
'12-34'
|
||||
],
|
||||
'string format leading match' => [
|
||||
'1234',
|
||||
'-2-2',
|
||||
'12-34'
|
||||
],
|
||||
'string format double inside match' => [
|
||||
'1234',
|
||||
'2--2',
|
||||
'12--34',
|
||||
],
|
||||
'string format short first' => [
|
||||
'1',
|
||||
'2-2',
|
||||
'1'
|
||||
],
|
||||
'string format match first' => [
|
||||
'12',
|
||||
'2-2',
|
||||
'12'
|
||||
],
|
||||
'string format short second' => [
|
||||
'123',
|
||||
'2-2',
|
||||
'12-3'
|
||||
],
|
||||
'string format too long' => [
|
||||
'1234567',
|
||||
'2-2',
|
||||
'12-34-567'
|
||||
],
|
||||
'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',
|
||||
'12--3-4'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* split format string
|
||||
*
|
||||
* @covers ::splitFormatString
|
||||
* @dataProvider splitFormatStringProvider
|
||||
* @testdox splitFormatString $input with format $format will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $format
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSplitFormatString(
|
||||
string $input,
|
||||
string $format,
|
||||
string $expected
|
||||
): void {
|
||||
$output = \CoreLibs\Convert\Strings::splitFormatString(
|
||||
$input,
|
||||
$format,
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/** check exceptions */
|
||||
public function splitFormatStringExceptionProvider(): array
|
||||
{
|
||||
return [
|
||||
'string format with no splitter match' => [
|
||||
'1234',
|
||||
'22',
|
||||
'12-34'
|
||||
],
|
||||
'invalid format string' => [
|
||||
'1234',
|
||||
'2あ2',
|
||||
],
|
||||
'mutltibyte string' => [
|
||||
'あいうえ',
|
||||
'2-2',
|
||||
],
|
||||
'mutltibyte split string' => [
|
||||
'1234',
|
||||
'2-2',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::splitFormatStringFixed
|
||||
* @dataProvider splitFormatStringExceptionProvider
|
||||
* @testdox splitFormatString Exception catch checks for $input with $format[$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSplitFormatStringExceptions(string $input, string $format): void
|
||||
{
|
||||
// catch exception
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
\CoreLibs\Convert\Strings::splitFormatString($input, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* test for split Format string fixed length
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function splitFormatStringFixedProvider(): array
|
||||
{
|
||||
return [
|
||||
'normal split, default split char' => [
|
||||
'abcdefg',
|
||||
4,
|
||||
null,
|
||||
'abcd-efg'
|
||||
],
|
||||
'noraml split, other single split char' => [
|
||||
'abcdefg',
|
||||
4,
|
||||
"=",
|
||||
'abcd=efg'
|
||||
],
|
||||
'noraml split, other multiple split char' => [
|
||||
'abcdefg',
|
||||
4,
|
||||
"-=-",
|
||||
'abcd-=-efg'
|
||||
],
|
||||
'non ascii characters' => [
|
||||
'あいうえお',
|
||||
2,
|
||||
"-",
|
||||
'あい-うえ-お'
|
||||
],
|
||||
'empty string' => [
|
||||
'',
|
||||
4,
|
||||
"-",
|
||||
''
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::splitFormatStringFixed
|
||||
* @dataProvider splitFormatStringFixedProvider
|
||||
* @testdox splitFormatStringFixed $input with length $split_length and split chars $split_characters will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param int $split_length
|
||||
* @param string|null $split_characters
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSplitFormatStringFixed(
|
||||
string $input,
|
||||
int $split_length,
|
||||
?string $split_characters,
|
||||
string $expected
|
||||
): void {
|
||||
if ($split_characters === null) {
|
||||
$output = \CoreLibs\Convert\Strings::splitFormatStringFixed(
|
||||
$input,
|
||||
$split_length
|
||||
);
|
||||
} else {
|
||||
$output = \CoreLibs\Convert\Strings::splitFormatStringFixed(
|
||||
$input,
|
||||
$split_length,
|
||||
$split_characters
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
public function splitFormatStringFixedExceptionProvider(): array
|
||||
{
|
||||
return [
|
||||
'split length too short' => [
|
||||
'abcdefg',
|
||||
-1,
|
||||
],
|
||||
'split length longer than string' => [
|
||||
'abcdefg',
|
||||
20,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::splitFormatStringFixed
|
||||
* @dataProvider splitFormatStringFixedExceptionProvider
|
||||
* @testdox splitFormatStringFixed Exception catch checks for $input with $length [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSplitFormatStringFixedExceptions(string $input, int $length): void
|
||||
{
|
||||
// catch exception
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
\CoreLibs\Convert\Strings::splitFormatStringFixed($input, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function allCharsInSetProvider(): array
|
||||
{
|
||||
return [
|
||||
'find' => [
|
||||
'abc',
|
||||
'abcdef',
|
||||
true
|
||||
],
|
||||
'not found' => [
|
||||
'abcz',
|
||||
'abcdef',
|
||||
false
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::allCharsInSet
|
||||
* @dataProvider allCharsInSetProvider
|
||||
* @testdox allCharsInSet $input in $haystack with expected $expected [$_dataName]
|
||||
*
|
||||
* @param string $needle
|
||||
* @param string $haystack
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testAllCharsInSet(string $needle, string $haystack, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Strings::allCharsInSet($needle, $haystack)
|
||||
);
|
||||
}
|
||||
|
||||
public function buildCharStringFromListsProvider(): array
|
||||
{
|
||||
return [
|
||||
'test a' => [
|
||||
'abc',
|
||||
['a', 'b', 'c'],
|
||||
],
|
||||
'test b' => [
|
||||
'abc123',
|
||||
['a', 'b', 'c'],
|
||||
['1', '2', '3'],
|
||||
],
|
||||
'test c: no params' => [
|
||||
'',
|
||||
],
|
||||
'test c: empty 1' => [
|
||||
'',
|
||||
[]
|
||||
],
|
||||
'test nested' => [
|
||||
'abc',
|
||||
[['a'], ['b'], ['c']],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::buildCharStringFromLists
|
||||
* @dataProvider buildCharStringFromListsProvider
|
||||
* @testdox buildCharStringFromLists all $input convert to $expected [$_dataName]
|
||||
*
|
||||
* @param string $expected
|
||||
* @param array ...$input
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildCharStringFromLists(string $expected, array ...$input): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Strings::buildCharStringFromLists(...$input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function removeDuplicatesProvider(): array
|
||||
{
|
||||
return [
|
||||
'test no change' => [
|
||||
'ABCDEFG',
|
||||
'ABCDEFG',
|
||||
],
|
||||
'test simple' => [
|
||||
'aa',
|
||||
'a'
|
||||
],
|
||||
'test keep lower and uppwer case' => [
|
||||
'AaBbCc',
|
||||
'AaBbCc'
|
||||
],
|
||||
'test unqiue' => [
|
||||
'aabbcc',
|
||||
'abc'
|
||||
],
|
||||
'test multibyte no change' => [
|
||||
'あいうえお',
|
||||
'あいうえお',
|
||||
],
|
||||
'test multibyte' => [
|
||||
'ああいいううええおお',
|
||||
'あいうえお',
|
||||
],
|
||||
'test multibyte special' => [
|
||||
'あぁいぃうぅえぇおぉ',
|
||||
'あぁいぃうぅえぇおぉ',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::removeDuplicates
|
||||
* @dataProvider removeDuplicatesProvider
|
||||
* @testdox removeDuplicates make $input unqiue to $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRemoveDuplicates(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Strings::removeDuplicates($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function isValidRegexSimpleProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid regex' => [
|
||||
'/^[A-z]$/',
|
||||
true,
|
||||
[
|
||||
'valid' => true,
|
||||
'preg_error' => 0,
|
||||
'error' => null,
|
||||
'pcre_error' => null
|
||||
],
|
||||
],
|
||||
'invalid regex A' => [
|
||||
'/^[A-z]$',
|
||||
false,
|
||||
[
|
||||
'valid' => false,
|
||||
'preg_error' => 1,
|
||||
'error' => 'Internal PCRE error',
|
||||
'pcre_error' => 'Internal error'
|
||||
],
|
||||
],
|
||||
'invalid regex B' => [
|
||||
'/^[A-z$',
|
||||
false,
|
||||
[
|
||||
'valid' => false,
|
||||
'preg_error' => 1,
|
||||
'error' => 'Internal PCRE error',
|
||||
'pcre_error' => 'Internal error'
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::isValidRegexSimple
|
||||
* @dataProvider isValidRegexSimpleProvider
|
||||
* @testdox isValidRegexSimple make $input unqiue to $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testIsValidRegexSimple(string $input, bool $expected, array $expected_extended): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Strings::isValidRegex($input),
|
||||
'Regex is not valid'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_extended,
|
||||
\CoreLibs\Convert\Strings::validateRegex($input),
|
||||
'Validation of regex failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
// for true null is set, so we get here No Error
|
||||
$expected_extended['error'] ?? \CoreLibs\Convert\Strings::PREG_ERROR_MESSAGES[0],
|
||||
\CoreLibs\Convert\Strings::getLastRegexErrorString(),
|
||||
'Cannot match last preg error string'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function parseCharacterRangesProvider(): array
|
||||
{
|
||||
return [
|
||||
'simple a-z' => [
|
||||
['a-z'],
|
||||
implode('', range('a', 'z')),
|
||||
null,
|
||||
],
|
||||
'simple A-Z' => [
|
||||
['A-Z'],
|
||||
implode('', range('A', 'Z')),
|
||||
null,
|
||||
],
|
||||
'simple 0-9' => [
|
||||
['0-9'],
|
||||
implode('', range('0', '9')),
|
||||
null,
|
||||
],
|
||||
'mixed ranges' => [
|
||||
['a-c', 'X-Z', '3-5'],
|
||||
'abcXYZ345',
|
||||
null,
|
||||
],
|
||||
'reverse ranges' => [
|
||||
['z-a'],
|
||||
'abcdefghijklmnopqrstuvwxyz',
|
||||
null,
|
||||
],
|
||||
'overlapping ranges' => [
|
||||
['a-f', 'd-j'],
|
||||
'abcdefghij',
|
||||
null,
|
||||
],
|
||||
'mixed valid and overlap ranges' => [
|
||||
['a-f', 'z-a', '0-3'],
|
||||
'abcdefghijklmnopqrstuvwxyz0123',
|
||||
null,
|
||||
],
|
||||
'range without dashes' => [
|
||||
['abcddfff'],
|
||||
'abcdf',
|
||||
null,
|
||||
],
|
||||
'invalid ranges' => [
|
||||
['a-あ', 'A-あ', '0-あ'],
|
||||
'',
|
||||
\InvalidArgumentException::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::parseCharacterRanges
|
||||
* @dataProvider parseCharacterRangesProvider
|
||||
* @testdox parseCharacterRanges $input to $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $expected
|
||||
* @param string|null $expected_exception
|
||||
* @return void
|
||||
*/
|
||||
public function testParseCharacterRanges(
|
||||
array $input,
|
||||
string $expected,
|
||||
?string $expected_exception
|
||||
): void {
|
||||
if ($expected_exception !== null) {
|
||||
$this->expectException($expected_exception);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
implode('', \CoreLibs\Convert\Strings::parseCharacterRanges(implode('', $input)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __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,862 +0,0 @@
|
||||
<?php
|
||||
|
||||
// because we have long testdox lines
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Combined\ArrayHandler
|
||||
* @coversDefaultClass \CoreLibs\Combined\ArrayHandler
|
||||
* @testdox \CoreLibs\Combined\ArrayHandler method tests
|
||||
*/
|
||||
final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
{
|
||||
// we use that for all
|
||||
public static $array = [
|
||||
'a' => [
|
||||
'b' => 'bar',
|
||||
'c' => 'foo',
|
||||
'same' => 'same',
|
||||
3 => 'foobar',
|
||||
'foobar' => 4,
|
||||
'true' => true,
|
||||
],
|
||||
'd',
|
||||
4,
|
||||
'b',
|
||||
'c' => 'test',
|
||||
'same' => 'same',
|
||||
'deep' => [
|
||||
'sub' => [
|
||||
'nested' => 'bar',
|
||||
'same' => 'same',
|
||||
'more' => 'test'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arraySearchRecursiveProvider(): array
|
||||
{
|
||||
return [
|
||||
'find value' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => ['a', 'b'],
|
||||
],
|
||||
'find value with key' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => 'nested',
|
||||
3 => ['deep', 'sub', 'nested']
|
||||
],
|
||||
'not existing value' => [
|
||||
0 => 'not exists',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => [],
|
||||
],
|
||||
'find value int' => [
|
||||
0 => 4,
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => ['a', 'foobar']
|
||||
],
|
||||
'find value int as string' => [
|
||||
0 => '4',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => []
|
||||
],
|
||||
'find value int as string with key' => [
|
||||
0 => '4',
|
||||
1 => self::$array,
|
||||
2 => 'foobar',
|
||||
3 => []
|
||||
],
|
||||
'first level value' => [
|
||||
0 => 'd',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
4 => [0]
|
||||
],
|
||||
'find value, return int key' => [
|
||||
0 => 'foobar',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => ['a', 3]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arraySearchRecursiveAllProvider(): array
|
||||
{
|
||||
return [
|
||||
'find value' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'level' => -1,
|
||||
'work' => [],
|
||||
'found' => [
|
||||
0 => ['a', 'b'],
|
||||
1 => ['deep', 'sub', 'nested']
|
||||
]
|
||||
]
|
||||
],
|
||||
'find value, new type' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => false,
|
||||
4 => [
|
||||
0 => ['a', 'b'],
|
||||
1 => ['deep', 'sub', 'nested']
|
||||
]
|
||||
],
|
||||
'find value with key' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => 'nested',
|
||||
3 => true,
|
||||
4 => [
|
||||
'level' => -1,
|
||||
'work' => [],
|
||||
'found' => [
|
||||
0 => ['deep', 'sub', 'nested']
|
||||
]
|
||||
]
|
||||
],
|
||||
'not existing value' => [
|
||||
0 => 'not exists',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'level' => -1,
|
||||
'work' => [],
|
||||
],
|
||||
],
|
||||
'not existing value, new type' => [
|
||||
0 => 'not exists',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => false,
|
||||
4 => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arraySearchSimpleProvider(): array
|
||||
{
|
||||
return [
|
||||
'key/value exist' => [
|
||||
0 => self::$array,
|
||||
1 => 'c',
|
||||
2 => 'foo',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key/value exists twice' => [
|
||||
0 => self::$array,
|
||||
1 => 'same',
|
||||
2 => 'same',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key/value not found' => [
|
||||
0 => self::$array,
|
||||
1 => 'not exists',
|
||||
2 => 'not exists',
|
||||
3 => false,
|
||||
4 => false,
|
||||
],
|
||||
'key exists, value not' => [
|
||||
0 => self::$array,
|
||||
1 => 'b',
|
||||
2 => 'not exists',
|
||||
3 => false,
|
||||
4 => false,
|
||||
],
|
||||
'key not, value exists' => [
|
||||
0 => self::$array,
|
||||
1 => 'not exists',
|
||||
2 => 'bar',
|
||||
3 => false,
|
||||
4 => false,
|
||||
],
|
||||
'numeric key, value exists' => [
|
||||
0 => self::$array,
|
||||
1 => 0,
|
||||
2 => 'd',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'numeric key as string, value exists' => [
|
||||
0 => self::$array,
|
||||
1 => '0',
|
||||
2 => 'd',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'numeric key as string, value exists, strinct' => [
|
||||
0 => self::$array,
|
||||
1 => '0',
|
||||
2 => 'd',
|
||||
3 => true,
|
||||
4 => false,
|
||||
],
|
||||
'key exists, value numeric' => [
|
||||
0 => self::$array,
|
||||
1 => 'foobar',
|
||||
2 => 4,
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key exists, value numeric as string' => [
|
||||
0 => self::$array,
|
||||
1 => 'foobar',
|
||||
2 => '4',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key exists, value numeric as string, strict' => [
|
||||
0 => self::$array,
|
||||
1 => 'foobar',
|
||||
2 => '4',
|
||||
3 => true,
|
||||
4 => false,
|
||||
],
|
||||
'key exists, value bool' => [
|
||||
0 => self::$array,
|
||||
1 => 'true',
|
||||
2 => true,
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key exists, value bool as string' => [
|
||||
0 => self::$array,
|
||||
1 => 'true',
|
||||
2 => 'true',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key exists, value bool as string, strict' => [
|
||||
0 => self::$array,
|
||||
1 => 'true',
|
||||
2 => 'true',
|
||||
3 => true,
|
||||
4 => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* provides array listing for the merge test
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayMergeRecursiveProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: expected
|
||||
// 1..n: to merge arrays
|
||||
// n+1: trigger for handle keys as string
|
||||
'two arrays' => [
|
||||
['a' => 1, 'b' => 2, 'c' => 3],
|
||||
['a' => 1, 'b' => 2],
|
||||
['b' => 2, 'c' => 3],
|
||||
],
|
||||
'two arrays, string flag' => [
|
||||
['a' => 1, 'b' => 2, 'c' => 3],
|
||||
['a' => 1, 'b' => 2],
|
||||
['b' => 2, 'c' => 3],
|
||||
true,
|
||||
],
|
||||
// non hash arrays
|
||||
'non hash array merge, no string flag' => [
|
||||
[3, 4, 5],
|
||||
[1, 2, 3],
|
||||
[3, 4, 5],
|
||||
],
|
||||
'non hash array merge, string flag' => [
|
||||
[1, 2, 3, 3, 4, 5],
|
||||
[1, 2, 3],
|
||||
[3, 4, 5],
|
||||
true
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* for warning checks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayMergeRecursiveProviderWarning(): array
|
||||
{
|
||||
return [
|
||||
// error <2 arguments
|
||||
'too view arguments' => [
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1]
|
||||
],
|
||||
// error <2 arrays
|
||||
'only one array' => [
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1],
|
||||
true,
|
||||
],
|
||||
// error element is not array
|
||||
'non array between array' => [
|
||||
'arrayMergeRecursive encountered a non array argument',
|
||||
[1],
|
||||
'string',
|
||||
[2]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayCompareProvider(): array
|
||||
{
|
||||
return [
|
||||
'one matching' => [
|
||||
['a', 'b', 'c'],
|
||||
['c', 'd', 'e'],
|
||||
['a', 'b', 'd', 'e']
|
||||
],
|
||||
'all the same' => [
|
||||
['a', 'b', 'c'],
|
||||
['a', 'b', 'c'],
|
||||
[]
|
||||
],
|
||||
'all different' => [
|
||||
['a', 'b'],
|
||||
['c', 'd'],
|
||||
['a', 'b', 'c', 'd']
|
||||
],
|
||||
'empty arrays' => [
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function inArrayAnyProvider(): array
|
||||
{
|
||||
return [
|
||||
'all exist in haystack' => [
|
||||
[1],
|
||||
[1, 2, 3, 4],
|
||||
[1]
|
||||
],
|
||||
'not all exist in haystack' => [
|
||||
[1, 5],
|
||||
[1, 2, 3, 4],
|
||||
[1]
|
||||
],
|
||||
'none exist in haystack' => [
|
||||
[5],
|
||||
[1, 2, 3, 4],
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function genAssocArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'non set' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
],
|
||||
'key set' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
'a',
|
||||
false,
|
||||
false,
|
||||
['a1' => 0, 'a2' => 1],
|
||||
],
|
||||
'value set' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
false,
|
||||
'a',
|
||||
false,
|
||||
[0 => 'a1', 1 => 'a2', 2 => ''],
|
||||
],
|
||||
'key and value set, add empty, null' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
'a',
|
||||
'b',
|
||||
false,
|
||||
['a1' => 2, 'a2' => 3],
|
||||
],
|
||||
'key and value set, add empty' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => ''],
|
||||
3 => ['a' => 'a4', 'b' => ''],
|
||||
],
|
||||
'a',
|
||||
'b',
|
||||
false,
|
||||
['a1' => 2, 'a2' => 3, 'a4' => ''],
|
||||
],
|
||||
'key/value set, skip empty' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
'a',
|
||||
'b',
|
||||
true,
|
||||
['a1' => 2, 'a2' => 3],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function flattenArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'array key/value, single' => [
|
||||
0 => ['a' => 'foo', 1 => 'bar', 'c' => 2],
|
||||
1 => ['foo', 'bar', 2],
|
||||
2 => ['a', 1, 'c'],
|
||||
3 => ['a', 1, 'c'],
|
||||
],
|
||||
'array values, single' => [
|
||||
0 => ['foo', 'bar', 2],
|
||||
1 => ['foo', 'bar', 2],
|
||||
2 => [0, 1, 2],
|
||||
3 => [0, 1, 2],
|
||||
],
|
||||
'array key/value, multi' => [
|
||||
0 => [
|
||||
'a' => ['a1' => 'a1foo', 'a2' => 'a1bar'],
|
||||
1 => 'bar',
|
||||
'c' => [2, 3, 4],
|
||||
'd' => [
|
||||
'e' => [
|
||||
'de1' => 'subfoo', 'de2' => 'subbar', 'a2' => 'a1bar'
|
||||
]
|
||||
]
|
||||
],
|
||||
1 => ['a1foo', 'a1bar', 'bar', 2, 3, 4, 'subfoo', 'subbar', 'a1bar'],
|
||||
2 => ['a', 'a1', 'a2', 1, 'c', 0, 1, 2, 'd', 'e', 'de1', 'de2', 'a2'],
|
||||
3 => ['a1', 'a2', 1, 0, 1, 2, 'de1', 'de2', 'a2'],
|
||||
],
|
||||
'array with double values' => [
|
||||
0 => ['a', 'a', 'b'],
|
||||
1 => ['a', 'a', 'b'],
|
||||
2 => [0, 1, 2],
|
||||
3 => [0, 1, 2],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* use the flattenArrayProvider and replace 1 with 2 array pos
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function flattenArrayKeyProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->flattenArrayProvider() as $key => $row) {
|
||||
$list[$key] = [
|
||||
$row[0],
|
||||
$row[2],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* use the flattenArrayProvider and replace 1 with 3 array pos
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function flattenArrayKeyLeavesOnlyProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->flattenArrayProvider() as $key => $row) {
|
||||
$list[$key] = [
|
||||
$row[0],
|
||||
$row[3],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayFlatForKeyProvider(): array
|
||||
{
|
||||
return [
|
||||
'all present, single level' => [
|
||||
0 => [
|
||||
'a' => ['b1' => 'foo', 'a2' => 'a-foo'],
|
||||
'b' => ['b1' => 'bar', 'a2' => 'b-foo'],
|
||||
'c' => ['b1' => 'foobar', 'a2' => 'c-foo'],
|
||||
],
|
||||
1 => 'a2',
|
||||
2 => [
|
||||
'a' => 'a-foo',
|
||||
'b' => 'b-foo',
|
||||
'c' => 'c-foo',
|
||||
],
|
||||
],
|
||||
'no sub arrays' => [
|
||||
0 => ['a', 'b', 'c'],
|
||||
1 => 'a',
|
||||
2 => ['a', 'b', 'c'],
|
||||
],
|
||||
'sub arrays with missing' => [
|
||||
0 => [
|
||||
'a' => ['b1' => 'foo', 'a2' => 'a-foo'],
|
||||
'b' => ['b1' => 'bar'],
|
||||
'c' => ['b1' => 'foobar', 'a2' => 'c-foo'],
|
||||
],
|
||||
1 => 'a2',
|
||||
2 => [
|
||||
'a' => 'a-foo',
|
||||
'b' => ['b1' => 'bar'],
|
||||
'c' => 'c-foo',
|
||||
],
|
||||
],
|
||||
'deep nested sub arrays' => [
|
||||
0 => [
|
||||
'a' => [
|
||||
'b1' => 'foo',
|
||||
'a2' => [
|
||||
'text' => ['a-foo', 'a-bar'],
|
||||
],
|
||||
],
|
||||
'b' => [
|
||||
'b1' => 'bar',
|
||||
'a2' => [
|
||||
'text' => 'b-foo',
|
||||
],
|
||||
],
|
||||
],
|
||||
1 => 'a2',
|
||||
2 => [
|
||||
'a' => [
|
||||
'text' => ['a-foo', 'a-bar'],
|
||||
],
|
||||
'b' => [
|
||||
'text' => 'b-foo',
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arraySearchRecursive
|
||||
* @dataProvider arraySearchRecursiveProvider
|
||||
* @testdox arraySearchRecursive $needle (key $key_search_for) in $input and will be $expected [$_dataName]
|
||||
*
|
||||
* @param string|null $needle
|
||||
* @param array $input
|
||||
* @param string|null $key_search_for
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySearchRecursive($needle, array $input, ?string $key_search_for, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arraySearchRecursive($needle, $input, $key_search_for)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arraySearchRecursiveAll
|
||||
* @dataProvider arraySearchRecursiveAllProvider
|
||||
* @testdox arraySearchRecursiveAll $needle (key $key_search_for) in $input and will be $expected (old: $flag) [$_dataName]
|
||||
*
|
||||
* @param string|null $needle
|
||||
* @param array $input
|
||||
* @param string|null $key_search_for
|
||||
* @param bool $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySearchRecursiveAll($needle, array $input, ?string $key_search_for, bool $flag, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arraySearchRecursiveAll($needle, $input, $key_search_for, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arraySearchSimple
|
||||
* @dataProvider arraySearchSimpleProvider
|
||||
* @testdox arraySearchSimple $input searched with key: $key / value: $value (strict: $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string|int $key
|
||||
* @param string|int $value
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySearchSimple(array $input, $key, $value, bool $flag, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arraySearchSimple($input, $key, $value, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayMergeRecursive
|
||||
* @dataProvider arrayMergeRecursiveProvider
|
||||
* @testdox arrayMergeRecursive ... [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public function testArrayMergeRecursive(): void
|
||||
{
|
||||
$arrays = func_get_args();
|
||||
// first is expected array, always
|
||||
$expected = array_shift($arrays);
|
||||
$output = \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(
|
||||
...$arrays
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayMergeRecursive
|
||||
* @dataProvider arrayMergeRecursiveProviderWarning
|
||||
* @testdox arrayMergeRecursive with E_USER_WARNING [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayMergeRecursiveWarningA(): void
|
||||
{
|
||||
$arrays = func_get_args();
|
||||
// first is expected warning
|
||||
$warning = array_shift($arrays);
|
||||
$this->expectWarning();
|
||||
$this->expectWarningMessage($warning);
|
||||
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayDiff
|
||||
* @dataProvider arrayCompareProvider
|
||||
* @testdox arrayDiff $input_a diff $input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input_a
|
||||
* @param array $input_b
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayDiff(array $input_a, array $input_b, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arrayDiff($input_a, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::inArrayAny
|
||||
* @dataProvider inArrayAnyProvider
|
||||
* @testdox inArrayAny needle $input_a in haystack $input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input_a
|
||||
* @param array $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testInArrayAny(array $input_a, array $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::inArrayAny($input_a, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::genAssocArray
|
||||
* @dataProvider genAssocArrayProvider
|
||||
* @testdox genAssocArray array $input with $key or $value and flag set only $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string|int|bool $key
|
||||
* @param string|int|bool $value
|
||||
* @param bool $flag
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGenAssocArray(array $input, $key, $value, bool $flag, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::genAssocArray($input, $key, $value, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::flattenArray
|
||||
* @dataProvider flattenArrayProvider
|
||||
* @testdox testFlattenArray array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testFlattenyArray(array $input, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::flattenArray($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::flattenArrayKey
|
||||
* @dataProvider flattenArrayKeyProvider
|
||||
* @testdox flattenArrayKey array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testFlattenArrayKey(array $input, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::flattenArrayKey($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::flattenArrayKeyLeavesOnly
|
||||
* @dataProvider flattenArrayKeyLeavesOnlyProvider
|
||||
* @testdox flattenArrayKeyLeavesOnly array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testFlattenArrayKeyLeavesOnly(array $input, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::flattenArrayKeyLeavesOnly($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayFlatForKey
|
||||
* @dataProvider arrayFlatForKeyProvider
|
||||
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayFlatForKey(array $input, $search, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arrayFlatForKey($input, $search)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,785 +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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function weekdayNumberProvider(): array
|
||||
{
|
||||
return [
|
||||
'0 invalid' => [0, null, 'Inv',],
|
||||
'0 invalid long' => [0, true, 'Invalid',],
|
||||
'1 short' => [1, null, 'Mon',],
|
||||
'1 long' => [1, true, 'Monday',],
|
||||
'2 short' => [2, null, 'Tue',],
|
||||
'2 long' => [2, true, 'Tuesday',],
|
||||
'3 short' => [3, null, 'Wed',],
|
||||
'3 long' => [3, true, 'Wednesday',],
|
||||
'4 short' => [4, null, 'Thu',],
|
||||
'4 long' => [4, true, 'Thursday',],
|
||||
'5 short' => [5, null, 'Fri',],
|
||||
'5 long' => [5, true, 'Friday',],
|
||||
'6 short' => [6, null, 'Sat',],
|
||||
'6 long' => [6, true, 'Saturday',],
|
||||
'7 short' => [7, null, 'Sun',],
|
||||
'7 long' => [7, true, 'Sunday',],
|
||||
'8 invalid' => [8, null, 'Inv',],
|
||||
'8 invalid long' => [8, true, 'Invalid',],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* int weekday number to string weekday
|
||||
*
|
||||
* @covers ::setWeekdayNameFromIsoDow
|
||||
* @dataProvider weekdayNumberProvider
|
||||
* @testdox weekdayListProvider $input (short $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input
|
||||
* @param bool|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetWeekdayNameFromIsoDow(
|
||||
int $input,
|
||||
?bool $flag,
|
||||
string $expected
|
||||
): void {
|
||||
if ($flag === null) {
|
||||
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromIsoDow($input);
|
||||
} else {
|
||||
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromIsoDow($input, $flag);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function weekdayDateProvider(): array
|
||||
{
|
||||
return [
|
||||
'invalid date' => ['2022-02-31', -1],
|
||||
'1: monday' => ['2022-07-25', 1],
|
||||
'2: tuesday' => ['2022-07-26', 2],
|
||||
'3: wednesday' => ['2022-07-27', 3],
|
||||
'4: thursday' => ['2022-07-28', 4],
|
||||
'5: friday' => ['2022-07-29', 5],
|
||||
'6: saturday' => ['2022-07-30', 6],
|
||||
'7: sunday' => ['2022-07-31', 7],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* date to weekday number
|
||||
*
|
||||
* @covers ::setWeekdayNumberFromDate
|
||||
* @dataProvider weekdayDateProvider
|
||||
* @testdox setWeekdayNumberFromDate $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetWeekdayNumberFromDate(
|
||||
string $input,
|
||||
int $expected
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::setWeekdayNumberFromDate($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function weekdayDateNameProvider(): array
|
||||
{
|
||||
return [
|
||||
'invalid date short' => ['2022-02-31', null, 'Inv'],
|
||||
'invalid date long' => ['2022-02-31', true, 'Invalid'],
|
||||
'Mon short' => ['2022-07-25', null, 'Mon'],
|
||||
'Monday long' => ['2022-07-25', true, 'Monday'],
|
||||
'Tue short' => ['2022-07-26', null, 'Tue'],
|
||||
'Tuesday long' => ['2022-07-26', true, 'Tuesday'],
|
||||
'Wed short' => ['2022-07-27', null, 'Wed'],
|
||||
'Wednesday long' => ['2022-07-27', true, 'Wednesday'],
|
||||
'Thu short' => ['2022-07-28', null, 'Thu'],
|
||||
'Thursday long' => ['2022-07-28', true, 'Thursday'],
|
||||
'Fri short' => ['2022-07-29', null, 'Fri'],
|
||||
'Friday long' => ['2022-07-29', true, 'Friday'],
|
||||
'Sat short' => ['2022-07-30', null, 'Sat'],
|
||||
'Saturday long' => ['2022-07-30', true, 'Saturday'],
|
||||
'Sun short' => ['2022-07-31', null, 'Sun'],
|
||||
'Sunday long' => ['2022-07-31', true, 'Sunday'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* date to weekday name
|
||||
*
|
||||
* @covers ::setWeekdayNameFromDate
|
||||
* @dataProvider weekdayDateNameProvider
|
||||
* @testdox setWeekdayNameFromDate $input (short $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param bool|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetWeekdayNameFromDate(
|
||||
string $input,
|
||||
?bool $flag,
|
||||
string $expected
|
||||
): void {
|
||||
if ($flag === null) {
|
||||
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromDate($input);
|
||||
} else {
|
||||
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromDate($input, $flag);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __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,261 +0,0 @@
|
||||
<?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
|
||||
{
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,212 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\Hash
|
||||
* @coversDefaultClass \CoreLibs\Create\Hash
|
||||
* @testdox \CoreLibs\Create\Hash method tests
|
||||
*/
|
||||
final class CoreLibsCreateHashTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashData(): array
|
||||
{
|
||||
return [
|
||||
'any string' => [
|
||||
'text' => 'Some String Text',
|
||||
'crc32b_reverse' => 'c5c21d91', // crc32b (in revere)
|
||||
'sha1Short' => '4d2bc9ba0', // sha1Short
|
||||
// via hash
|
||||
'crc32b' => '911dc2c5', // hash: crc32b
|
||||
'adler32' => '31aa05f1', // hash: alder32
|
||||
'fnv132' => '9df444f9', // hash: fnv132
|
||||
'fnv1a32' => '2c5f91b9', // hash: fnv1a32
|
||||
'joaat' => '50dab846', // hash: joaat
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function crc32bProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
$list[$name . ' to crc32b reverse'] = [
|
||||
0 => $values['text'],
|
||||
1 => $values['crc32b_reverse'],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sha1ShortProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
$list[$name . ' to sha1 short'] = [
|
||||
0 => $values['text'],
|
||||
1 => $values['crc32b_reverse'],
|
||||
2 => $values['sha1Short'],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* test all hash functions
|
||||
* NOTE: if we add new hash functions in the __hash method
|
||||
* they need to be added here too (and in the master hashData array too)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
foreach ([null, 'crc32b', 'adler32', 'fnv132', 'fnv1a32', 'joaat'] as $_hash_type) {
|
||||
// default value test
|
||||
if ($_hash_type === null) {
|
||||
$hash_type = \CoreLibs\Create\Hash::STANDARD_HASH_SHORT;
|
||||
} else {
|
||||
$hash_type = $_hash_type;
|
||||
}
|
||||
$list[$name . ' to ' . $hash_type] = [
|
||||
0 => $values['text'],
|
||||
1 => $_hash_type,
|
||||
2 => $values[$hash_type]
|
||||
];
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashLongProvider(): array
|
||||
{
|
||||
$hash_source = 'Some String Text';
|
||||
return [
|
||||
'Long Hash check: ' . \CoreLibs\Create\Hash::STANDARD_HASH_LONG => [
|
||||
$hash_source,
|
||||
hash(\CoreLibs\Create\Hash::STANDARD_HASH_LONG, $hash_source)
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__crc32b
|
||||
* @dataProvider crc32bProvider
|
||||
* @testdox __crc32b $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCrc32b(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__crc32b($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__sha1Short
|
||||
* @dataProvider sha1ShortProvider
|
||||
* @testdox __sha1Short $input will be $expected (crc32b) and $expected_sha1 (sha1 short) [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSha1Short(string $input, string $expected, string $expected_sha1): void
|
||||
{
|
||||
// uses crc32b
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input, false)
|
||||
);
|
||||
// sha1 type
|
||||
$this->assertEquals(
|
||||
$expected_sha1,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__hash
|
||||
* @dataProvider hashProvider
|
||||
* @testdox __hash $input with $hash_type will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|null $hash_type
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHash(string $input, ?string $hash_type, string $expected): void
|
||||
{
|
||||
if ($hash_type === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hash($input)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hash($input, $hash_type)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__hashLong
|
||||
* @dataProvider hashLongProvider
|
||||
* @testdox __hashLong $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHashLong(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hashLong($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,205 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\RandomKey
|
||||
* @coversDefaultClass \CoreLibs\Create\RandomKey
|
||||
* @testdox \CoreLibs\Create\RandomKey method tests
|
||||
*/
|
||||
final class CoreLibsCreateRandomKeyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function keyLenghtProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid key length' => [
|
||||
0 => 6,
|
||||
1 => true,
|
||||
2 => 6,
|
||||
],
|
||||
'negative key length' => [
|
||||
0 => -1,
|
||||
1 => false,
|
||||
2 => 4,
|
||||
],
|
||||
'tpp big key length' => [
|
||||
0 => 300,
|
||||
1 => false,
|
||||
2 => 4,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function randomKeyGenProvider(): array
|
||||
{
|
||||
return [
|
||||
'default key length' => [
|
||||
0 => null,
|
||||
1 => 4
|
||||
],
|
||||
'set -1 key length default' => [
|
||||
0 => -1,
|
||||
1 => 4,
|
||||
],
|
||||
'set too large key length' => [
|
||||
0 => 300,
|
||||
1 => 4,
|
||||
],
|
||||
'set override key lenght' => [
|
||||
0 => 6,
|
||||
1 => 6,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 1
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function keepKeyLengthProvider(): array
|
||||
{
|
||||
return [
|
||||
'set too large' => [
|
||||
0 => 6,
|
||||
1 => 300,
|
||||
2 => 6,
|
||||
],
|
||||
'set too small' => [
|
||||
0 => 8,
|
||||
1 => -2,
|
||||
2 => 8,
|
||||
],
|
||||
'change valid' => [
|
||||
0 => 10,
|
||||
1 => 6,
|
||||
2 => 6,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* run before each test and reset to default 4
|
||||
*
|
||||
* @before
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetKeyLength(): void
|
||||
{
|
||||
\CoreLibs\Create\RandomKey::setRandomKeyLength(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* check that first length is 4
|
||||
*
|
||||
* @covers ::getRandomKeyLength
|
||||
* @testWith [4]
|
||||
* @testdox getRandomKeyLength on init will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetRandomKeyLengthInit(int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\RandomKey::getRandomKeyLength()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setRandomKeyLength
|
||||
* @covers ::getRandomKeyLength
|
||||
* @dataProvider keyLenghtProvider
|
||||
* @testdox setRandomKeyLength $input will be $expected, compare to $compare [$_dataName]
|
||||
*
|
||||
* @param integer $input
|
||||
* @param boolean $expected
|
||||
* @param integer $compare
|
||||
* @return void
|
||||
*/
|
||||
public function testSetRandomKeyLength(int $input, bool $expected, int $compare): void
|
||||
{
|
||||
// set
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\RandomKey::setRandomKeyLength($input)
|
||||
);
|
||||
// read test, if false, use compare check
|
||||
if ($expected === false) {
|
||||
$input = $compare;
|
||||
}
|
||||
$this->assertEquals(
|
||||
$input,
|
||||
\CoreLibs\Create\RandomKey::getRandomKeyLength()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::randomKeyGeyn
|
||||
* @dataProvider randomKeyGenProvider
|
||||
* @testdox randomKeyGen use $input key length $expected [$_dataName]
|
||||
*
|
||||
* @param integer|null $input
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRandomKeyGen(?int $input, int $expected): void
|
||||
{
|
||||
if ($input === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\RandomKey::randomKeyGen())
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\RandomKey::randomKeyGen($input))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that if set to n and then invalid, it keeps the previous one
|
||||
* or if second change valid, second will be shown
|
||||
*
|
||||
* @covers ::setRandomKeyLength
|
||||
* @dataProvider keepKeyLengthProvider
|
||||
* @testdox keep setRandomKeyLength set with $input_valid and then $input_invalid will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_valid
|
||||
* @param integer $input_invalid
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testKeepKeyLength(int $input_valid, int $input_invalid, int $expected): void
|
||||
{
|
||||
\CoreLibs\Create\RandomKey::setRandomKeyLength($input_valid);
|
||||
\CoreLibs\Create\RandomKey::setRandomKeyLength($input_invalid);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\RandomKey::getRandomKeyLength()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,464 +0,0 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Debug\Support
|
||||
* @coversDefaultClass \CoreLibs\Debug\Support
|
||||
* @testdox \CoreLibs\Debug\Support method tests
|
||||
*/
|
||||
final class CoreLibsDebugSupportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printTimeProvider(): array
|
||||
{
|
||||
return [
|
||||
'default microtime' => [
|
||||
0 => null,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{8}$/",
|
||||
],
|
||||
'microtime -1' => [
|
||||
0 => -1,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{8}$/",
|
||||
],
|
||||
'microtime 0' => [
|
||||
0 => 0,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/",
|
||||
],
|
||||
'microtime 4' => [
|
||||
0 => 4,
|
||||
1 => "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{4}$/",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty array' => [
|
||||
0 => [],
|
||||
1 => "<pre>Array\n(\n)\n</pre>"
|
||||
],
|
||||
'simple array' => [
|
||||
0 => ['a', 'b'],
|
||||
1 => "<pre>Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n</pre>"
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printBoolProvider(): array
|
||||
{
|
||||
return [
|
||||
'true input default' => [
|
||||
0 => true,
|
||||
1 => [],
|
||||
2 => 'true'
|
||||
],
|
||||
'false input default' => [
|
||||
0 => false,
|
||||
1 => [],
|
||||
2 => 'false'
|
||||
],
|
||||
'false input param name' => [
|
||||
0 => false,
|
||||
1 => [
|
||||
'name' => 'param test'
|
||||
],
|
||||
2 => '<b>param test</b>: false'
|
||||
],
|
||||
'true input param name, true override' => [
|
||||
0 => true,
|
||||
1 => [
|
||||
'name' => 'param test',
|
||||
'true' => 'ok'
|
||||
],
|
||||
2 => '<b>param test</b>: ok'
|
||||
],
|
||||
'false input param name, true override, false override' => [
|
||||
0 => false,
|
||||
1 => [
|
||||
'name' => 'param test',
|
||||
'true' => 'ok',
|
||||
'false' => 'not',
|
||||
],
|
||||
2 => '<b>param test</b>: not'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function printToStringProvider(): array
|
||||
{
|
||||
return [
|
||||
'string' => [
|
||||
'a string',
|
||||
null,
|
||||
'a string',
|
||||
],
|
||||
'string with html chars, encode' => [
|
||||
'a string with <> &',
|
||||
true,
|
||||
'a string with <> &',
|
||||
],
|
||||
'string with html chars' => [
|
||||
'a string with <> &',
|
||||
null,
|
||||
'a string with <> &',
|
||||
],
|
||||
'a number' => [
|
||||
1234,
|
||||
null,
|
||||
'1234',
|
||||
],
|
||||
'a float number' => [
|
||||
1234.5678,
|
||||
null,
|
||||
'1234.5678',
|
||||
],
|
||||
'bool true' => [
|
||||
true,
|
||||
null,
|
||||
'TRUE',
|
||||
],
|
||||
'bool false' => [
|
||||
false,
|
||||
null,
|
||||
'FALSE',
|
||||
],
|
||||
'an array default' => [
|
||||
['a', 'b'],
|
||||
null,
|
||||
"<pre>Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n</pre>",
|
||||
],
|
||||
'an array, no html' => [
|
||||
['a', 'b'],
|
||||
true,
|
||||
"##HTMLPRE##"
|
||||
. "Array\n(\n"
|
||||
. " [0] => a\n"
|
||||
. " [1] => b\n"
|
||||
. ")\n"
|
||||
. "##/HTMLPRE##",
|
||||
],
|
||||
// resource
|
||||
'a resource' => [
|
||||
tmpfile(),
|
||||
null,
|
||||
'/^Resource id #\d+$/',
|
||||
],
|
||||
// object
|
||||
'an object' => [
|
||||
new \CoreLibs\Debug\Support(),
|
||||
null,
|
||||
'CoreLibs\Debug\Support',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function debugStringProvider(): array
|
||||
{
|
||||
// 0: input string
|
||||
// 1: replace
|
||||
// 2: html flag
|
||||
// 3: expected
|
||||
return [
|
||||
'null string, default' => [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'-'
|
||||
],
|
||||
'empty string, ... replace' => [
|
||||
'',
|
||||
'...',
|
||||
null,
|
||||
'...'
|
||||
],
|
||||
'filled string' => [
|
||||
'some string',
|
||||
null,
|
||||
null,
|
||||
'some string'
|
||||
],
|
||||
'string with html chars, encode' => [
|
||||
'a string with <> &',
|
||||
'-',
|
||||
true,
|
||||
'a string with <> &',
|
||||
],
|
||||
'string with html chars' => [
|
||||
'a string with <> &',
|
||||
'-',
|
||||
null,
|
||||
'a string with <> &',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printTime
|
||||
* @dataProvider printTimeProvider
|
||||
* @testdox printTime test with $microtime and match to regex [$_dataName]
|
||||
*
|
||||
* @param int|null $mircrotime
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintTime(?int $microtime, string $regex): void
|
||||
{
|
||||
if ($microtime === null) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
\CoreLibs\Debug\Support::printTime()
|
||||
);
|
||||
} else {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
\CoreLibs\Debug\Support::printTime($microtime)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printAr
|
||||
* @cover ::printArray
|
||||
* @dataProvider printArrayProvider
|
||||
* @testdox printAr/printArray $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintAr(array $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printAr($input),
|
||||
'assert printAr'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printArray($input),
|
||||
'assert printArray'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printBool
|
||||
* @dataProvider printBoolProvider
|
||||
* @testdox printBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param bool $input
|
||||
* @param array $params
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintBool(bool $input, array $params, string $expected): void
|
||||
{
|
||||
if (
|
||||
isset($params['name']) &&
|
||||
isset($params['true']) &&
|
||||
isset($params['false'])
|
||||
) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true'],
|
||||
$params['false']
|
||||
);
|
||||
} elseif (isset($params['name']) && isset($params['true'])) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name'],
|
||||
$params['true']
|
||||
);
|
||||
} elseif (isset($params['name'])) {
|
||||
$string = \CoreLibs\Debug\Support::printBool(
|
||||
$input,
|
||||
$params['name']
|
||||
);
|
||||
} else {
|
||||
$string = \CoreLibs\Debug\Support::printBool($input);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$string,
|
||||
'assert printBool'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::printToString
|
||||
* @dataProvider printToStringProvider
|
||||
* @testdox printToString $input with $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param boolean|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPrintToString($input, ?bool $flag, string $expected): void
|
||||
{
|
||||
if ($flag === null) {
|
||||
// if expected starts with / and ends with / then this is a regex compare
|
||||
if (substr($expected, 0, 1) == '/' && substr($expected, -1, 1) == '/') {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::printToString($input, $flag)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethod
|
||||
* @testWith ["testGetCallerMethod"]
|
||||
* @testdox getCallerMethod check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethod(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerMethod()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerMethodList
|
||||
* @testWith [["main", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"],["main", "run", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"]]
|
||||
* @testdox getCallerMethodList check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerMethodList(array $expected, array $expected_group): void
|
||||
{
|
||||
$compare = \CoreLibs\Debug\Support::getCallerMethodList();
|
||||
// if we direct call we have 10, if we call as folder we get 11
|
||||
if (count($compare) == 10) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerMethodList(),
|
||||
'assert expected 10'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected_group,
|
||||
\CoreLibs\Debug\Support::getCallerMethodList(),
|
||||
'assert expected group'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerClass
|
||||
* @testWith ["PHPUnit\\TextUI\\Command"]
|
||||
* @testdox getCallerClass check if it returns $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerClass(string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::getCallerClass()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::debugString
|
||||
* @dataProvider debugStringProvider
|
||||
* @testdox debugString $input with replace $replace and html $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string|null $replace
|
||||
* @param bool|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testDebugString(?string $input, ?string $replace, ?bool $flag, string $expected): void
|
||||
{
|
||||
if ($replace === null && $flag === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input),
|
||||
'assert all default'
|
||||
);
|
||||
} elseif ($flag === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input, $replace),
|
||||
'assert flag default'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Debug\Support::debugString($input, $replace, $flag),
|
||||
'assert all set'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,310 +0,0 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Language\GetLocale
|
||||
*
|
||||
* @coversDefaultClass \CoreLibs\Language\GetLocale
|
||||
* @testdox \CoreLibs\Language\GetLocale method tests
|
||||
*/
|
||||
final class CoreLibsLanguageGetLocaleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* set all constant variables that must be set before call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// default web page encoding setting
|
||||
if (!defined('DEFAULT_ENCODING')) {
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
}
|
||||
if (!defined('DEFAULT_LOCALE')) {
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
}
|
||||
// site
|
||||
if (!defined('SITE_ENCODING')) {
|
||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||
}
|
||||
if (!defined('SITE_LOCALE')) {
|
||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||
}
|
||||
// just set
|
||||
if (!defined('BASE')) {
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('INCLUDES')) {
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LANG')) {
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LOCALE')) {
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CONTENT_PATH')) {
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
// array session
|
||||
$_SESSION = [];
|
||||
global $_SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setLocaleProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: SESSION: DEFAULT_LOCALE
|
||||
// 5: SESSION: DEFAULT_CHARSET
|
||||
// 6: expected array
|
||||
'no params, all default constants' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
'no params, session charset and lang' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja_JP', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
'no params, session charset and lang short' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang (no sessions)
|
||||
'locale param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// different locale setting
|
||||
'locale complex param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja_JP.SJIS', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP.SJIS',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'SJIS',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// lang, domain, path (no override)
|
||||
'locale, domain and path, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', '', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// all params set (no override)
|
||||
'all parameter, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja', 'admin', 'UTF-8', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'long locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'de_CH.UTF-8@euro', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'de_CH.UTF-8@euro',
|
||||
'lang' => 'de_CH',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// TODO invalid params (bad path) (no override)
|
||||
// TODO param calls, but with override set
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLocale
|
||||
* @dataProvider setLocaleProvider
|
||||
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testsetLocale(
|
||||
?string $language,
|
||||
?string $domain,
|
||||
?string $encoding,
|
||||
?string $path,
|
||||
?string $SESSION_DEFAULT_LOCALE,
|
||||
?string $SESSION_DEFAULT_CHARSET,
|
||||
array $expected
|
||||
): void {
|
||||
$return_lang_settings = [];
|
||||
global $_SESSION;
|
||||
// set override
|
||||
if ($SESSION_DEFAULT_LOCALE !== null) {
|
||||
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
|
||||
}
|
||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
||||
}
|
||||
// function call
|
||||
if ($language === null && $domain === null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale();
|
||||
} elseif ($language !== null && $domain === null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language
|
||||
);
|
||||
} elseif ($language !== null && $domain !== null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain
|
||||
);
|
||||
} elseif ($language !== null && $domain !== null && $encoding !== null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding
|
||||
);
|
||||
} else {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding,
|
||||
$path
|
||||
);
|
||||
}
|
||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
||||
|
||||
foreach (
|
||||
[
|
||||
'locale', 'lang', 'domain', 'encoding', 'path'
|
||||
] as $key
|
||||
) {
|
||||
$value = $expected[$key];
|
||||
if (strpos($value, "/") === 0) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert regex failed for ' . $key
|
||||
);
|
||||
} else {
|
||||
// assert equal
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert equal failed for ' . $key
|
||||
);
|
||||
}
|
||||
}
|
||||
// unset all vars
|
||||
$_SESSION = [];
|
||||
unset($GLOBALS['OVERRIDE_LANG']);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -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__
|
||||
@@ -22,12 +22,9 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
self::$log = new \CoreLibs\Logging\Logging([
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-Create-Email-Test',
|
||||
'debug_all' => true,
|
||||
'echo_all' => false,
|
||||
'print_all' => true,
|
||||
'log_file_id' => 'CoreLibs-Create-Email-Test',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -624,7 +621,7 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
// force new set for each run
|
||||
self::$log->setLogUniqueId(true);
|
||||
// set on of unique log id
|
||||
self::$log->setLogPer('run', true);
|
||||
self::$log->setLogFlag(\CoreLibs\Logging\Logger\Flag::per_run);
|
||||
// init logger
|
||||
$status = \CoreLibs\Create\Email::sendEmail(
|
||||
$subject,
|
||||
@@ -646,7 +643,9 @@ final class CoreLibsCreateEmailTest extends TestCase
|
||||
// assert content: must load JSON from log file
|
||||
if ($status == 2) {
|
||||
// open file, get last entry with 'SEND EMAIL JSON' key
|
||||
$file = file_get_contents(self::$log->getLogFileName());
|
||||
$file = file_get_contents(
|
||||
self::$log->getLogFolder() . self::$log->getLogFile()
|
||||
);
|
||||
if ($file !== false) {
|
||||
// extract SEND EMAIL JSON line
|
||||
$found = preg_match_all("/^.* <SEND EMAIL JSON> - (.*)$/m", $file, $matches);
|
||||
426
4dev/tests/Create/CoreLibsCreateHashTest.php
Normal file
426
4dev/tests/Create/CoreLibsCreateHashTest.php
Normal file
@@ -0,0 +1,426 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\Hash
|
||||
* @coversDefaultClass \CoreLibs\Create\Hash
|
||||
* @testdox \CoreLibs\Create\Hash method tests
|
||||
*/
|
||||
final class CoreLibsCreateHashTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashData(): array
|
||||
{
|
||||
return [
|
||||
'hash tests' => [
|
||||
// this is the string
|
||||
'text' => 'Some String Text',
|
||||
// hash list special
|
||||
'crc32b_reverse' => 'c5c21d91', // crc32b (in revere)
|
||||
'sha1Short' => '4d2bc9ba0', // sha1Short
|
||||
// via hash
|
||||
'crc32b' => '911dc2c5', // hash: crc32b
|
||||
'adler32' => '31aa05f1', // hash: alder32
|
||||
'fnv132' => '9df444f9', // hash: fnv132
|
||||
'fnv1a32' => '2c5f91b9', // hash: fnv1a32
|
||||
'joaat' => '50dab846', // hash: joaat
|
||||
'ripemd160' => 'aeae3f041b20136451519edd9361570909300342', // hash: ripemd160,
|
||||
'sha256' => '9055080e022f224fa835929b80582b3c71c672206fa3a49a87412c25d9d42ceb', // hash: sha256
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function crc32bProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
$list[$name . ' to crc32b reverse'] = [
|
||||
0 => $values['text'],
|
||||
1 => $values['crc32b_reverse'],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sha1ShortProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
$list[$name . ' to sha1 short'] = [
|
||||
0 => $values['text'],
|
||||
1 => $values['crc32b_reverse'],
|
||||
2 => $values['sha1Short'],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* test all hash functions
|
||||
* NOTE: if we add new hash functions in the __hash method
|
||||
* they need to be added here too (and in the master hashData array too)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
foreach ([null, 'crc32b', 'adler32', 'fnv132', 'fnv1a32', 'joaat', 'ripemd160', 'sha256'] as $_hash_type) {
|
||||
// default value test
|
||||
if ($_hash_type === null) {
|
||||
$hash_type = \CoreLibs\Create\Hash::STANDARD_HASH_SHORT;
|
||||
} else {
|
||||
$hash_type = $_hash_type;
|
||||
}
|
||||
$list[$name . ' to ' . $hash_type] = [
|
||||
0 => $values['text'],
|
||||
1 => $_hash_type,
|
||||
2 => $values[$hash_type]
|
||||
];
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashLongProvider(): array
|
||||
{
|
||||
$hash_source = 'Some String Text';
|
||||
return [
|
||||
'Long Hash check: ' . \CoreLibs\Create\Hash::STANDARD_HASH_LONG => [
|
||||
$hash_source,
|
||||
hash(\CoreLibs\Create\Hash::STANDARD_HASH_LONG, $hash_source)
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashStandardProvider(): array
|
||||
{
|
||||
$hash_source = 'Some String Text';
|
||||
return [
|
||||
'Long Hash check: ' . \CoreLibs\Create\Hash::STANDARD_HASH => [
|
||||
$hash_source,
|
||||
hash(\CoreLibs\Create\Hash::STANDARD_HASH, $hash_source)
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__crc32b
|
||||
* @dataProvider crc32bProvider
|
||||
* @testdox __crc32b $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCrc32b(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__crc32b($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* phpcs:disable Generic.Files.LineLength
|
||||
* @covers ::__sha1Short
|
||||
* @covers ::__crc32b
|
||||
* @covers ::sha1Short
|
||||
* @dataProvider sha1ShortProvider
|
||||
* @testdox __sha1Short/__crc32b/sha1short $input will be $expected (crc32b) and $expected_sha1 (sha1 short) [$_dataName]
|
||||
* phpcs:enable Generic.Files.LineLength
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSha1Short(string $input, string $expected, string $expected_sha1): void
|
||||
{
|
||||
// uses crc32b
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input),
|
||||
'__sha1Short depreacted'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input, false),
|
||||
'__sha1Short (false) depreacted'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__crc32b($input),
|
||||
'__crc32b'
|
||||
);
|
||||
// sha1 type
|
||||
$this->assertEquals(
|
||||
$expected_sha1,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input, true),
|
||||
'__sha1Short (true) depreacted'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_sha1,
|
||||
\CoreLibs\Create\Hash::sha1Short($input),
|
||||
'sha1Short'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__hash
|
||||
* @covers ::hashShort
|
||||
* @covers ::hashShort
|
||||
* @dataProvider hashProvider
|
||||
* @testdox __hash/hashShort/hash $input with $hash_type will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|null $hash_type
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHash(string $input, ?string $hash_type, string $expected): void
|
||||
{
|
||||
if ($hash_type === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hash($input),
|
||||
'__hash'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::hashShort($input),
|
||||
'hashShort'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hash($input, $hash_type),
|
||||
'__hash with hash type'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::hash($input, $hash_type),
|
||||
'hash with hash type'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__hashLong
|
||||
* @covers ::hashLong
|
||||
* @dataProvider hashLongProvider
|
||||
* @testdox __hashLong/hashLong $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHashLong(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hashLong($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::hashLong($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hash
|
||||
* @covers ::hashStd
|
||||
* @dataProvider hashStandardProvider
|
||||
* @testdox hash/hashStd $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHashStandard(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::hashStd($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::hash($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hash
|
||||
* @testdox hash with invalid type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidHashType(): void
|
||||
{
|
||||
$hash_source = 'Some String Text';
|
||||
$expected = hash(\CoreLibs\Create\Hash::STANDARD_HASH, $hash_source);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::hash($hash_source, 'DOES_NOT_EXIST')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this only tests default sha256
|
||||
*
|
||||
* @covers ::hashHmac
|
||||
* @testdox hash hmac test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHashMac(): void
|
||||
{
|
||||
$hash_key = 'FIX KEY';
|
||||
$hash_source = 'Some String Text';
|
||||
$expected = '16479b3ef6fa44e1cdd8b2dcfaadf314d1a7763635e8738f1e7996d714d9b6bf';
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::hashHmac($hash_source, $hash_key)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hashHmac
|
||||
* @testdox hash hmac with invalid type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidHashMacType(): void
|
||||
{
|
||||
$hash_key = 'FIX KEY';
|
||||
$hash_source = 'Some String Text';
|
||||
$expected = hash_hmac(\CoreLibs\Create\Hash::STANDARD_HASH, $hash_source, $hash_key);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::hashHmac($hash_source, $hash_key, 'DOES_NOT_EXIST')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function providerHashTypes(): array
|
||||
{
|
||||
return [
|
||||
'Hash crc32b' => [
|
||||
'crc32b',
|
||||
true,
|
||||
false,
|
||||
],
|
||||
'Hash adler32' => [
|
||||
'adler32',
|
||||
true,
|
||||
false,
|
||||
],
|
||||
'HAsh fnv132' => [
|
||||
'fnv132',
|
||||
true,
|
||||
false,
|
||||
],
|
||||
'Hash fnv1a32' => [
|
||||
'fnv1a32',
|
||||
true,
|
||||
false,
|
||||
],
|
||||
'Hash: joaat' => [
|
||||
'joaat',
|
||||
true,
|
||||
false,
|
||||
],
|
||||
'Hash: ripemd160' => [
|
||||
'ripemd160',
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'Hash: sha256' => [
|
||||
'sha256',
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'Hash: invalid' => [
|
||||
'invalid',
|
||||
false,
|
||||
false
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::isValidHashType
|
||||
* @covers ::isValidHashHmacType
|
||||
* @dataProvider providerHashTypes
|
||||
* @testdox check if $hash_type is valid for hash $hash_ok and hash hmac $hash_hmac_ok [$_dataName]
|
||||
*
|
||||
* @param string $hash_type
|
||||
* @param bool $hash_ok
|
||||
* @param bool $hash_hmac_ok
|
||||
* @return void
|
||||
*/
|
||||
public function testIsValidHashAndHashHmacTypes(string $hash_type, bool $hash_ok, bool $hash_hmac_ok): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$hash_ok,
|
||||
\CoreLibs\Create\Hash::isValidHashType($hash_type),
|
||||
'hash valid'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$hash_hmac_ok,
|
||||
\CoreLibs\Create\Hash::isValidHashHmacType($hash_type),
|
||||
'hash hmac valid'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
135
4dev/tests/Create/CoreLibsCreateRandomKeyTest.php
Normal file
135
4dev/tests/Create/CoreLibsCreateRandomKeyTest.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\RandomKey
|
||||
* @coversDefaultClass \CoreLibs\Create\RandomKey
|
||||
* @testdox \CoreLibs\Create\RandomKey method tests
|
||||
*/
|
||||
final class CoreLibsCreateRandomKeyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function randomKeyGenProvider(): array
|
||||
{
|
||||
return [
|
||||
// just key length
|
||||
'default key length, default char set' => [
|
||||
0 => null,
|
||||
1 => \CoreLibs\Create\RandomKey::KEY_LENGTH_DEFAULT
|
||||
],
|
||||
'set -1 key length, default char set' => [
|
||||
0 => -1,
|
||||
1 => \CoreLibs\Create\RandomKey::KEY_LENGTH_DEFAULT,
|
||||
],
|
||||
'set 0 key length, default char set' => [
|
||||
0 => -1,
|
||||
1 => \CoreLibs\Create\RandomKey::KEY_LENGTH_DEFAULT,
|
||||
],
|
||||
'set too large key length, default char set' => [
|
||||
0 => 300,
|
||||
1 => \CoreLibs\Create\RandomKey::KEY_LENGTH_DEFAULT,
|
||||
],
|
||||
'set override key lenght, default char set' => [
|
||||
0 => 6,
|
||||
1 => 6,
|
||||
],
|
||||
// just character set
|
||||
'default key length, different char set A' => [
|
||||
0 => \CoreLibs\Create\RandomKey::KEY_LENGTH_DEFAULT,
|
||||
1 => \CoreLibs\Create\RandomKey::KEY_LENGTH_DEFAULT,
|
||||
2 => [
|
||||
'A', 'B', 'C'
|
||||
],
|
||||
],
|
||||
'different key length, different char set B' => [
|
||||
0 => 16,
|
||||
1 => 16,
|
||||
2 => [
|
||||
'A', 'B', 'C'
|
||||
],
|
||||
3 => [
|
||||
'1', '2', '3'
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Alternative more efficient version using strpos
|
||||
/**
|
||||
* check if all characters are in set
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $allowed_chars
|
||||
* @return bool
|
||||
*/
|
||||
private function allCharsInSet(string $input, string $allowed_chars): bool
|
||||
{
|
||||
$inputLength = strlen($input);
|
||||
|
||||
for ($i = 0; $i < $inputLength; $i++) {
|
||||
if (strpos($allowed_chars, $input[$i]) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::randomKeyGeyn
|
||||
* @dataProvider randomKeyGenProvider
|
||||
* @testdox randomKeyGen use $input key length $expected [$_dataName]
|
||||
*
|
||||
* @param integer|null $input
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRandomKeyGen(?int $input, int $expected, array ...$key_range): void
|
||||
{
|
||||
$__key_data = \CoreLibs\Create\RandomKey::KEY_CHARACTER_RANGE_DEFAULT;
|
||||
if (count($key_range)) {
|
||||
$__key_data = join('', array_unique(array_merge(...$key_range)));
|
||||
}
|
||||
if ($input === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\RandomKey::randomKeyGen())
|
||||
);
|
||||
} elseif ($input !== null && !count($key_range)) {
|
||||
$random_key = \CoreLibs\Create\RandomKey::randomKeyGen($input);
|
||||
$this->assertTrue(
|
||||
$this->allCharsInSet($random_key, $__key_data),
|
||||
'Characters not valid'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen($random_key),
|
||||
'String length not matching'
|
||||
);
|
||||
} elseif (count($key_range)) {
|
||||
$random_key = \CoreLibs\Create\RandomKey::randomKeyGen($input, ...$key_range);
|
||||
$this->assertTrue(
|
||||
$this->allCharsInSet($random_key, $__key_data),
|
||||
'Characters not valid'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen($random_key),
|
||||
'String length not matching'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -22,7 +22,6 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
public function sessionProvider(): array
|
||||
{
|
||||
// 0: session name as parameter or for GLOBAL value
|
||||
// 1: type p: parameter, g: global, d: php.ini default
|
||||
// 2: mock data as array
|
||||
// checkCliStatus: true/false,
|
||||
// getSessionStatus: PHP_SESSION_DISABLED for abort,
|
||||
@@ -30,12 +29,11 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
// setSessionName: true/false,
|
||||
// checkActiveSession: true/false, [1st call, 2nd call]
|
||||
// getSessionId: string or false
|
||||
// 3: exepcted name (session)
|
||||
// 4: expected error string
|
||||
// 3: exepcted name (session)]
|
||||
// 4: auto write close flag
|
||||
return [
|
||||
'session parameter' => [
|
||||
'sessionNameParameter',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
@@ -44,11 +42,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameParameter',
|
||||
''
|
||||
null,
|
||||
],
|
||||
'session globals' => [
|
||||
'sessionNameGlobals',
|
||||
'g',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
@@ -57,11 +54,12 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameGlobals',
|
||||
''
|
||||
[
|
||||
'auto_write_close' => false,
|
||||
],
|
||||
],
|
||||
'session name default' => [
|
||||
'',
|
||||
'd',
|
||||
'auto write close' => [
|
||||
'sessionNameAutoWriteClose',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
@@ -69,95 +67,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
''
|
||||
],
|
||||
// error checks
|
||||
// 1: we are in cli
|
||||
'on cli error' => [
|
||||
'',
|
||||
'd',
|
||||
'sessionNameAutoWriteClose',
|
||||
[
|
||||
'checkCliStatus' => true,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
'auto_write_close' => true,
|
||||
],
|
||||
'',
|
||||
'[SESSION] No sessions in php cli'
|
||||
],
|
||||
// 2: session disabled
|
||||
'session disabled error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_DISABLED,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Sessions are disabled'
|
||||
],
|
||||
// 3: invalid session name: string
|
||||
'invalid name chars error' => [
|
||||
'1invalid$session#;',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => false,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Invalid session name: 1invalid$session#;'
|
||||
],
|
||||
// 3: invalid session name: only numbers
|
||||
'invalid name numbers only error' => [
|
||||
'123',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => false,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Invalid session name: 123'
|
||||
],
|
||||
// 3: invalid session name: invalid name short
|
||||
// 3: invalid session name: too long (128)
|
||||
// 4: failed to start session (2nd false on check active session)
|
||||
'invalid name numbers only error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, false],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Failed to activate session'
|
||||
],
|
||||
// 5: get session id return false
|
||||
'invalid name numbers only error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => false
|
||||
],
|
||||
'',
|
||||
'[SESSION] getSessionId did not return a session id'
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -170,29 +83,24 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
* @testdox startSession $input name for $type will be $expected (error: $expected_error) [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $type
|
||||
* @param array<mixed> $mock_data
|
||||
* @param string $expected
|
||||
* @param string $expected_error
|
||||
* @param array<string,mixed> $options
|
||||
* @return void
|
||||
*/
|
||||
public function testStartSession(
|
||||
string $input,
|
||||
string $type,
|
||||
array $mock_data,
|
||||
string $expected,
|
||||
string $expected_error
|
||||
?array $options,
|
||||
): void {
|
||||
// override expected
|
||||
if ($type == 'd') {
|
||||
$expected = ini_get('session.name');
|
||||
}
|
||||
/** @var \CoreLibs\Create\Session&MockObject $session_mock */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
[
|
||||
'checkCliStatus', 'getSessionStatus', 'checkActiveSession',
|
||||
'setSessionName', 'startSessionCall', 'getSessionId',
|
||||
'checkCliStatus',
|
||||
'getSessionStatus', 'checkActiveSession',
|
||||
'getSessionId',
|
||||
'getSessionName'
|
||||
]
|
||||
);
|
||||
@@ -211,12 +119,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
$mock_data['checkActiveSession'][0],
|
||||
$mock_data['checkActiveSession'][1],
|
||||
);
|
||||
// dummy set for session name
|
||||
$session_mock->method('setSessionName')->with($input)->willReturn($mock_data['setSessionName']);
|
||||
// set session name & return bsed on request data
|
||||
$session_mock->method('getSessionName')->willReturn($expected);
|
||||
// will not return anything
|
||||
$session_mock->method('startSessionCall');
|
||||
// in test case only return string
|
||||
// false: will return false
|
||||
$session_mock->method('getSessionId')->willReturn($mock_data['getSessionId']);
|
||||
@@ -224,20 +128,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
// regex for session id
|
||||
$ression_id_regex = "/^\w+$/";
|
||||
|
||||
unset($GLOBALS['SET_SESSION_NAME']);
|
||||
$session_id = '';
|
||||
switch ($type) {
|
||||
case 'p':
|
||||
$session_id = $session_mock->startSession($input);
|
||||
break;
|
||||
case 'g':
|
||||
$GLOBALS['SET_SESSION_NAME'] = $input;
|
||||
$session_id = $session_mock->startSession();
|
||||
break;
|
||||
case 'd':
|
||||
$session_id = $session_mock->startSession();
|
||||
break;
|
||||
}
|
||||
$session_id = $session_mock->getSessionId();
|
||||
// asert checks
|
||||
if (!empty($session_id)) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
@@ -253,16 +144,82 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
$expected,
|
||||
$session_mock->getSessionName()
|
||||
);
|
||||
} else {
|
||||
// false checks
|
||||
$this->assertEquals(
|
||||
$expected_error,
|
||||
$session_mock->getErrorStr(),
|
||||
'error assert'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerSessionException(): array
|
||||
{
|
||||
return [
|
||||
'not cli' => [
|
||||
'TEST_EXCEPTION',
|
||||
\RuntimeException::class,
|
||||
1,
|
||||
'/^\[SESSION\] No sessions in php cli$/',
|
||||
],
|
||||
/* 'session disabled ' => [
|
||||
'TEST_EXCEPTION',
|
||||
\RuntimeException::class,
|
||||
2,
|
||||
'/^\[SESSION\] Sessions are disabled/'
|
||||
],
|
||||
'invalid session name' => [
|
||||
'--#as^-292p-',
|
||||
\UnexpectedValueException::class,
|
||||
3,
|
||||
'/^\[SESSION\] Invalid session name: /'
|
||||
],
|
||||
'failed to activate session' => [
|
||||
'TEST_EXCEPTION',
|
||||
\RuntimeException::class,
|
||||
4,
|
||||
'/^\[SESSION\] Failed to activate session/'
|
||||
],
|
||||
'expired session' => [
|
||||
\RuntimeException::class,
|
||||
5,
|
||||
'/^\[SESSION\] Expired session found/'
|
||||
],
|
||||
'not a valid session id returned' => [
|
||||
\UnexpectedValueException::class,
|
||||
6,
|
||||
'/^\[SESSION\] getSessionId did not return a session id/'
|
||||
], */
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* exception checks
|
||||
*
|
||||
* @covers ::initSession
|
||||
* @dataProvider providerSessionException
|
||||
* @testdox create session $session_name with exception $exception ($exception_code) [$_dataName]
|
||||
*
|
||||
* @param string $session_name
|
||||
* @param string $exception
|
||||
* @param int $exception_code
|
||||
* @param string $expected_error
|
||||
* @return void
|
||||
*/
|
||||
public function testSessionException(
|
||||
string $session_name,
|
||||
string $exception,
|
||||
int $exception_code,
|
||||
string $expected_error,
|
||||
): void {
|
||||
//
|
||||
// throws only on new Object creation
|
||||
$this->expectException($exception);
|
||||
$this->expectExceptionCode($exception_code);
|
||||
$this->expectExceptionMessageMatches($expected_error);
|
||||
// cannot set ini after header sent, plus we are on command line there are no headers
|
||||
new \CoreLibs\Create\Session($session_name, ['session_strict' => false]);
|
||||
}
|
||||
|
||||
/**
|
||||
* provider for session name check
|
||||
*
|
||||
@@ -326,109 +283,147 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sessionDataProvider(): array
|
||||
public function providerSessionData(): array
|
||||
{
|
||||
return [
|
||||
'test' => [
|
||||
'foo',
|
||||
'bar',
|
||||
'bar',
|
||||
null,
|
||||
],
|
||||
'int key test' => [
|
||||
123,
|
||||
'bar',
|
||||
'bar',
|
||||
\UnexpectedValueException::class
|
||||
],
|
||||
// more complex value tests
|
||||
'array values' => [
|
||||
'array',
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
null,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// NOTE: with auto start session, we cannot test this in the command line
|
||||
|
||||
/**
|
||||
* method call test
|
||||
*
|
||||
* @covers ::setS
|
||||
* @covers ::getS
|
||||
* @covers ::issetS
|
||||
* @covers ::unsetS
|
||||
* @dataProvider sessionDataProvider
|
||||
* @testdox setS/getS/issetS/unsetS $name with $input is $expected [$_dataName]
|
||||
* @covers ::set
|
||||
* @covers ::get
|
||||
* @covers ::isset
|
||||
* @covers ::unset
|
||||
* @dataProvider providerSessionData
|
||||
* @testdox set/get/isset/unset $name with $input is $expected ($exception) [$_dataName]
|
||||
*
|
||||
* @param string|int $name
|
||||
* @param mixed $input
|
||||
* @param mixed $expected
|
||||
* @param ?mixed $exception
|
||||
* @return void
|
||||
*/
|
||||
public function testMethodSetGet($name, $input, $expected): void
|
||||
public function testMethodSetGet($name, $input, $expected, $exception): void
|
||||
{
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session->setS($name, $input);
|
||||
if (\CoreLibs\Get\System::checkCLI()) {
|
||||
$this->markTestSkipped('Cannot run testMethodSetGet in CLI');
|
||||
}
|
||||
$session = new \CoreLibs\Create\Session('TEST_METHOD');
|
||||
if ($expected !== null) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
$session->set($name, $input);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$session->getS($name),
|
||||
$session->get($name),
|
||||
'method set assert'
|
||||
);
|
||||
// isset true
|
||||
$this->assertTrue(
|
||||
$session->issetS($name),
|
||||
$session->isset($name),
|
||||
'method isset assert ok'
|
||||
);
|
||||
$session->unsetS($name);
|
||||
$session->unset($name);
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->getS($name),
|
||||
$session->get($name),
|
||||
'method unset assert'
|
||||
);
|
||||
// iset false
|
||||
// isset false
|
||||
$this->assertFalse(
|
||||
$session->issetS($name),
|
||||
$session->isset($name),
|
||||
'method isset assert false'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* magic call test
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__set
|
||||
* @covers ::__get
|
||||
* @covers ::__isset
|
||||
* @covers ::__unset
|
||||
* @dataProvider sessionDataProvider
|
||||
* @testdox __set/__get/__iseet/__unset $name with $input is $expected [$_dataName]
|
||||
* @return array
|
||||
*/
|
||||
public function providerSessionDataMany(): array
|
||||
{
|
||||
return [
|
||||
'valid set' => [
|
||||
[
|
||||
'foo 1' => 'bar 1',
|
||||
'foo 2' => 'bar 1',
|
||||
],
|
||||
[
|
||||
'foo 1' => 'bar 1',
|
||||
'foo 2' => 'bar 1',
|
||||
],
|
||||
null,
|
||||
],
|
||||
'invalid entry' => [
|
||||
[
|
||||
'foo 1' => 'bar 1',
|
||||
123 => 'bar 1',
|
||||
],
|
||||
[
|
||||
'foo 1' => 'bar 1',
|
||||
],
|
||||
\UnexpectedValueException::class
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string|int $name
|
||||
* @param mixed $input
|
||||
* @param mixed $expected
|
||||
* @covers ::setMany
|
||||
* @covers ::getMany
|
||||
* @dataProvider providerSessionDataMany
|
||||
* @testdox setMany/getMany/unsetMany $set is $expected ($exception) [$_dataName]
|
||||
*
|
||||
* @param array<string|int,mixed> $set
|
||||
* @param array<string,mixed> $expected
|
||||
* @param ?mixed $exception
|
||||
* @return void
|
||||
*/
|
||||
public function testMagicSetGet($name, $input, $expected): void
|
||||
public function testMany($set, $expected, $exception): void
|
||||
{
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session->$name = $input;
|
||||
if (\CoreLibs\Get\System::checkCLI()) {
|
||||
$this->markTestSkipped('Cannot run testMethodSetGet in CLI');
|
||||
}
|
||||
$session = new \CoreLibs\Create\Session('TEST_METHOD');
|
||||
if ($expected !== null) {
|
||||
$this->expectException($exception);
|
||||
}
|
||||
$session->setMany($set);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$session->$name,
|
||||
'magic set assert'
|
||||
$session->getMany(array_keys($set)),
|
||||
'set many failed'
|
||||
);
|
||||
// isset true
|
||||
$this->assertTrue(
|
||||
isset($session->$name),
|
||||
'magic isset assert ok'
|
||||
);
|
||||
unset($session->$name);
|
||||
$session->unsetMany(array_keys($set));
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->$name,
|
||||
'magic unset assert'
|
||||
);
|
||||
// isset true
|
||||
$this->assertFalse(
|
||||
isset($session->$name),
|
||||
'magic isset assert false'
|
||||
[],
|
||||
$session->getMany(array_keys($set)),
|
||||
'unset many failed'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -442,27 +437,30 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
*/
|
||||
public function testUnsetAll(): void
|
||||
{
|
||||
if (\CoreLibs\Get\System::checkCLI()) {
|
||||
$this->markTestSkipped('Cannot run testUnsetAll in CLI');
|
||||
}
|
||||
$test_values = [
|
||||
'foo' => 'abc',
|
||||
'bar' => '123'
|
||||
];
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session = new \CoreLibs\Create\Session('TEST_UNSET');
|
||||
foreach ($test_values as $name => $value) {
|
||||
$session->setS($name, $value);
|
||||
$session->set($name, $value);
|
||||
// confirm set
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$session->getS($name),
|
||||
$session->get($name),
|
||||
'set assert: ' . $name
|
||||
);
|
||||
}
|
||||
// unset all
|
||||
$session->unsetAllS();
|
||||
$session->clear();
|
||||
// check unset
|
||||
foreach (array_keys($test_values) as $name) {
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->getS($name),
|
||||
$session->get($name),
|
||||
'unsert assert: ' . $name
|
||||
);
|
||||
}
|
||||
@@ -21,45 +21,83 @@ final class CoreLibsCreateUidsTest extends TestCase
|
||||
public function uniqIdProvider(): array
|
||||
{
|
||||
return [
|
||||
// number length
|
||||
'too short' => [
|
||||
0 => 1,
|
||||
1 => 4,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 10' => [
|
||||
0 => 10,
|
||||
1 => 10,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 9, auto length' => [
|
||||
0 => 9,
|
||||
1 => 8,
|
||||
2 => null
|
||||
],
|
||||
'valid length: 9, force length' => [
|
||||
0 => 9,
|
||||
1 => 9,
|
||||
2 => true,
|
||||
],
|
||||
'very long: 512' => [
|
||||
0 => 512,
|
||||
1 => 512,
|
||||
2 => null
|
||||
],
|
||||
// below is all legacy
|
||||
'md5 hash' => [
|
||||
0 => 'md5',
|
||||
1 => 32,
|
||||
2 => null
|
||||
],
|
||||
'sha256 hash' => [
|
||||
0 => 'sha256',
|
||||
1 => 64
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'ripemd160 hash' => [
|
||||
0 => 'ripemd160',
|
||||
1 => 40
|
||||
1 => 40,
|
||||
2 => null
|
||||
],
|
||||
'adler32 hash' => [
|
||||
0 => 'adler32',
|
||||
1 => 8
|
||||
1 => 8,
|
||||
2 => null
|
||||
],
|
||||
'not in list hash but valid' => [
|
||||
'not in list, set default length' => [
|
||||
0 => 'sha3-512',
|
||||
1 => strlen(hash('sha3-512', 'A'))
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'default hash not set' => [
|
||||
0 => null,
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'invalid name' => [
|
||||
0 => 'iamnotavalidhash',
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_HASH => [
|
||||
0 => \CoreLibs\Create\Uids::DEFAULT_HASH,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::DEFAULT_HASH, 'A'))
|
||||
// auto calls
|
||||
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH => [
|
||||
0 => \CoreLibs\Create\Uids::DEFAULT_UNNIQ_ID_LENGTH,
|
||||
1 => 64,
|
||||
2 => null
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_LONG,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A'))
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A')),
|
||||
2 => null
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_SHORT => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_SHORT,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A'))
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A')),
|
||||
2 => null
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -83,6 +121,7 @@ final class CoreLibsCreateUidsTest extends TestCase
|
||||
* must match 7e78fe0d-59b8-4637-af7f-e88d221a7d1e
|
||||
*
|
||||
* @covers ::uuidv4
|
||||
* @covers ::validateUuidv4
|
||||
* @testdox uuidv4 check that return is matching regex [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
@@ -91,13 +130,18 @@ final class CoreLibsCreateUidsTest extends TestCase
|
||||
{
|
||||
$uuid = \CoreLibs\Create\Uids::uuidv4();
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/',
|
||||
$uuid
|
||||
'/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
|
||||
$uuid,
|
||||
'Failed regex check'
|
||||
);
|
||||
$this->assertTrue(
|
||||
\CoreLibs\Create\Uids::validateUuuidv4($uuid),
|
||||
'Failed validate regex method'
|
||||
);
|
||||
$this->assertFalse(
|
||||
\CoreLibs\Create\Uids::validateUuuidv4('not-a-uuidv4'),
|
||||
'Failed wrong uuid validated as true'
|
||||
);
|
||||
// $this->assertStringMatchesFormat(
|
||||
// '%4s%4s-%4s-%4s-%4s-%4s%4s%4s',
|
||||
// $uuid
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,25 +149,26 @@ final class CoreLibsCreateUidsTest extends TestCase
|
||||
*
|
||||
* @covers ::uniqId
|
||||
* @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 bool|null $flag
|
||||
* @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) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId())
|
||||
);
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId());
|
||||
} elseif ($flag === null) {
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input));
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId($input))
|
||||
);
|
||||
$uniq_id_length = strlen(\CoreLibs\Create\Uids::uniqId($input, $flag));
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$uniq_id_length
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -10,7 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
* Test class for DB\Extended\ArrayIO
|
||||
* This will only test the PgSQL parts
|
||||
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
||||
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
||||
* @testdox \CoreLibs\Extended\ArrayIO method tests for extended DB interface
|
||||
*/
|
||||
final class CoreLibsDBExtendedArrayIOTest extends TestCase
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,11 +10,13 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Debug\Logging
|
||||
* @coversDefaultClass \CoreLibs\Debug\Logging
|
||||
* @testdox \CoreLibs\Debug\Logging method tests
|
||||
* @coversDefaultClass \CoreLibs\Debug\LoggingLegacy
|
||||
* @testdox \CoreLibs\Debug\LoggingLegacy method tests
|
||||
*/
|
||||
final class CoreLibsDebugLoggingTest extends TestCase
|
||||
final class CoreLibsDebugLoggingLegacyTest extends TestCase
|
||||
{
|
||||
private const LOG_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* test set for options BASIC
|
||||
*
|
||||
@@ -23,7 +25,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
* 1: expected
|
||||
* 2: override
|
||||
* override:
|
||||
* - constant for COSNTANTS
|
||||
* - constant for CONSTANTS
|
||||
* - global for _GLOBALS
|
||||
*
|
||||
* @return array
|
||||
@@ -33,17 +35,20 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
return [
|
||||
'log folder set' => [
|
||||
[
|
||||
'log_folder' => '/tmp'
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'testClassInit'
|
||||
],
|
||||
[
|
||||
'log_folder' => '/tmp/',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
'debug_all' => false,
|
||||
'print_all' => false,
|
||||
],
|
||||
[]
|
||||
],
|
||||
'nothing set' => [
|
||||
null,
|
||||
[
|
||||
'file_id' => 'testClassInit'
|
||||
],
|
||||
[
|
||||
'log_folder' => getcwd() . DIRECTORY_SEPARATOR,
|
||||
'debug_all' => false,
|
||||
@@ -51,30 +56,33 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
],
|
||||
[]
|
||||
],
|
||||
'no options set, constant set' => [
|
||||
null,
|
||||
'no options set, constant set [DEPRECATED]' => [
|
||||
[
|
||||
'log_folder' => str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR . 'log/',
|
||||
'file_id' => 'testClassInit'
|
||||
],
|
||||
[
|
||||
'log_folder' => str_replace(DIRECTORY_SEPARATOR . 'configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR,
|
||||
'debug_all' => false,
|
||||
'print_all' => false,
|
||||
],
|
||||
[
|
||||
'constant' => [
|
||||
'BASE' => str_replace('/configs', '', __DIR__)
|
||||
'BASE' => str_replace(DIRECTORY_SEPARATOR . 'configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR,
|
||||
'LOG' => 'log/'
|
||||
'LOG' => 'log' . DIRECTORY_SEPARATOR
|
||||
]
|
||||
]
|
||||
],
|
||||
'standard test set' => [
|
||||
[
|
||||
'log_folder' => '/tmp',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'testClassInit',
|
||||
'debug_all' => true,
|
||||
'print_all' => true,
|
||||
],
|
||||
[
|
||||
'log_folder' => '/tmp/',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
|
||||
'debug_all' => true,
|
||||
'print_all' => true,
|
||||
],
|
||||
@@ -89,35 +97,66 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
* @dataProvider optionsProvider
|
||||
* @testdox init test [$_dataName]
|
||||
*
|
||||
* @param array|null $options
|
||||
* @param array $options
|
||||
* @param array $expected
|
||||
* @param array $override
|
||||
* @return void
|
||||
*/
|
||||
public function testClassInit(?array $options, array $expected, array $override): void
|
||||
public function testClassInit(array $options, array $expected, array $override): void
|
||||
{
|
||||
if (!empty($override['constant'])) {
|
||||
foreach ($override['constant'] as $var => $value) {
|
||||
define($var, $value);
|
||||
if (!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 ($options === null) {
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
} else {
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
// 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);
|
||||
}
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy($options);
|
||||
// reset error handler
|
||||
restore_error_handler();
|
||||
// check that settings match
|
||||
$this->assertEquals(
|
||||
$expected['log_folder'],
|
||||
$log->getSetting('log_folder')
|
||||
$log->getSetting('log_folder'),
|
||||
'log folder not matching'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected['debug_all'],
|
||||
$log->getSetting('debug_output_all')
|
||||
$log->getSetting('debug_output_all'),
|
||||
'debug all flag not matching'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected['print_all'],
|
||||
$log->getSetting('print_output_all')
|
||||
$log->getSetting('print_output_all'),
|
||||
'print all flag not matching'
|
||||
);
|
||||
// print "LOG: " . $log->getSetting('log_folder') . "\n";
|
||||
// print "DEBUG: " . $log->getSetting('debug_output_all') . "\n";
|
||||
@@ -134,17 +173,23 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
// 0: options
|
||||
// 1: expected
|
||||
// 2: override
|
||||
// 3: exception message
|
||||
return [
|
||||
'no log id set' => [
|
||||
null,
|
||||
[
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
],
|
||||
[
|
||||
'log_file_id' => ''
|
||||
],
|
||||
[]
|
||||
[],
|
||||
null
|
||||
],
|
||||
// set log id manually afterwards
|
||||
'set log id manually' => [
|
||||
null,
|
||||
[
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
],
|
||||
[
|
||||
'log_file_id' => '',
|
||||
'set_log_file_id' => 'abc123',
|
||||
@@ -154,21 +199,26 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
'values' => [
|
||||
'log_file_id' => 'abc123'
|
||||
]
|
||||
]
|
||||
],
|
||||
null
|
||||
],
|
||||
// set log id from options
|
||||
'set log id via options' => [
|
||||
[
|
||||
'file_id' => 'abc456',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
],
|
||||
[
|
||||
'log_file_id' => 'abc456'
|
||||
],
|
||||
[]
|
||||
[],
|
||||
null
|
||||
],
|
||||
// set log id from GLOBALS [DEPRECATED]
|
||||
'set log id via globals' => [
|
||||
null,
|
||||
'set log id via globals [DEPRECATED]' => [
|
||||
[
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
],
|
||||
[
|
||||
'log_file_id' => 'def123'
|
||||
],
|
||||
@@ -176,11 +226,14 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
'globals' => [
|
||||
'LOG_FILE_ID' => 'def123'
|
||||
]
|
||||
]
|
||||
],
|
||||
'options: file_id must be set. Setting via LOG_FILE_ID global variable is deprecated'
|
||||
],
|
||||
// set log id from CONSTANT [DEPRECATED]
|
||||
'set log id via constant' => [
|
||||
null,
|
||||
'set log id via constant [DEPRECATED]' => [
|
||||
[
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
],
|
||||
[
|
||||
'log_file_id' => 'ghi123'
|
||||
],
|
||||
@@ -192,12 +245,14 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
'constant' => [
|
||||
'LOG_FILE_ID' => 'ghi123'
|
||||
]
|
||||
]
|
||||
],
|
||||
'options: file_id must be set. Setting via LOG_FILE_ID constant is deprecated'
|
||||
],
|
||||
// invalid, keep previous set
|
||||
'invalid log id' => [
|
||||
[
|
||||
'file_id' => 'jkl456'
|
||||
'file_id' => 'jkl456',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
],
|
||||
[
|
||||
'log_file_id' => 'jkl456',
|
||||
@@ -207,7 +262,8 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
'values' => [
|
||||
'log_file_id' => './#'
|
||||
]
|
||||
]
|
||||
],
|
||||
null
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -219,13 +275,18 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
* @dataProvider logIdOptionsProvider
|
||||
* @testdox log id set/get tests [$_dataName]
|
||||
*
|
||||
* @param array|null $options
|
||||
* @param array $options
|
||||
* @param array $expected
|
||||
* @param array $override
|
||||
* @param string|null $deprecation_message until we remove the old code
|
||||
* @return void
|
||||
*/
|
||||
public function testLogId(?array $options, array $expected, array $override): void
|
||||
{
|
||||
public function testLogId(
|
||||
array $options,
|
||||
array $expected,
|
||||
array $override,
|
||||
?string $deprecation_message
|
||||
): void {
|
||||
// we need to set with file_id option, globals LOG_FILE_ID, constant LOG_FILE_ID
|
||||
if (!empty($override['constant'])) {
|
||||
foreach ($override['constant'] as $var => $value) {
|
||||
@@ -237,11 +298,20 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
$GLOBALS[$var] = $value;
|
||||
}
|
||||
}
|
||||
if ($options === null) {
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
} else {
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
if (!empty($override['constant']) || !empty($override['globals'])) {
|
||||
// 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\Debug\LoggingLegacy($options);
|
||||
// reset error handler
|
||||
restore_error_handler();
|
||||
// check current
|
||||
$this->assertEquals(
|
||||
$log->getLogId(),
|
||||
@@ -316,7 +386,10 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
bool $expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testSetGetLogLevelAll',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
// set and check
|
||||
$this->assertEquals(
|
||||
$log->setLogLevelAll($type, $flag),
|
||||
@@ -438,7 +511,10 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
$expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testSetGetLogLevel',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
// set
|
||||
$this->assertEquals(
|
||||
$log->setLogLevel($type, $flag, $debug_on),
|
||||
@@ -517,7 +593,10 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
bool $expected_get
|
||||
): void {
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testSetGetLogPer',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
// set and check
|
||||
$this->assertEquals(
|
||||
$log->setLogPer($type, $set),
|
||||
@@ -546,7 +625,10 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
public function testSetGetLogPrintFileDate(bool $input, bool $expected_set, bool $expected_get): void
|
||||
{
|
||||
// neutral start with default
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testSetGetLogPrintFileDate',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
// set and check
|
||||
$this->assertEquals(
|
||||
$log->setGetLogPrintFileDate($input),
|
||||
@@ -612,7 +694,10 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
*/
|
||||
public function testPrAr(array $input, string $expected): void
|
||||
{
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testPrAr',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
$this->assertEquals(
|
||||
$log->prAr($input),
|
||||
$expected
|
||||
@@ -673,7 +758,10 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
*/
|
||||
public function testPrBl(bool $input, ?string $true, ?string $false, string $expected): void
|
||||
{
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testPrBl',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
$return = '';
|
||||
if ($true === null && $false === null) {
|
||||
$return = $log->prBl($input);
|
||||
@@ -845,7 +933,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
// remove any files named /tmp/error_log_TestDebug*.log
|
||||
array_map('unlink', glob($options['log_folder'] . 'error_msg_' . $options['file_id'] . '*.log'));
|
||||
// init logger
|
||||
$log = new \CoreLibs\Debug\Logging($options);
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy($options);
|
||||
// * debug (A/B)
|
||||
// NULL check for strip/prefix
|
||||
$this->assertEquals(
|
||||
@@ -959,9 +1047,16 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
public function testLogUniqueId(bool $option, bool $override): void
|
||||
{
|
||||
if ($option === true) {
|
||||
$log = new \CoreLibs\Debug\Logging(['per_run' => $option]);
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testLogUniqueId',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'per_run' => $option
|
||||
]);
|
||||
} else {
|
||||
$log = new \CoreLibs\Debug\Logging();
|
||||
$log = new \CoreLibs\Debug\LoggingLegacy([
|
||||
'file_id' => 'testLogUniqueId',
|
||||
'log_folder' => self::LOG_FOLDER
|
||||
]);
|
||||
$log->setLogUniqueId();
|
||||
}
|
||||
$per_run_id = $log->getLogUniqueId();
|
||||
735
4dev/tests/Debug/CoreLibsDebugSupportTest.php
Normal file
735
4dev/tests/Debug/CoreLibsDebugSupportTest.php
Normal file
@@ -0,0 +1,735 @@
|
||||
<?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;
|
||||
default:
|
||||
$this->assertTrue(true, 'Default fallback as true');
|
||||
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',
|
||||
'status' => 2,
|
||||
'content' => [],
|
||||
'chmod' => '000',
|
||||
// 0000
|
||||
'chmod' => '100000',
|
||||
],
|
||||
'empty file' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'empty.env',
|
||||
'status' => 1,
|
||||
'content' => [],
|
||||
'chmod' => null,
|
||||
// 0664
|
||||
'chmod' => '100664',
|
||||
],
|
||||
'override all' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
'file' => 'test.env',
|
||||
'status' => 0,
|
||||
'content' => $dot_env_content,
|
||||
'chmod' => null,
|
||||
// 0664
|
||||
'chmod' => '100664',
|
||||
],
|
||||
'override directory' => [
|
||||
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||
@@ -124,6 +127,16 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
array $expected_env,
|
||||
?string $chmod
|
||||
): void {
|
||||
if (
|
||||
!empty($chmod) &&
|
||||
$chmod == '100000' &&
|
||||
getmyuid() == 0
|
||||
) {
|
||||
$this->markTestSkipped(
|
||||
"Skip cannot read file test because run user is root"
|
||||
);
|
||||
return;
|
||||
}
|
||||
// if we have file + chmod set
|
||||
$old_chmod = null;
|
||||
if (
|
||||
@@ -134,6 +147,20 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
$old_chmod = fileperms($folder . DIRECTORY_SEPARATOR . $file);
|
||||
chmod($folder . DIRECTORY_SEPARATOR . $file, octdec($chmod));
|
||||
}
|
||||
$message = '\CoreLibs\Get\DotEnv is deprecated in favor for '
|
||||
. 'composer package gullevek\dotenv which is a copy of this';
|
||||
// convert E_USER_DEPRECATED to a exception
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// tests are never run -> deprecated
|
||||
if (is_file($folder . DIRECTORY_SEPARATOR . $file)) {
|
||||
chmod($folder . DIRECTORY_SEPARATOR . $file, 0664);
|
||||
}
|
||||
$this->expectExceptionMessage($message);
|
||||
if ($folder !== null && $file !== null) {
|
||||
$status = DotEnv::readEnvFile($folder, $file);
|
||||
} elseif ($folder !== null) {
|
||||
@@ -141,6 +168,7 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
} else {
|
||||
$status = DotEnv::readEnvFile();
|
||||
}
|
||||
restore_error_handler();
|
||||
$this->assertEquals(
|
||||
$status,
|
||||
$expected_status,
|
||||
@@ -153,8 +181,9 @@ final class CoreLibsGetDotEnvTest extends TestCase
|
||||
'Assert _ENV correct'
|
||||
);
|
||||
// if we have file and chmod unset
|
||||
if ($old_chmod !== null) {
|
||||
chmod($folder . DIRECTORY_SEPARATOR . $file, $old_chmod);
|
||||
print "Write mode: $old_chmod\n";
|
||||
if ($old_chmod !== null && $chmod == '100000') {
|
||||
chmod($folder . DIRECTORY_SEPARATOR . $file, 0664);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,17 +67,17 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
'original set' => [
|
||||
0 => null,
|
||||
1 => 'NOHOST',
|
||||
2 => 'NOPORT',
|
||||
2 => 0,
|
||||
],
|
||||
'override set no port' => [
|
||||
0 => 'foo.org',
|
||||
1 => 'foo.org',
|
||||
2 => '80'
|
||||
2 => 80
|
||||
],
|
||||
'override set with port' => [
|
||||
0 => 'foo.org:443',
|
||||
1 => 'foo.org',
|
||||
2 => '443'
|
||||
2 => 443
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -99,7 +99,7 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
1 => 'phpunit',
|
||||
2 => 'phpunit',
|
||||
// NOTE: this can change, so it is a regex check
|
||||
3 => "/^(\/?.*\/?)?www\/vendor\/bin\/phpunit$/",
|
||||
3 => "/^(\/?.*\/?)?(vendor\/bin|tools)\/phpunit$/",
|
||||
],
|
||||
'some path with extension' => [
|
||||
0 => '/some/path/to/file.txt',
|
||||
@@ -138,10 +138,10 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected_host
|
||||
* @param string $expected_port
|
||||
* @param int $expected_port
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHostNanme(?string $input, string $expected_host, string $expected_port): void
|
||||
public function testGetHostNanme(?string $input, string $expected_host, int $expected_port): void
|
||||
{
|
||||
// print "HOSTNAME: " . $_SERVER['HTTP_HOST'] . "<br>";
|
||||
// print "SERVER: " . print_r($_SERVER, true) . "\n";
|
||||
@@ -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__
|
||||
233
4dev/tests/Language/CoreLibsLanguageGetLocaleTest.php
Normal file
233
4dev/tests/Language/CoreLibsLanguageGetLocaleTest.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function setLocaleFromSessionProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: SESSION: DEFAULT_LOCALE
|
||||
// 5: SESSION: DEFAULT_CHARSET
|
||||
// 5: SESSION: DEFAULT_DOMAIN
|
||||
// 6: SESSION: LOCALE_PATH
|
||||
// 6: expected array
|
||||
// 7: deprecation message
|
||||
'all session vars set' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'ja_JP.UTF-8', 'UTF-8', 'admin', __DIR__ . '/locale_other/',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP.UTF-8',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'no session set, only parameters' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
null, null, null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// special parse session check for locales
|
||||
'all session vars set, short lang' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'ja', 'UTF-8', 'admin', __DIR__ . '/locale_other/',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// lang with modifier
|
||||
// param lang and domain (no override)
|
||||
'long locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'de_CH.UTF-8@euro', 'admin', 'UTF-8', __DIR__ . '/includes/locale/',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'de_CH.UTF-8@euro',
|
||||
'lang' => 'de_CH',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// missing session values check
|
||||
// special parse session check for locales
|
||||
'session missing encoding, set from parameters' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'ja', null, 'admin', __DIR__ . '/locale_other/',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// null return check for invalid entries
|
||||
'no session set, only parameters, all invalid' => [
|
||||
// lang, domain, encoding, path
|
||||
'###', '&&&&', '$$$$', 'foo_bar_path',
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
null, null, null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => null,
|
||||
'lang' => null,
|
||||
'domain' => null,
|
||||
'encoding' => null,
|
||||
'path' => null,
|
||||
],
|
||||
],
|
||||
// invalid session names, fall backup
|
||||
'all session vars are invalid, fallback' => [
|
||||
// lang, domain, encoding, path
|
||||
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
|
||||
// SESSION SETTINGS: locale, charset, domain, path
|
||||
'###', '&&&&', '$$$$', 'foo_bar_path',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLocale
|
||||
* @dataProvider setLocaleFromSessionProvider
|
||||
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
|
||||
*
|
||||
* @param string| $language
|
||||
* @param string| $domain
|
||||
* @param string| $encoding
|
||||
* @param string| $path
|
||||
* @param string|null $SESSION_DEFAULT_LOCALE
|
||||
* @param string|null $SESSION_DEFAULT_CHARSET
|
||||
* @param string|null $SESSION_DEFAULT_DOMAIN
|
||||
* @param string|null $SESSION_LOCALE_PATH
|
||||
* @param array<mixed> $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testsetLocaleFromSession(
|
||||
string $language,
|
||||
string $domain,
|
||||
string $encoding,
|
||||
string $path,
|
||||
?string $SESSION_DEFAULT_LOCALE,
|
||||
?string $SESSION_DEFAULT_CHARSET,
|
||||
?string $SESSION_DEFAULT_DOMAIN,
|
||||
?string $SESSION_LOCALE_PATH,
|
||||
array $expected,
|
||||
): void {
|
||||
$return_lang_settings = [];
|
||||
global $_SESSION;
|
||||
// set override
|
||||
if ($SESSION_DEFAULT_LOCALE !== null) {
|
||||
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
|
||||
}
|
||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
||||
}
|
||||
if ($SESSION_DEFAULT_DOMAIN !== null) {
|
||||
$_SESSION['DEFAULT_DOMAIN'] = $SESSION_DEFAULT_DOMAIN;
|
||||
}
|
||||
if ($SESSION_LOCALE_PATH !== null) {
|
||||
$_SESSION['LOCALE_PATH'] = $SESSION_LOCALE_PATH;
|
||||
}
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocaleFromSession(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding,
|
||||
$path
|
||||
);
|
||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
||||
foreach (
|
||||
[
|
||||
'locale', 'lang', 'domain', 'encoding', 'path'
|
||||
] as $key
|
||||
) {
|
||||
$value = $expected[$key];
|
||||
if (
|
||||
!empty($value) &&
|
||||
strpos($value, "/") === 0
|
||||
) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
$return_lang_settings[$key] ?? '',
|
||||
'assert regex failed for ' . $key
|
||||
);
|
||||
} else {
|
||||
// assert equal
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert equal failed for ' . $key
|
||||
);
|
||||
}
|
||||
}
|
||||
// unset all vars
|
||||
$_SESSION = [];
|
||||
unset($GLOBALS['OVERRIDE_LANG']);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -22,37 +22,16 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// default web page encoding setting
|
||||
if (!defined('DEFAULT_ENCODING')) {
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
}
|
||||
if (!defined('DEFAULT_LOCALE')) {
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
}
|
||||
// site
|
||||
if (!defined('SITE_ENCODING')) {
|
||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||
}
|
||||
if (!defined('SITE_LOCALE')) {
|
||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||
}
|
||||
// just set
|
||||
// for deprecation test only, will be removed
|
||||
if (!defined('BASE')) {
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
define('BASE', str_replace(DIRECTORY_SEPARATOR . 'configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('INCLUDES')) {
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LANG')) {
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LOCALE')) {
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CONTENT_PATH')) {
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,77 +84,163 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 1: encoding
|
||||
// 2: domain
|
||||
// 3: path
|
||||
// 4: locale expected
|
||||
// 5: locale set expected
|
||||
// 6: domain exepcted
|
||||
// 7: context (null for none)
|
||||
// 8: test string in
|
||||
// 9: test translated
|
||||
// 6: lang expected
|
||||
// 7: lang short expected
|
||||
// 8: encoding expected
|
||||
// 9: domain exepcted
|
||||
// 10: context (null for none)
|
||||
// 11: test string in
|
||||
// 12: test translated
|
||||
// 13: deprecation message (until removed)
|
||||
// new style load
|
||||
'gettext load en' => [
|
||||
'en_US.UTF-8',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
//
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// 4, 5, 6, 7, 8, 9
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'en_US',
|
||||
'en',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
// 10
|
||||
null,
|
||||
// 11, 12
|
||||
'Original',
|
||||
'Translated frontend en_US',
|
||||
// 13
|
||||
null,
|
||||
],
|
||||
'gettext load en' => [
|
||||
'en_US.UTF-8',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'en_US',
|
||||
'en',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
//
|
||||
'context',
|
||||
//
|
||||
'Original',
|
||||
'Original context frontend en_US',
|
||||
//
|
||||
null,
|
||||
],
|
||||
'gettext load ja' => [
|
||||
'ja_JP.UTF-8',
|
||||
'UTF-8',
|
||||
'admin',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
//
|
||||
'ja_JP.UTF-8',
|
||||
'ja_JP',
|
||||
'ja_JP',
|
||||
'ja',
|
||||
'UTF-8',
|
||||
'admin',
|
||||
//
|
||||
null,
|
||||
//
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
//
|
||||
null,
|
||||
],
|
||||
// mixed path and domain
|
||||
'mixed path and domain' => [
|
||||
// load short locale with different encoding
|
||||
'gettext load short ja no encoding' => [
|
||||
'ja',
|
||||
'SJIS',
|
||||
'admin',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
//
|
||||
'ja',
|
||||
'ja',
|
||||
'ja',
|
||||
'ja',
|
||||
'SJIS',
|
||||
'admin',
|
||||
//
|
||||
null,
|
||||
//
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
//
|
||||
null,
|
||||
],
|
||||
// mixed path and domain [DEPRECATED]
|
||||
'mixed path and domain [DEPRECATED]' => [
|
||||
'en_US.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'UTF-8',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
'frontend',
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'en_US',
|
||||
'en',
|
||||
'UTF-8',
|
||||
'frontend',
|
||||
//
|
||||
'context',
|
||||
//
|
||||
'Original',
|
||||
'Original context frontend en_US',
|
||||
//
|
||||
'L10n constructor parameter switch is no longer supported. domain is 2nd, path is 3rd parameter'
|
||||
],
|
||||
// unset path
|
||||
'unset path with locale and domain [DEPRECATED]' => [
|
||||
'ja_JP.UTF-8',
|
||||
'UTF-8',
|
||||
'admin',
|
||||
null,
|
||||
//
|
||||
'ja_JP.UTF-8',
|
||||
'ja_JP',
|
||||
'ja_JP',
|
||||
'ja',
|
||||
'UTF-8',
|
||||
'admin',
|
||||
//
|
||||
null,
|
||||
//
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
//
|
||||
'Empty path parameter is no longer allowed if locale and domain are set',
|
||||
],
|
||||
// null set
|
||||
'empty load new ' => [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
//
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'', // unset on empty call
|
||||
'',
|
||||
//
|
||||
null,
|
||||
//
|
||||
'Original',
|
||||
'Original',
|
||||
//
|
||||
null,
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -188,37 +253,62 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName]
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @param string|null $encoding
|
||||
* @param string|null $domain
|
||||
* @param string|null $path
|
||||
* @param string $locale_expected
|
||||
* @param string $locale_set_expected
|
||||
* @param string $lang_expected
|
||||
* @param string $lang_short_expected
|
||||
* @param string $encoding_expected
|
||||
* @param string $domain_expected
|
||||
* @param ?string $context
|
||||
* @param string|null $context
|
||||
* @param string $original
|
||||
* @param string $translated
|
||||
* @param string|null $deprecation_message
|
||||
* @return void
|
||||
*/
|
||||
public function testL10nObject(
|
||||
?string $locale,
|
||||
?string $encoding,
|
||||
?string $domain,
|
||||
?string $path,
|
||||
string $locale_expected,
|
||||
string $locale_set_expected,
|
||||
string $lang_expected,
|
||||
string $lang_short_expected,
|
||||
string $encoding_expected,
|
||||
string $domain_expected,
|
||||
?string $context,
|
||||
string $original,
|
||||
string $translated
|
||||
string $translated,
|
||||
?string $deprecation_message
|
||||
): void {
|
||||
if ($deprecation_message !== null) {
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// catch this with the message
|
||||
$this->expectExceptionMessage($deprecation_message);
|
||||
}
|
||||
if ($locale === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n();
|
||||
} elseif ($domain === null) {
|
||||
// deprecated, locale + domain must be set, handled like empty calls
|
||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||
} elseif ($path === null) {
|
||||
// deprecated, path must be set, will thow DEPRECATION error, handled like empty
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||
} else {
|
||||
} elseif ($encoding === null) {
|
||||
// if encoding not found will be UTF-8
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||
} else {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path, $encoding);
|
||||
}
|
||||
// print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
|
||||
restore_error_handler();
|
||||
// print "MO: " . $l10n->getMoFile() . "\n";
|
||||
$this->assertEquals(
|
||||
$locale_expected,
|
||||
@@ -248,6 +338,20 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'Translated string assert failed in context: ' . $context
|
||||
);
|
||||
}
|
||||
// test get locel as array
|
||||
$locale = $l10n->getLocaleAsArray();
|
||||
$this->assertEquals(
|
||||
[
|
||||
'locale' => $locale_expected,
|
||||
'lang' => $lang_expected,
|
||||
'lang_short' => $lang_short_expected,
|
||||
'domain' => $domain_expected,
|
||||
'encoding' => $encoding_expected,
|
||||
'path' => $path
|
||||
],
|
||||
$locale,
|
||||
'getLocaleAsArray mismatch'
|
||||
);
|
||||
}
|
||||
|
||||
// l10nReloadMOfile and getTranslator
|
||||
@@ -283,7 +387,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// set 0-2
|
||||
'en_US.UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// status 3
|
||||
false,
|
||||
// to translate 4
|
||||
@@ -296,7 +400,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// set new 8-10
|
||||
'ja_JP.UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// status new 11
|
||||
false,
|
||||
// check new setter 12-14
|
||||
@@ -322,7 +426,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// set new 8-10
|
||||
'en_US.UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// status new 11
|
||||
false,
|
||||
// check new setter 12-14
|
||||
@@ -387,12 +491,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
string $domain_expected_b,
|
||||
string $translated_b
|
||||
): void {
|
||||
if ($locale === null) {
|
||||
if ($locale === null || $domain === null || $path === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n();
|
||||
} elseif ($domain === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||
} elseif ($path === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||
} else {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||
}
|
||||
@@ -494,16 +594,16 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: path
|
||||
// 2: domain
|
||||
// 1: domain
|
||||
// 2: path
|
||||
// 3: context (null for none)
|
||||
// 4: single string
|
||||
// 5: plural string
|
||||
// 6: array for each n value expected string
|
||||
'plural text en' => [
|
||||
'en_US',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'admin',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// context
|
||||
null,
|
||||
// text single/multi in
|
||||
@@ -518,8 +618,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
],
|
||||
'plural text context en' => [
|
||||
'en_US',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'admin',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
// context
|
||||
'context',
|
||||
// text single/multi in
|
||||
@@ -544,8 +644,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @testdox plural string test for locale $locale and domain $domain with $context [$_dataName]
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $path
|
||||
* @param string $domain
|
||||
* @param string $path
|
||||
* @param ?string $context
|
||||
* @param string $original_single
|
||||
* @param string $original_plural
|
||||
@@ -555,8 +655,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
public function testNgettext(
|
||||
// config 0-3
|
||||
string $locale,
|
||||
string $path,
|
||||
string $domain,
|
||||
string $path,
|
||||
// context string
|
||||
?string $context,
|
||||
// input strings
|
||||
@@ -565,7 +665,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// expected
|
||||
array $expected_strings
|
||||
): void {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain, false);
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||
|
||||
foreach ($expected_strings as $n => $expected) {
|
||||
if (empty($context)) {
|
||||
@@ -981,7 +1081,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'standard en' => [
|
||||
'en_US.UTF-8',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
'UTF-8',
|
||||
'Original',
|
||||
'Translated frontend en_US',
|
||||
@@ -989,7 +1089,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'standard ja' => [
|
||||
'ja_JP.UTF-8',
|
||||
'admin',
|
||||
__DIR__ . 'includes/locale/',
|
||||
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
|
||||
'UTF-8',
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
@@ -1030,6 +1130,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
_textdomain($domain);
|
||||
_bindtextdomain($domain, $path);
|
||||
_bind_textdomain_codeset($domain, $encoding);
|
||||
|
||||
$this->assertEquals(
|
||||
$translated,
|
||||
__($original),
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user