Compare commits

...

45 Commits

Author SHA1 Message Date
Clemens Schwaighofer
1379cf1519 Add print bool in logging class 2022-05-26 14:31:48 +09:00
Clemens Schwaighofer
2d15b78d21 Composer update 2022-05-26 09:52:37 +09:00
Clemens Schwaighofer
92ebdb4b9e Update session class and write session clas tester, update DB\IO Tester
DB\IO Tester now has correct testing for pgVersion string compare. Uses
mocked pgVersion return for this

Session class update with full magic set/get or method set/get for
_SESSION var. Also added full testing for this
2022-05-26 09:27:57 +09:00
Clemens Schwaighofer
a523a4e831 ACL\Login class update for phpstan check 2022-05-24 16:50:37 +09:00
Clemens Schwaighofer
db8e17ae7c Convert static Session class to normal session class
All static Session:: calls (except for checking valid session name) are
converted to object type. This Object is passed on to Login, Admin
Backend and any other class that needs basic session checking
2022-05-24 15:00:04 +09:00
Clemens Schwaighofer
5b581c2ed6 Fix checkCLI call on false return from php_sapi_name() 2022-05-24 13:12:17 +09:00
Clemens Schwaighofer
1e734581d7 Session class update, cli check add, tests updates, edit table update
Update edit_access_data table and set unique check for edit_access_id +
name so we do not have two identical keys for one edit access set

Update config host and add more test domains for various access tests

Update Session and move cli check to Get\System class. Some other minor
session info updates

New method \Get\System::checkCLI() returns true if the sapi name has
cli inside, else false
2022-05-24 11:36:03 +09:00
Clemens Schwaighofer
aecdda3557 Update per level log file writing and with level check
remove all non alphanumeric characters from the level string (debug call
first parameter) so the file name is not invalid:wq
2022-05-19 13:24:28 +09:00
Clemens Schwaighofer
2119b757b1 Session class docu not needed text delete 2022-05-19 10:22:39 +09:00
Clemens Schwaighofer
27087a0e0e Update session class with checks, etc
Add a write close session call to end a session for AJAX calls
Add error strings to session start method
Add check call for session names that they are valid
2022-05-13 14:14:08 +09:00
Clemens Schwaighofer
2b689b666a Update all class test files in admin with proper named header 2022-05-13 13:34:54 +09:00
Clemens Schwaighofer
63aeebdee0 phpstan ingore for Error Handlung function 2022-05-12 15:19:09 +09:00
Clemens Schwaighofer
51e700cd10 Fixes from phan/phpstan tests 2022-04-28 14:17:30 +09:00
Clemens Schwaighofer
71a431d5aa Class fix for ACL\Login, DB\Extended\ArrayIO, edit_base.php
- edit base used useless regex for getting filename and dir from folder
  list. Changed to pathinfo() call to fix this
- edit_base.php and DB\Extended\ArrayIO fixes
On page order in edit we got errors because pk_name in ArrayIO class was
not init as empty string as it should be (is defined as string only)
- ACL\Login updates
Move all public functions to the public block.
Add public functions for base check Page/Base level to min level name
get acl array as is for now (will be extended with other calls for more
detail query)
Also clean ups in PHPdoc layout, long lines, etc
2022-04-28 10:03:47 +09:00
Clemens Schwaighofer
6970e6221b Fix ACL\Login base ACL for page with DEFAULT ACL LEVEL USER 2022-04-27 18:12:22 +09:00
Clemens Schwaighofer
831f3be1a8 Update config.php to use absolute paths for loading basic settings 2022-04-26 13:55:51 +09:00
Clemens Schwaighofer
f2aba8c466 add error for unsupported php in phpunit test script 2022-04-25 18:36:08 +09:00
Clemens Schwaighofer
f085ccaa38 update phpunit call script for testing 2022-04-25 18:26:30 +09:00
Clemens Schwaighofer
6c3c1a908d PHPunit fixes for PHP 7.4 2022-04-25 17:01:28 +09:00
Clemens Schwaighofer
388b90913a translation creation script 2022-04-25 13:58:43 +09:00
Clemens Schwaighofer
07aea9d7b2 Add local set to L10n class and use it in Smarty Extended
The actual locale name of the folder where the mo file is located can be
queried with getLocaleSet()

This is used in smarty extended to set the smarty translation template
for javascript strings
2022-04-25 10:15:11 +09:00
Clemens Schwaighofer
edcdbee523 phpunit tests update for acl login, db io, fix smarty extended class 2022-04-25 09:52:13 +09:00
Clemens Schwaighofer
43b51895f0 Bug fixes in ACL\Login and DB\IO\Extended 2022-04-22 15:32:06 +09:00
Clemens Schwaighofer
d0e294ecf5 Fix Language encoding move documentation 2022-04-18 17:57:04 +09:00
Clemens Schwaighofer
3c35341e8b Bug fix in smarty block.t plugin
Equal instead of assign for plural text translate calls.

Update smarty tests with more detail checks of translations
2022-04-18 10:52:37 +09:00
Clemens Schwaighofer
daf1f9263c Change all function L10n calls to one underscore, test updates
That change is done to be compatible with the phpmyadmin translator
class so this can be a drop in replacement or other way around.

Update smarty block.t to only check for _* functions and not any pre
loaded language class
2022-04-18 10:33:45 +09:00
Clemens Schwaighofer
805c695d68 Language\L10n method name fixes, update Smarty block.t.php
__pn for context plural has now correct name __np

Update smarty plugin block.t.php to use __* named gettext methods for
all calls, for __n/__np/__/__p calls we fallback to check internal set
class on l10n object variable.

This will be removed in future calls
2022-04-15 16:53:02 +09:00
Clemens Schwaighofer
ffdd45e32a Fix phpUnit tests with constant settings and missing checks
BASE constant setting: moved all to same base folder in 4dev/tests
check all other CONSTANT settings if they are already set and skip (used
only in Language default set)

Add missing phpunit check for array merge recursive
2022-04-15 15:19:30 +09:00
Clemens Schwaighofer
316ca106fd Composer autoload update 2022-04-15 13:57:48 +09:00
Clemens Schwaighofer
fd9b201346 Remove old GetSettings for language legacy flow 2022-04-15 13:57:26 +09:00
Clemens Schwaighofer
667dc4de8e Clean up of old _LANG config variables 2022-04-15 13:53:37 +09:00
Clemens Schwaighofer
fed67e990d Update Language\L10n class and drop all legacy code
new Langauge\GetLocale::setLocale() for getting new type lang info from
session, etc
L10n class call chnage of parameters:
NEW: locale, domain, path
OLD: locale, path, domain, legacy(bool)

Temporary auto detect for possible path/domain switch if domain value
has slash inside

Rename all local files to names matching locale folder
en_US -> en

Delete lang folders with symlinks as they are no longer used

Update all header files and class Backend\Admin, ACL\Login,
Output\Form\Generate, Template\SmartyExtend with new language order:
call ::setLocale() afer login class

Update missing test translation strings in all po files

Update phpUnit tests to match all new changes
2022-04-15 13:29:41 +09:00
Clemens Schwaighofer
c181a83b48 Rename po files to new standard <locale>-<domain>.po 2022-04-14 14:47:58 +09:00
Clemens Schwaighofer
c830a32962 Minor fix in gettext loop for max string lenght 2022-04-14 13:43:26 +09:00
Clemens Schwaighofer
82bc99b181 Language\ namespace update
Update the Core Language classes to have all method parameter type
declaration.
GetTextReader has gettext as alias to translate.
GetTextReader public methods to get cache enable status and short
circuit (no translation loaded) status

Main language:
Add new methods for plural and plural in context (__n, __p, __pn)
Deprecate gettext, ngettext, _e

Add new translation loader in gettext standard
<locale>/LC_MESSAGES/<domain> style
Including locales checker, auto detect on enviroment variables, return
self as class (for functions type) return translator class after
loading, etc

New LoadFunctions to run all like functions. Names like php but with two
underscores prefixed. eg gettext -> __gettext
2022-04-13 16:26:15 +09:00
Clemens Schwaighofer
556cabca38 Add DOCTYPE to all admin test files, update phpunit DB IO test
DB IO Test: Change max DB version to 99 from 20 in Version check test

Add DOCTYPE html to all admin class test files
2022-04-13 10:25:04 +09:00
Clemens Schwaighofer
6f4c5e36e6 Move Encoding class away from the Language namespace
Language\Encoding::__mbMimeEncode -> Convert\MimeEncode::__mbMimeEncode
Langauge\Encoding::checkConvertEncoding -> Check\Encoding::checkConvertEncoding
Langauge\Encoding::setErrorChar -> Check\Encoding::setErrorChar
Langauge\Encoding::getErrorChar -> Encoding::getErrorChar
Langauge\Encoding::convertEncoding -> Convert\Encoding::convertEncoding

Also fixed encoding check that not only a code point but a string can
also be used as a parameter.

Update phpunit tests and split them out for each class

Normal test page is still combined for all classes but updated to
correctly use each class
2022-04-13 09:25:42 +09:00
Clemens Schwaighofer
a3c49e408a Update to get default language settings with correct POSIX locale form
Also add phpunit test
2022-04-12 20:20:10 +09:00
Clemens Schwaighofer
cc77d7e031 Update Language\Encoding and phpunit tets
Fix missing replace char settings for conversion check call.
The php replace char method was never called. Also add standard type
settings next to char settings.
Return (get) call can either class set or current set in php

Fix mime encode with trailing space problem if length is on split
length. Mime encode uses \r\n for all line breaks now, can be controlled
via parameter
2022-04-12 20:19:48 +09:00
Clemens Schwaighofer
d553c1364f Add LOCALE config settings
next to the current lang/encoding add locale that is a combination of
both.
Also add a locale folder constant

the default LANG variables (DEFAULT_LANG, SITE_LANG) change from en_utf8
to en_US
new DEFAULT_LOCALE with en_US.UTF-8
2022-04-12 20:14:41 +09:00
Clemens Schwaighofer
3f374a2cd7 Update default db edit* language settings
en = en_US
jp = ja_JP
2022-04-12 20:13:23 +09:00
Clemens Schwaighofer
9e99275db5 phpunit tests includes folder for translation tests 2022-04-12 20:12:38 +09:00
Clemens Schwaighofer
330e2baf39 Add new locale folder structure and symlinks for old lang layout 2022-04-12 14:25:19 +09:00
Clemens Schwaighofer
5a81626e8c Clean up ACL/Login
Add locale global variable in the format
<lang>_<country>.<encoding>@<suffix>
Default set to en_US.UTF-8

Also remove nested if callse and do early abort/method return for
flatten code:
loginUser
logoutUser
setAcl
printLogin
passwordChange
2022-04-11 09:17:19 +09:00
Clemens Schwaighofer
41cff5e3c6 Remove old comment from DB\IO class about encoding settings 2022-04-08 19:59:37 +09:00
139 changed files with 6541 additions and 1919 deletions

17
4dev/bin/create_mo.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
base_folder='/var/www/html/developers/clemens/core_data/php_libraries/trunk/www/';
# locale gettext po to mo translator master
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
file=$(basename $file .po);
echo "Translate language ${file}";
locale=$(echo "${file}" | cut -d "-" -f 1);
domain=$(echo "${file}" | cut -d "-" -f 2);
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
fi;
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}../4dev/locale/${locale}-${domain}.po;
done;
# __END__

View File

@@ -1,4 +1,42 @@
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
# -c phpunit.xml
# --testdox
${base}www/vendor/bin/phpunit -c ${base}phpunit.xml ${base}4dev/tests/
# call with "t" to give verbose testdox output
# SUPPORTED: https://www.php.net/supported-versions.php
# call with 7.3, 7.4, 8.0, 8.1 to force a certain php version
opt_testdox="";
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
opt_testdox="--testdox";
fi;
php_bin="";
if [ ! -z "${1}" ]; then
case "${1}" in
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
"7.4") php_bin="/usr/bin/php7.4 "; ;;
"8.0") php_bin="/usr/bin/php8.0 "; ;;
"8.1") php_bin="/usr/bin/php8.1 "; ;;
*) echo "Not support PHP: ${1}"; exit; ;;
esac;
fi;
if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
case "${2}" in
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
"7.4") php_bin="/usr/bin/php7.4 "; ;;
"8.0") php_bin="/usr/bin/php8.0 "; ;;
"8.1") php_bin="/usr/bin/php8.1 "; ;;
*) 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);
else
echo "Default PHP used: "$(php --version);
fi;
# __END__

View File

@@ -68,9 +68,10 @@ INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', 'B0C4B3
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
-- edit language
-- iso_name = encoding
DELETE FROM edit_language;
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('en', 'English', 'UTF-8', 1, 1, 1);
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('ja', 'Japanese', 'UTF-8', 2, 1, 0);
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
INSERT INTO edit_language (long_name, short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
-- edit group
DELETE FROM edit_group;

View File

@@ -14,3 +14,7 @@ CREATE TABLE edit_access_data (
name VARCHAR,
value VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- create a unique index for each attached data block for each edit access can
-- only have ONE value;
CREATE UNIQUE INDEX edit_access_data_edit_access_id_name_ukey ON edit_access_data (edit_access_id, name);

View File

@@ -12,7 +12,7 @@ CREATE TABLE edit_language (
enabled SMALLINT NOT NULL DEFAULT 0,
lang_default SMALLINT NOT NULL DEFAULT 0,
long_name VARCHAR,
short_name VARCHAR,
iso_name VARCHAR,
short_name VARCHAR, -- en_US, en or en_US@latin without encoding
iso_name VARCHAR, -- should actually be encoding
order_number INT
) INHERITS (edit_generic) WITHOUT OIDS;

55
4dev/locale/Readme.md Normal file
View File

@@ -0,0 +1,55 @@
# Translation files
## Source file name convetion
Locale Name . Domain . Encoding .po
## Name parte explenations
### Locale Name Examples
If underscore in name the long version is checked first, then the short version:
en_US@latin -> en_US -> en
* en
* en_US
* en_US.UTF-8
* en_US@latin
### Domain
For current case auto set CONTENT_PATH is used
* admin
* frontend
### Encoding
if not set UTF-8 is assumed. Any other utf8 encoding is changed to UTF-8
* UTF-8
* SJIS
* EUC
## File name example source
`ja-admin.po`
First part is LOCALE, second part is domain. Separator is `-`
## Folder layout
`includes/locale/ja/LC_MESSAGES/frontend.mo`
ALTERNATE LOCALE NAMES:
* ja
* ja_JP
* ja.UTF-8
* ja_JP.UTF-8
ja_JP.UTF-8: Locale Name
frontend: dmain (CONTENT_PATH)
## command
`msgfmt -o www/includes/locale/ja/LC_MESSAGES/frontend.mo 4dev/lang/ja.admin.po`

View File

@@ -2,22 +2,22 @@
# AUTHOR: Clemens Schwaighofer
# CREATED: 2005/08/09
# SHORT DESCRIPTION:
# Backned English Messages file for gettext
# to craete: msgfmt -o ja.mo messages_en.po
# HISTORY:
# Backend English Messages file for gettext
# ********************************************************************/
msgid ""
msgstr ""
"Project-Id-Version: Project Version\n"
"Project-Id-Version: en.UTF-8 LC_MESSAGES admin\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: \n"
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
msgid "Year"
msgstr "Year"
@@ -26,7 +26,25 @@ msgid "Month"
msgstr "Month"
msgid "INPUT TEST"
msgstr "OUTPUT TEST EN"
msgstr "OUTPUT TEST ADMIN EN"
# testing multi
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi Admin en 0"
msgstr[1] "Multi Admin en 1"
msgstr[2] "Multi Admin en 2"
msgctxt "month name"
msgid "May"
msgstr "May Admin en"
msgctxt "month name"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi Admin month en 0"
msgstr[1] "Multi Admin month en 1"
msgstr[2] "Multi Admin month en 2"
msgid "I should be translated"
msgstr "I should be translated: I WAS TRANSLATED"

View File

@@ -0,0 +1,29 @@
# ********************************************************************
# AUTHOR: Clemens Schwaighofer
# CREATED: 2005/08/09
# SHORT DESCRIPTION:
# Frontend English Messages file for gettext
# ********************************************************************/
msgid ""
msgstr ""
"Project-Id-Version: en.UTF-8 LC_MESSAGES frontend\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
msgid "INPUT TEST"
msgstr "OUTPUT TEST FRONTEND EN"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi frontend en 0"
msgstr[1] "Multi frontend en 1"
msgstr[2] "Multi frontend en 2"

View File

@@ -2,22 +2,22 @@
# AUTHOR: Clemens Schwaighofer
# CREATED: 2018/03/28
# SHORT DESCRIPTION:
# Backend Japanese Messages file for gettext
# to craete: msgfmt -o ja.mo messages_ja.po
# HISTORY:
# Backend Japanese Messages file for gettext>
# ********************************************************************/
msgid ""
msgstr ""
"Project-Id-Version: Project Version\n"
"Project-Id-Version: ja.UTF-8 LC_MESSAGES admin\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: \n"
"Last-Translator: clemens.schwaighofer@egplusww.com\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
msgid "Yes"
msgstr "はい"
@@ -63,7 +63,25 @@ msgid "Sun"
msgstr "日"
msgid "INPUT TEST"
msgstr "OUTPUT TEST JA"
msgstr "OUTPUT TEST ADMIN JA"
# testing multi
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi Admin ja 0"
msgstr[1] "Multi Admin ja 1"
msgstr[2] "Multi Admin ja 2"
msgctxt "month name"
msgid "May"
msgstr "May Admin ja"
msgctxt "month name"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi Admin month ja 0"
msgstr[1] "Multi Admin month ja 1"
msgstr[2] "Multi Admin month ja 2"
# login string
msgid "Hello %s"

View File

@@ -0,0 +1,29 @@
# ********************************************************************
# AUTHOR: Clemens Schwaighofer
# CREATED: 2005/08/09
# SHORT DESCRIPTION:
# Frontend Japanese Messages file for gettext
# ********************************************************************/
msgid ""
msgstr ""
"Project-Id-Version: ja.UTF-8 LC_MESSAGES frontend\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: clemens.schwaighofer@egplusww.com\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
msgid "INPUT TEST"
msgstr "OUTPUT TEST FRONTEND JA"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi frontend ja 0"
msgstr[1] "Multi frontend ja 1"
msgstr[2] "Multi frontend ja 2"

View File

@@ -13,18 +13,76 @@ use PHPUnit\Framework\TestCase;
*/
final class CoreLibsACLLoginTest extends TestCase
{
private static $db;
private static $log;
private static $session;
/**
* Undocumented function
* start DB conneciton, setup DB, etc
*
* @return void
*/
protected function setUp(): void
public static function setUpBeforeClass(): void
{
if (!extension_loaded('pgsql')) {
$this->markTestSkipped(
self::markTestSkipped(
'The PgSQL extension is not available.'
);
}
// init session
self::$session = new \CoreLibs\Create\Session('ACLLoginTest');
// logger is always needed
// define basic connection set valid and one invalid
self::$log = new \CoreLibs\Debug\Logging([
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
'file_id' => 'CoreLibs-ACL-Login-Test',
'debug_all' => false,
'echo_all' => false,
'print_all' => false,
]);
// if we do have pgsql, we need to create a test DB or check that one
// exists and clean the table to zero state
self::$db = new \CoreLibs\DB\IO(
[
'db_name' => 'corelibs_acl_login_test',
'db_user' => 'corelibs_acl_login_test',
'db_pass' => 'corelibs_acl_login_test',
'db_host' => 'localhost',
'db_port' => 5432,
'db_schema' => 'public',
'db_type' => 'pgsql',
'db_encoding' => '',
'db_ssl' => 'allow', // allow, disable, require, prefer
'db_debug' => true,
],
self::$log
);
if (!self::$db->dbGetConnectionStatus()) {
self::markTestSkipped(
'Cannot connect to valid Test DB for ACL\Login test.'
);
}
/*
// check if they already exist, drop them
if ($db->dbShowTableMetaData('table_with_primary_key') !== false) {
$db->dbExec("DROP TABLE table_with_primary_key");
$db->dbExec("DROP TABLE table_without_primary_key");
$db->dbExec("DROP TABLE test_meta");
}
*/
}
/**
* close db
*
* @return void
*/
public static function tearDownAfterClass(): void
{
if (self::$db->dbGetConnectionStatus()) {
self::$db->dbClose();
}
}
/**
@@ -40,6 +98,8 @@ final class CoreLibsACLLoginTest extends TestCase
$this->markTestIncomplete(
'ACL\Login Tests have not yet been implemented'
);
$login = new \CoreLibs\ACL\Login(self::$db, self::$log, self::$session);
}
}

View File

@@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
/**
* Test class for Check\Encoding
* @coversDefaultClass \CoreLibs\Check\Encoding
* @testdox \CoreLibs\Check\Encoding method tests
*/
final class CoreLibsCheckEncodingTest extends TestCase
{
/**
* Undocumented function
*
* @return array
*/
public function checkConvertEncodingProvider(): array
{
return [
// 0: string to test
// 1: source encoding
// 2: target encoding
// 3: substitue character
// 4: false for ok, array with error list
'valid test UTF-8 to SJIS (default)' => [
'日本語',
'UTF-8',
'SJIS',
null,
false
],
'invalid test UTF-8 to SJIS (dots as code point)' => [
'❶',
'UTF-8',
'SJIS',
0x2234,
['❶']
],
'invalid test UTF-8 to SJIS (dots as string)' => [
'❶',
'UTF-8',
'SJIS',
'∴',
['❶']
],
'invalid test UTF-8 to SJIS (none)' => [
'❶',
'UTF-8',
'SJIS',
'none',
['❶']
],
'invalid test UTF-8 to SJIS (long)' => [
'❶',
'UTF-8',
'SJIS',
'long',
['❶']
],
'invalid test UTF-8 to SJIS (entity)' => [
'❶',
'UTF-8',
'SJIS',
'entity',
['❶']
],
];
}
/**
* Undocumented function
*
* @covers ::checkConvertEncoding
* @dataProvider checkConvertEncodingProvider
* @testdox check encoding convert from $from_encoding to $to_encoding [$_dataName]
*
* @param string $input
* @param string $from_encoding
* @param string $to_encoding
* @param string|int|null $error_char
* @param array|bool $expected
* @return void
*/
public function testCheckConvertEncoding(
string $input,
string $from_encoding,
string $to_encoding,
$error_char,
$expected
): void {
if ($error_char !== null) {
\CoreLibs\Check\Encoding::setErrorChar($error_char);
if (!in_array($error_char, ['none', 'long', 'entity'])) {
$this->assertEquals(
\IntlChar::chr($error_char),
\CoreLibs\Check\Encoding::getErrorChar()
);
} else {
$this->assertEquals(
$error_char,
\CoreLibs\Check\Encoding::getErrorChar()
);
}
}
$return = \CoreLibs\Check\Encoding::checkConvertEncoding($input, $from_encoding, $to_encoding);
$this->assertEquals(
$expected,
$return
);
}
}
// __END__

View File

@@ -7,6 +7,7 @@ declare(strict_types=1);
namespace tests;
use Exception;
use PHPUnit\Framework\TestCase;
/**
@@ -274,7 +275,6 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
}
/**
* TODO: create provider for n array merge
* provides array listing for the merge test
*
* @return array
@@ -282,6 +282,61 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
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]
],
];
}
@@ -626,21 +681,43 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
* Undocumented function
*
* @covers ::arrayMergeRecursive
* @#dataProvider arrayMergeRecursiveProvider
* @testdox arrayMergeRecursive ... will be $expected [$_dataName]
* @dataProvider arrayMergeRecursiveProvider
* @testdox arrayMergeRecursive ... [$_dataName]
*
* @param array $input nested array set as each parameter
* @param bool $flag
* @param bool|array $expected
* @return void
* array $input, bool $flag, $expected
*
*/
public function testArrayMergeRecursive(): void
{
$this->assertTrue(true, 'Implement proper test run');
$this->markTestIncomplete(
'testArrayMergeRecursive has not been implemented yet.'
$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);
}
/**

View File

@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
/**
* Test class for Convert\Encoding
* @coversDefaultClass \CoreLibs\Convert\Encoding
* @testdox \CoreLibs\Convert\Encoding method tests
*/
final class CoreLibsConvertEncodingTest extends TestCase
{
/**
* Undocumented function
*
* @return array
*/
public function convertEncodingProvider(): array
{
return [
// 0: original string
// 1: target encoding
// 2: optional source encoding
// 3: auto check (not used)
// 4: expected string
// 5: expected string encoding
'simple from UTF-8 to SJIS' => [
'input string',
'SJIS',
null,
null,
'input string',
'SJIS'
],
'kanji from UTF-8 to SJIS' => [
'日本語',
'SJIS',
null,
null,
'日本語',
'SJIS'
],
'kanji from UTF-8 to SJIS with source' => [
'日本語',
'SJIS',
'UTF-8',
null,
'日本語',
'SJIS'
],
];
}
/**
* Undocumented function
*
* @covers ::convertEncoding
* @dataProvider convertEncodingProvider
* @testdox convert encoding $target_encoding, source: $source_encoding, auto: $auto_check [$_dataName]
*
* @param string $input
* @param string $target_encoding
* @param string $source_encoding
* @param bool $auto_check
* @param string $expected
* @param string $expected_encoding
* @return void
*/
public function testConvertEncoding(
string $input,
string $target_encoding,
?string $source_encoding,
?bool $auto_check,
string $expected,
string $expected_encoding
): void {
if ($source_encoding === null and $auto_check === null) {
$string = \CoreLibs\Convert\Encoding::convertEncoding($input, $target_encoding);
} elseif ($auto_check === null) {
$string = \CoreLibs\Convert\Encoding::convertEncoding($input, $target_encoding, $source_encoding);
} else {
$string = \CoreLibs\Convert\Encoding::convertEncoding(
$input,
$target_encoding,
$source_encoding,
$auto_check
);
}
// because we can't store encoding in here anyway
$target = mb_convert_encoding($expected, $expected_encoding, 'UTF-8');
// print "IN: $input, $target_encoding\n";
$this->assertEquals(
$target,
$string
);
}
}
// __END__

View File

@@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase;
*/
final class CoreLibsConvertJsonTest extends TestCase
{
/**
* test list for json convert tests
*

View File

@@ -0,0 +1,101 @@
<?php
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
/**
* Test class for Convert\MimeEncode
* @coversDefaultClass \CoreLibs\Convert\MimeEncode
* @testdox \CoreLibs\Convert\MimeEncode method tests
*/
final class CoreLibsConvertMimeEncodeTest extends TestCase
{
/**
* Undocumented function
*
* @return array
*/
public function mbMimeEncodeProvider(): array
{
return [
// 0: input string
// 1: encoding
// 2: expected
'standard UTF-8' => [
'Test string',
'UTF-8',
'Test string'
],
'long text 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',
'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'
],
'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==?=&'
],
'35 chars and space at the end UTF-8' => [
'12345678901234567890123456789012345 '
. 'is there a space?',
'UTF-8',
'12345678901234567890123456789012345 '
. 'is there a =?UTF-8?B?c3BhY2U/?='
],
'36 chars and space at the end UTF-8' => [
'123456789012345678901234567890123456 '
. 'is there a space?',
'UTF-8',
'123456789012345678901234567890123456 '
. 'is there a =?UTF-8?B?c3BhY2U/?='
],
'36 kanji and space UTF-8' => [
'カタカナカタカナかなカタカナカタカナかなカタカナカタカナかなカタカナカタ '
. '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/?="
]
];
}
/**
* mb mime header encoding test
*
* @covers ::__mbMimeEncode
* @dataProvider mbMimeEncodeProvider
* @testdox mb encoding target $encoding [$_dataName]
*
* @return void
*/
public function testUuMbMimeEncode(string $input, string $encoding, string $expected): void
{
// encode string first
$encoded = \CoreLibs\Convert\MimeEncode::__mbMimeEncode($input, $encoding);
// print "MIME: -" . $encoded . "-\n";
$this->assertEquals(
$expected,
$encoded
);
$decoded = mb_decode_mimeheader($encoded);
// print "INPUT : " . $input . "\n";
// print "DECODED: " . $decoded . "\n";
// back compare decoded
$this->assertEquals(
$input,
$decoded
);
}
}
// __END__

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Test class for Create\Session
@@ -20,84 +21,451 @@ 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,
// PHP_SESSION_NONE/ACTIVE for ok
// setSessionName: true/false,
// checkActiveSession: true/false, [1st call, 2nd call]
// getSessionId: string or false
// 3: exepcted name (session)
// 4: expected error string
return [
'session parameter' => [
'sessionNameParameter',
'p',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'sessionNameParameter',
'/^\w+$/'
''
],
'session globals' => [
'sessionNameGlobals',
'g',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'sessionNameGlobals',
'/^\w+$/'
''
],
'session constant' => [
'sessionNameConstant',
'c',
'sessionNameConstant',
'/^\w+$/'
'session name default' => [
'',
'd',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'',
''
],
// error checks
// 1: we are in cli
'on cli error' => [
'',
'd',
[
'checkCliStatus' => true,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'',
'[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'
],
];
}
/**
* Undocumented function
* Test session start
*
* @covers ::startSession
* @dataProvider sessionProvider
* @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
* @return void
*/
protected function setUp(): void
{
if (session_id()) {
session_destroy();
public function testStartSession(
string $input,
string $type,
array $mock_data,
string $expected,
string $expected_error,
): 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',
'getSessionName'
]
);
// set return values based requested input values
// OK: true
// error: false
$session_mock->method('checkCliStatus')->willReturn($mock_data['checkCliStatus']);
// OK: PHP_SESSION_ACTIVE, PHP_SESSION_NONE
// error: PHP_SESSION_DISABLED
$session_mock->method('getSessionStatus')->willReturn($mock_data['getSessionStatus']);
// false: try start
// true: skip start
// note that on second call if false -> error
$session_mock->method('checkActiveSession')
->willReturnOnConsecutiveCalls(
$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']);
// 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;
}
// asert checks
if (!empty($session_id)) {
$this->assertMatchesRegularExpression(
$ression_id_regex,
(string)$session_id,
'session id regex from retrun'
);
$this->assertMatchesRegularExpression(
$ression_id_regex,
(string)$session_mock->getSessionId()
);
$this->assertEquals(
$expected,
$session_mock->getSessionName()
);
} else {
// false checks
$this->assertEquals(
$expected_error,
$session_mock->getErrorStr(),
'error assert'
);
}
}
/**
* Undocumented function
* provider for session name check
*
* @dataProvider sessionProvider
* @testdox startSession $input name for $type will be $expected_n with $expected_i [$_dataName]
* @return array
*/
public function sessionNameProvider(): array
{
// 0: string for session
// 1: expected return as bool
return [
'valid name' => [
'abc',
true
],
'valid name longer' => [
'something-abc-123',
true
],
'invalid name' => [
'abc#abc',
false
],
'only numbers' => [
'123',
false
],
'longer than 128 chars' => [
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
. 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
. 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz',
false
],
'too short' => [
'',
false
],
];
}
/**
* test valid session name
*
* @param string $input
* @param string $type
* @param string|bool $expected_n
* @param string|bool $expected_i
* @covers ::checkValidSessionName
* @dataProvider sessionNameProvider
* @testdox checkValidSessionName $input seessionn name is $expected [$_dataName]
*
* @param string $input
* @param bool $expected
* @return void
*/
public function testStartSession(string $input, string $type, $expected_n, $expected_i): void
public function testCheckValidSessionName(string $input, bool $expected): void
{
/* $session_id = '';
switch ($type) {
case 'p':
$session_id = \CoreLibs\Create\Session::startSession($input);
break;
case 'g':
$GLOBALS['SET_SESSION_NAME'] = $input;
$session_id = \CoreLibs\Create\Session::startSession();
break;
case 'c':
define('SET_SESSION_NAME', $input);
$session_id = \CoreLibs\Create\Session::startSession();
break;
}
$this->assertMatchesRegularExpression(
$expected_i,
(string)$session_id
);
$this->assertMatchesRegularExpression(
$expected_i,
(string)\CoreLibs\Create\Session::getSessionId()
);
$this->assertEquals(
$expected_n,
\CoreLibs\Create\Session::getSessionName()
$expected,
\CoreLibs\Create\Session::checkValidSessionName($input)
);
if ($type == 'g') {
unset($GLOBALS['SET_SESSION_NAME']);
} */
$this->markTestSkipped('No implementation for Create\Session. Cannot run session_start in CLI');
}
/**
* provider for set/get tests
*
* @return array
*/
public function sessionDataProvider(): array
{
return [
'test' => [
'foo',
'bar',
'bar',
],
'int key test' => [
123,
'bar',
'bar',
],
// more complex value tests
'array values' => [
'array',
[1, 2, 3],
[1, 2, 3],
]
];
}
/**
* method call test
*
* @covers ::setS
* @covers ::getS
* @covers ::issetS
* @covers ::unsetS
* @dataProvider sessionDataProvider
* @testdox setS/getS/issetS/unsetS $name with $input is $expected [$_dataName]
*
* @param string|int $name
* @param mixed $input
* @param mixed $expected
* @return void
*/
public function testMethodSetGet($name, $input, $expected): void
{
$session = new \CoreLibs\Create\Session();
$session->setS($name, $input);
$this->assertEquals(
$expected,
$session->getS($name),
'method set assert'
);
// isset true
$this->assertTrue(
$session->issetS($name),
'method isset assert ok'
);
$session->unsetS($name);
$this->assertEquals(
'',
$session->getS($name),
'method unset assert'
);
// iset false
$this->assertFalse(
$session->issetS($name),
'method isset assert false'
);
}
/**
* magic call test
*
* @covers ::__set
* @covers ::__get
* @covers ::__isset
* @covers ::__unset
* @dataProvider sessionDataProvider
* @testdox __set/__get/__iseet/__unset $name with $input is $expected [$_dataName]
*
* @param string|int $name
* @param mixed $input
* @param mixed $expected
* @return void
*/
public function testMagicSetGet($name, $input, $expected): void
{
$session = new \CoreLibs\Create\Session();
$session->$name = $input;
$this->assertEquals(
$expected,
$session->$name,
'magic set assert'
);
// isset true
$this->assertTrue(
isset($session->$name),
'magic isset assert ok'
);
unset($session->$name);
$this->assertEquals(
'',
$session->$name,
'magic unset assert'
);
// isset true
$this->assertFalse(
isset($session->$name),
'magic isset assert false'
);
}
/**
* unset all test
*
* @covers ::unsetAllS
* @testdox unsetAllS test
*
* @return void
*/
public function testUnsetAll(): void
{
$test_values = [
'foo' => 'abc',
'bar' => '123'
];
$session = new \CoreLibs\Create\Session();
foreach ($test_values as $name => $value) {
$session->setS($name, $value);
// confirm set
$this->assertEquals(
$value,
$session->getS($name),
'set assert: ' . $name
);
}
// unset all
$session->unsetAllS();
// check unset
foreach (array_keys($test_values) as $name) {
$this->assertEquals(
'',
$session->getS($name),
'unsert assert: ' . $name
);
}
}
}

View File

@@ -36,6 +36,7 @@ declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Test class for DB\IO + DB\SQL\PgSQL
@@ -145,7 +146,7 @@ final class CoreLibsDBIOTest extends TestCase
);
if (!$db->dbGetConnectionStatus()) {
self::markTestSkipped(
'Cannot connect to valid Test DB.'
'Cannot connect to valid Test DB for DB\IO test.'
);
}
// check if they already exist, drop them
@@ -347,6 +348,7 @@ final class CoreLibsDBIOTest extends TestCase
/**
* Returns test list for dbCompareVersion check
* NOTE: unless we fully mock the =version check needs to be updated
*
* @return array
*/
@@ -357,16 +359,16 @@ final class CoreLibsDBIOTest extends TestCase
return [
'compare = ok' => [ '=13.6.0', true ],
'compare = bad' => [ '=9.2.0', false ],
'compare < ok' => [ '<20.0.0', true ],
'compare < ok' => [ '<99.0.0', true ],
'compare < bad' => [ '<9.2.0', false ],
'compare <= ok a' => [ '<=20.0.0', true ],
'compare <= ok a' => [ '<=99.0.0', true ],
'compare <= ok b' => [ '<=13.6.0', true ],
'compare <= false' => [ '<=9.2.0', false ],
'compare > ok' => [ '>9.2.0', true ],
'compare > bad' => [ '>20.2.0', false ],
'compare > bad' => [ '>99.2.0', false ],
'compare >= ok a' => [ '>=13.6.0', true ],
'compare >= ok b' => [ '>=9.2.0', true ],
'compare >= bad' => [ '>=20.0.0', false ],
'compare >= bad' => [ '>=99.0.0', false ],
];
}
@@ -386,28 +388,24 @@ final class CoreLibsDBIOTest extends TestCase
public function testDbVerson(string $input, bool $expected): void
{
// connect to valid DB
$db = new \CoreLibs\DB\IO(
self::$db_config['valid'],
self::$log
);
// $db = new \CoreLibs\DB\IO(
// self::$db_config['valid'],
// self::$log
// );
/** @var \CoreLibs\DB\IO&MockObject $db_io_mock */
$db_io_mock = $this->createPartialMock(\CoreLibs\DB\IO::class, ['dbVersion']);
$db_io_mock->method('dbVersion')->willReturn('13.6.0');
// print "DB VERSION: " . $db->dbVersion() . "\n";
// TODO: Mock \CoreLibs\DB\SQL\PgSQL somehow or Mock \CoreLibsDB\IO::dbVersion
// Create a stub for the SomeClass class.
// $stub = $this->createMock(\CoreLibs\DB\IO::class);
// $stub->method('dbVersion')
// ->willReturn('13.1.0');
// print "DB: " . $stub->dbVersion() . "\n";
// print "DB Mock: " . $stub->dbVersion() . "\n";
// print "TEST: " . ($stub->dbCompareVersion('=13.1.0') ? 'YES' : 'NO') . "\n";
// print "TEST: " . ($stub->dbCompareVersion('=13.6.0') ? 'YES' : 'NO') . "\n";
// $mock = $this->getMockBuilder(CoreLibs\DB\IO::class)
// ->addMethods(['dbVersion'])
// ->getMock();
$this->assertEquals(
$expected,
$db->dbCompareVersion($input)
// $db->dbCompareVersion($input)
$db_io_mock->dbCompareVersion($input)
);
// print "IT HAS TO BE 13.1.0: " . $stub->dbVersion() . "\n";
@@ -565,7 +563,7 @@ final class CoreLibsDBIOTest extends TestCase
public function testDbSetDebug(
string $connection,
?bool $set,
bool $expected,
bool $expected
): void {
$db = new \CoreLibs\DB\IO(
self::$db_config[$connection],
@@ -598,7 +596,7 @@ final class CoreLibsDBIOTest extends TestCase
public function testDbToggleDebug(
string $connection,
?bool $toggle,
bool $expected,
bool $expected
): void {
$db = new \CoreLibs\DB\IO(
self::$db_config[$connection],
@@ -1733,7 +1731,7 @@ final class CoreLibsDBIOTest extends TestCase
$expected,
string $warning,
string $error,
string $insert_data,
string $insert_data
): void {
// self::$log->setLogLevelAll('debug', true);
// self::$log->setLogLevelAll('print', true);
@@ -1870,7 +1868,7 @@ final class CoreLibsDBIOTest extends TestCase
$expected,
string $warning,
string $error,
string $insert_data,
string $insert_data
): void {
// self::$log->setLogLevelAll('debug', true);
// self::$log->setLogLevelAll('print', true);
@@ -2033,7 +2031,7 @@ final class CoreLibsDBIOTest extends TestCase
array $cursor_ext_checks,
string $warning,
string $error,
string $insert_data,
string $insert_data
): void {
// self::$log->setLogLevelAll('debug', true);
// self::$log->setLogLevelAll('print', true);
@@ -2355,7 +2353,7 @@ final class CoreLibsDBIOTest extends TestCase
string $error_execute,
string $expected_data_query,
array $expected_data,
string $insert_data,
string $insert_data
): void {
// self::$log->setLogLevelAll('debug', true);
// self::$log->setLogLevelAll('print', true);
@@ -2708,7 +2706,8 @@ final class CoreLibsDBIOTest extends TestCase
// comarep all, except timestamp that is a regex
foreach ($expected_history as $key => $value) {
// check if starts with / because this is regex (timestamp)
if (strpos($value, "/") === 0) {
// if (substr($expected_2, 0, 1) == '/) {
if (strpos($value, '/') === 0) {
// this is regex
$this->assertMatchesRegularExpression(
$value,
@@ -3008,7 +3007,7 @@ final class CoreLibsDBIOTest extends TestCase
string $insert,
?string $pk_name,
string $table,
string $primary_key,
string $primary_key
): void {
// self::$log->setLogLevelAll('debug', true);
// self::$log->setLogLevelAll('print', true);

View File

@@ -6,6 +6,8 @@ namespace tests;
use PHPUnit\Framework\TestCase;
// TODO: setLogPer test log file written matches pattern
/**
* Test class for Debug\Logging
* @coversDefaultClass \CoreLibs\Debug\Logging
@@ -54,14 +56,16 @@ final class CoreLibsDebugLoggingTest extends TestCase
'no options set, constant set' => [
null,
[
'log_folder' => '/tmp/',
'log_folder' => str_replace('/configs', '', __DIR__)
. DIRECTORY_SEPARATOR . 'log/',
'debug_all' => false,
'print_all' => false,
],
[
'constant' => [
'BASE' => '/tmp',
'LOG' => '/'
'BASE' => str_replace('/configs', '', __DIR__)
. DIRECTORY_SEPARATOR,
'LOG' => 'log/'
]
]
],
@@ -728,7 +732,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
bool $expected_debug,
string $expected_file,
string $expected_string_start,
string $expected_string_contains,
string $expected_string_contains
): void {
// must run with below matrix
// level | debug | print | echo | debug() | printErrorMsg() | file

View File

@@ -90,11 +90,16 @@ final class CoreLibsGetSystemTest extends TestCase
public function getPageNameProvider(): array
{
return [
// 0: input
// 1: expected default/WITH_EXTENSION
// 2: expected NO_EXTENSION
// 3: expected FULL_PATH, if first and last character are / use regex
'original set' => [
0 => null, // input
0 => null,
1 => 'phpunit',
2 => 'phpunit',
3 => 'www/vendor/bin/phpunit', // NOTE: this can change
// NOTE: this can change, so it is a regex check
3 => "/^(\/?.*\/?)?www\/vendor\/bin\/phpunit$/",
],
'some path with extension' => [
0 => '/some/path/to/file.txt',
@@ -147,11 +152,13 @@ final class CoreLibsGetSystemTest extends TestCase
list ($host, $port) = \CoreLibs\Get\System::getHostName();
$this->assertEquals(
$expected_host,
$host
$host,
'failed expected host assert'
);
$this->assertEquals(
$expected_port,
$port
$port,
'faile expected port assert'
);
}
@@ -176,20 +183,38 @@ final class CoreLibsGetSystemTest extends TestCase
// default 0,
$this->assertEquals(
$expected_0,
\CoreLibs\Get\System::getPageName()
\CoreLibs\Get\System::getPageName(),
'failed default assert'
);
$this->assertEquals(
$expected_0,
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::WITH_EXTENSION)
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::WITH_EXTENSION),
'failed WITH_EXTESION assert'
);
$this->assertEquals(
$expected_1,
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::NO_EXTENSION)
);
$this->assertEquals(
$expected_2,
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::FULL_PATH)
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::NO_EXTENSION),
'failed NO_EXTENSION assert'
);
// FULL PATH check can be equals or regex
$page_name_full_path = \CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::FULL_PATH);
if (
substr($expected_2, 0, 1) == '/' &&
substr($expected_2, -1, 1) == '/'
) {
// this is regex
$this->assertMatchesRegularExpression(
$expected_2,
$page_name_full_path,
'failed FULL_PATH assert regex'
);
} else {
$this->assertEquals(
$expected_2,
$page_name_full_path,
'failed FULL_PATH assert equals'
);
}
}
}

View File

@@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
/**
* Test class for Language\Encoding
* @coversDefaultClass \CoreLibs\Language\Encoding
* @testdox \CoreLibs\Language\Encoding method tests
*/
final class CoreLibsLanguageEncodingTest extends TestCase
{
/**
* Undocumented function
*
* @testdox Language\Encoding Class tests
*
* @return void
*/
public function testLanguageEncoding()
{
$this->assertTrue(true, 'Language Encoding Tests not implemented');
$this->markTestIncomplete(
'Language\Encoding Tests have not yet been implemented'
);
}
}
// __END__

View File

@@ -0,0 +1,310 @@
<?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__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# if we don't have one base file we are in the wrong folder
if [ ! -f "locale/en_US/LC_MESSAGES/admin.mo" ]; then
echo "Locale file is missing, wrong base folder?"
echo "Should be: 4dev/tests/includes/"
exit;
fi;
for file in $(ls -1 locale/*.po); do
echo $file;
file=$(basename $file .po);
locale=$(echo "${file}" | cut -d "-" -f 1);
domain=$(echo "${file}" | cut -d "-" -f 2);
msgfmt -o locale/${locale}/LC_MESSAGES/${domain}.mo locale/${locale}-${domain}.po;
done;

View File

@@ -0,0 +1,34 @@
msgid ""
msgstr ""
"Project-Id-Version: en_US.UTF-8 LC_MESSAGES admin\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
msgid "Original"
msgstr "Translated admin en_US"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi admin en_US 0"
msgstr[1] "Multi admin en_US 1"
msgstr[2] "Multi admin en_US 2"
msgctxt "context"
msgid "Original"
msgstr "Original context admin en_US"
msgctxt "context"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi context admin en_US 0"
msgstr[1] "Multi context admin en_US 1"
msgstr[2] "Multi context admin en_US 2"

View File

@@ -0,0 +1,34 @@
msgid ""
msgstr ""
"Project-Id-Version: en_US.UTF-8 LC_MESSAGES frontend\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
msgid "Original"
msgstr "Translated frontend en_US"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi frontend en_US 0"
msgstr[1] "Multi frontend en_US 1"
msgstr[2] "Multi frontend en_US 2"
msgctxt "context"
msgid "Original"
msgstr "Original context frontend en_US"
msgctxt "context"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi context frontend en_US 0"
msgstr[1] "Multi context frontend en_US 1"
msgstr[2] "Multi context frontend en_US 2"

Binary file not shown.

View File

@@ -0,0 +1,35 @@
msgid ""
msgstr ""
"Project-Id-Version: ja_JP.UTF-8 LC_MESSAGES admin\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;\n"
# 0, 1, 2 plural
msgid "Original"
msgstr "Translated admin ja_JP"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi admin ja_JP 0"
msgstr[1] "Multi admin ja_JP 1"
msgstr[2] "Multi admin ja_JP 2"
msgctxt "context"
msgid "Original"
msgstr "Original context admin ja_JP"
msgctxt "context"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi context admin ja_JP 0"
msgstr[1] "Multi context admin ja_JP 1"
msgstr[2] "Multi context admin ja_JP 2"

View File

@@ -0,0 +1,35 @@
msgid ""
msgstr ""
"Project-Id-Version: ja_JP.UTF-8 LC_MESSAGES frontend\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;\n"
# 0, 1, 2 plural
msgid "Original"
msgstr "Translated frontend ja_JP"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi frontend ja_JP 0"
msgstr[1] "Multi frontend ja_JP 1"
msgstr[2] "Multi frontend ja_JP 2"
msgctxt "context"
msgid "Original"
msgstr "Original context frontend ja_JP"
msgctxt "context"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi context frontend ja_JP 0"
msgstr[1] "Multi context frontend ja_JP 1"
msgstr[2] "Multi context frontend ja_JP 2"

Binary file not shown.

View File

@@ -1,58 +0,0 @@
<?php
declare(strict_types=1);
namespace test;
use PHPUnit\Framework\TestCase;
final class TemplateMethodsTest extends TestCase
{
public static function setUpBeforeClass(): void
{
fwrite(STDOUT, __METHOD__ . "\n");
}
protected function setUp(): void
{
fwrite(STDOUT, __METHOD__ . "\n");
}
protected function assertPreConditions(): void
{
fwrite(STDOUT, __METHOD__ . "\n");
}
public function testOne(): void
{
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue(true);
}
public function testTwo(): void
{
fwrite(STDOUT, __METHOD__ . "\n");
$this->assertTrue(false);
}
protected function assertPostConditions(): void
{
fwrite(STDOUT, __METHOD__ . "\n");
}
protected function tearDown(): void
{
fwrite(STDOUT, __METHOD__ . "\n");
}
public static function tearDownAfterClass(): void
{
fwrite(STDOUT, __METHOD__ . "\n");
}
protected function onNotSuccessfulTest(\Throwable $t): void
{
fwrite(STDOUT, __METHOD__ . "\n");
throw $t;
}
}

View File

@@ -44,9 +44,24 @@ $db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login & page access check
$login = new CoreLibs\ACL\Login($db, $log);
```
* update language class
```php
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
```
* smarty needs language
```php
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
```
* admin backend also needs logger
```php
$cms = new CoreLibs\Admin\Backend($db, $log);
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
```
* update and `$cms` or similar calls so db is in `$cms->db->...` and log are in `$cms->log->...`
* update all `config.*.php` files where needed
@@ -60,6 +75,12 @@ require BASE . LIB . 'autoloader.php';
```
**UPDATE:**
```php
// po langs [DEPRECAED: use LOCALE]
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
// po locale file
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
```
```php
// SSL host name
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
```
@@ -85,6 +106,13 @@ define('CONTENT_WIDTH', '100%');
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
```
```php
/************* LANGUAGE / ENCODING *******/
// default lang + encoding
define('DEFAULT_LOCALE', 'en_US.UTF-8');
// default web page encoding setting
define('DEFAULT_ENCODING', 'UTF-8');
```
```php
// BAIL ON MISSING DB CONFIG:
// we have either no db selction for this host but have db config entries
// or we have a db selection but no db config as array or empty
@@ -104,6 +132,10 @@ if (
}
```
```php
// remove SITE_LANG
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
```
```php
/************* GENERAL PAGE TITLE ********/
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
@@ -118,6 +150,15 @@ In the config then
```php
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
```
* config.host.php update
must add site_locale (site_lang + site_encoding)
remove site_lang
```php
// lang + encoding
'site_locale' => 'en_US.UTF-8',
// site language
'site_encoding' => 'UTF-8',
```
* copy `layout/admin/javascript/edit.jq.js`
* check other javacsript files if needed (`edit.jq.js`)

View File

@@ -1,7 +1,72 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$result of function pg_result_error expects resource, object\\|resource\\|true given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_connection_busy expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 3
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_connection_status expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_get_result expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_meta_data expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_send_query expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_socket expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_version expects PgSql\\\\Connection\\|null, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_affected_rows expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_fetch_all expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_fetch_array expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_field_name expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_num_fields expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_num_rows expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_result_error expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php

View File

@@ -24,7 +24,9 @@ parameters:
# do not check old qq file uploader tests
- www/admin/qq_file_upload_*.php
# ignore all test files
- www/admin/class_test*php
- www/admin/class_test*.php
# extra in sub folder
- www/admin/subfolder/class_test*.php
- www/admin/error_test.php
# admin synlink files
- www/admin/edit_*.php
@@ -47,9 +49,12 @@ parameters:
- www/vendor
# ignore errores with
ignoreErrors:
- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*
- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#"
path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
- # this is for 8.1 or newer
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|null)?), object\\|resource given\\.$#"
path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
# this is ignored for now
# - '#Expression in empty\(\) is always falsy.#'
# -

View File

@@ -23,14 +23,12 @@ define('USE_DATABASE', true);
require 'config.php';
// override ECHO ALL FALSE
$ECHO_ALL = true;
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-admin';
$SET_SESSION_NAME = EDIT_SESSION_NAME;
ob_end_flush();
$session = new CoreLibs\Create\Session($SET_SESSION_NAME);
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
@@ -43,14 +41,23 @@ $log = new CoreLibs\Debug\Logging([
]);
// db config with logger
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$backend = new CoreLibs\Admin\Backend($db, $log);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$backend = new CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
print "<html><head><title>TEST CLASS: ADMIN BACKEND</title><head>";
$PAGE_NAME = 'TEST CLASS: ADMIN BACKEND';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// set acl, from eg login acl
print "SETACL[]: " . $backend->setACL([]) . "<br>";
print "SETACL[]: " . $backend->setACL(['EMPTY' => 'EMPTY']) . "<br>";
print "ADBEDITLOG: " . $backend->adbEditLog('CLASSTEST-ADMIN', 'Some info stirng') . "<br>";
print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "<br>";
print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "<br>";

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-array';
ob_end_flush();
@@ -45,9 +41,12 @@ $log = new CoreLibs\Debug\Logging([
// $_array = new CoreLibs\Combined\ArrayHandler();
// $array_class = 'CoreLibs\Combination\ArrayHandler';
print "<html><head><title>TEST CLASS: ARRAY HANDLER</title><head>";
$PAGE_NAME = 'TEST CLASS: ARRAY HANDLER';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// recursive array search
$test_array = [

View File

@@ -20,10 +20,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-autoloader';
ob_end_flush();
@@ -32,9 +28,12 @@ ob_end_flush();
use CoreLibs\Convert\Byte;
print "<html><head><title>TEST CLASS: AUTOLOADER</title><head>";
$PAGE_NAME = 'TEST CLASS: AUTOLOADER';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$bytes = 10242424;
$_bytes = Byte::humanReadableByteFormat($bytes);

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-byte';
ob_end_flush();
@@ -43,9 +39,12 @@ $log = new CoreLibs\Debug\Logging([
]);
$byte_class = 'CoreLibs\Convert\Byte';
print "<html><head><title>TEST CLASS: BYTE CONVERT</title><head>";
$PAGE_NAME = 'TEST CLASS: BYTE CONVERT';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// class
$byte = 254779258;

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-colors';
ob_end_flush();
@@ -44,9 +40,12 @@ $log = new CoreLibs\Debug\Logging([
]);
$color_class = 'CoreLibs\Convert\Colors';
print "<html><head><title>TEST CLASS: COLORS</title><head>";
$PAGE_NAME = 'TEST CLASS: COLORS';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// define a list of from to color sets for conversion test

View File

@@ -0,0 +1,59 @@
<?php // phpcs:ignore warning
/**
* @phan-file-suppress PhanTypeSuspiciousStringExpression
*/
declare(strict_types=1);
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
ob_start();
// basic class test file
define('USE_DATABASE', false);
// sample config
require '../configs/config.php';
// define log file id
$LOG_FILE_ID = 'classTest-config-direct';
ob_end_flush();
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$PAGE_NAME = 'TEST CLASS: CONFIG DIRECT';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "DIR: " . DIR . "<br>";
print "BASE: " . BASE . "<br>";
print "ROOT: " . ROOT . "<br>";
print "BASE NAME: " . BASE_NAME . "<br>";
echo "Config path prefix: " . $CONFIG_PATH_PREFIX . "<br>";
print "DB Name: " . DB_CONFIG_NAME . "<br>";
print "DB Config: " . \CoreLibs\Debug\Support::printAr(DB_CONFIG) . "<br>";
// error message
print $log->printErrorMsg();
print "</body></html>";
// __END__

View File

@@ -0,0 +1,59 @@
<?php // phpcs:ignore warning
/**
* @phan-file-suppress PhanTypeSuspiciousStringExpression
*/
declare(strict_types=1);
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
ob_start();
// basic class test file
define('USE_DATABASE', false);
// sample config
require 'config.php';
// define log file id
$LOG_FILE_ID = 'classTest-config-link';
ob_end_flush();
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$PAGE_NAME = 'TEST CLASS: CONFIG LINK';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "DIR: " . DIR . "<br>";
print "BASE: " . BASE . "<br>";
print "ROOT: " . ROOT . "<br>";
print "BASE NAME: " . BASE_NAME . "<br>";
echo "Config path prefix: " . $CONFIG_PATH_PREFIX . "<br>";
print "DB Name: " . DB_CONFIG_NAME . "<br>";
print "DB Config: " . \CoreLibs\Debug\Support::printAr(DB_CONFIG) . "<br>";
// error message
print $log->printErrorMsg();
print "</body></html>";
// __END__

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-datetime';
ob_end_flush();
@@ -44,9 +40,12 @@ $log = new CoreLibs\Debug\Logging([
]);
$datetime_class = 'CoreLibs\Combined\DateTime';
print "<html><head><title>TEST CLASS: DATE/TIME</title><head>";
$PAGE_NAME = 'TEST CLASS: DATE/TIME';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// class
$timestamp = 1622788315.123456;

View File

@@ -39,9 +39,12 @@ $log = new CoreLibs\Debug\Logging([
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$db->log->debug('START', '=============================>');
print "<html><head><title>TEST CLASS: DB</title><head>";
$PAGE_NAME = 'TEST CLASS: DB';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "LOGFILE NAME: " . $db->log->getSetting('log_file_name') . "<br>";
print "LOGFILE ID: " . $db->log->getSetting('log_file_id') . "<br>";

View File

@@ -44,9 +44,12 @@ $debug = new CoreLibs\Debug\Logging([
$debug_support_class = 'CoreLibs\Debug\Support';
$debug_logging_class = 'CoreLibs\Debug\Logging';
print "<html><head><title>TEST CLASS: DEBUG</title><head>";
$PAGE_NAME = 'TEST CLASS: DEBUG';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
function test()
{
@@ -67,6 +70,9 @@ print "S::DEBUSTRING(s): " . DebugSupport::debugString('SET') . "<br>";
print "S::DEBUSTRING(''): " . DebugSupport::debugString('') . "<br>";
print "S::DEBUSTRING(,s): " . DebugSupport::debugString(null, '{-}') . "<br>";
// get test
print "LOG FOLDER: " . $debug->getSetting('log_folder') . "<br>";
// debug
print "C->DEBUG: " . $debug->debug('CLASS-TEST-DEBUG', 'Class Test Debug') . "<br>";
print "C->DEBUG(html): " . $debug->debug('CLASS-TEST-DEBUG', 'HTML TAG<br><b>BOLD</b>') . "<br>";
@@ -169,6 +175,16 @@ print "GETCALLERCLASS(NON CLASS): " . \CoreLibs\Debug\Support::getCallerClass()
print "S::FSETFILENAME: " . FileWriter::fsetFilename('class_test_debug_file.log') . "<br>";
print "S::FDEBUG: " . FileWriter::fdebug('CLASS TEST DEBUG FILE: ' . date('Y-m-d H:i:s')) . "<br>";
// test per level
$debug->setLogPer('level', true);
$debug->debug('TEST PER LEVEL', 'Per level test');
$debug->debug('()', 'Per level test: invalid chars');
$debug->setLogPer('level', false);
$ar = ['A', 1, ['B' => 'D']];
$debug->debug('ARRAY', 'Array: ' . $debug->prAr($ar));
$debug->debug('BOOL', 'True: ' . $debug->prBl(true) . ', False: ' . $debug->prBl(false));
// error message
// future DEPRECATED
// $debug->debug('BASIC CLASS', 'Debug test');

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-email';
ob_end_flush();
@@ -43,9 +39,12 @@ $log = new CoreLibs\Debug\Logging([
'print_all' => $PRINT_ALL ?? false,
]);
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
$PAGE_NAME = 'TEST CLASS: HTML/ELEMENTS';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// regex get
print "S::GETEMAILREGEX(0): " . Email::getEmailRegex(0) . "<br>";

View File

@@ -21,15 +21,13 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-encoding';
ob_end_flush();
use CoreLibs\Language\Encoding;
use CoreLibs\Convert\Encoding as ConEnc;
use CoreLibs\Check\Encoding as ChkEnc;
use CoreLibs\Convert\MimeEncode;
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
@@ -41,12 +39,17 @@ $log = new CoreLibs\Debug\Logging([
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$_encoding = new CoreLibs\Language\Encoding();
$encoding_class = 'CoreLibs\Language\Encoding';
// class type
$_chk_enc = new CoreLibs\Check\Encoding();
$_con_enc = new CoreLibs\Convert\Encoding();
$chk_enc = 'CoreLibs\Check\Encoding';
print "<html><head><title>TEST CLASS: ENCODING</title><head>";
$PAGE_NAME = 'TEST CLASS: ENCODING (CHECK/CONVERT/MIME)';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// print "Valid encoding: ".$log->printAr(mb_list_encodings())."<br>";
@@ -58,41 +61,47 @@ $mime_encodes = [
['日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい', 'ISO-2022-JP-MS'],
];
foreach ($mime_encodes as $mime_encode) {
print "__MBMIMEENCODE: $mime_encode[0]: " . Encoding::__mbMimeEncode($mime_encode[0], $mime_encode[1]) . "<br>";
print "__MBMIMEENCODE: $mime_encode[0]: " . MimeEncode::__mbMimeEncode($mime_encode[0], $mime_encode[1]) . "<br>";
}
echo "<br>";
$enc_strings = [
'Normal Text',
'日本語',
// bad
'❶',
// unworkable
''
];
// class
$_encoding->setErrorChar('∴');
$_chk_enc->setErrorChar(0x2234);
$_chk_enc->setErrorChar('∴');
print "ERROR CHAR: " . $_chk_enc->getErrorChar() . "<br>";
foreach ($enc_strings as $_string) {
$string = $_encoding->checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
print "CONV ENCODING: $_string: " . $_encoding->convertEncoding($_string, 'ISO-2022-JP') . "<br>";
print "CONV ENCODING (s): $_string: " . $_encoding->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
$string = $_chk_enc->checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "ENC CHECK: $_string: " . ($string === false ? '<b>-OK-</b>' : print_r($string, true)) . "<br>";
print "CONV ENCODING: $_string: " . $_con_enc->convertEncoding($_string, 'ISO-2022-JP') . "<br>";
print "CONV ENCODING (s): $_string: " . $_con_enc->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
print "CONV ENCODING (s,a-false): $_string: "
. $_encoding->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
. $_con_enc->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
}
print "ERROR CHAR: " . $_encoding->getErrorChar() . "<br>";
echo "<br>";
// static
$encoding_class::setErrorChar('∴');
// ChkEnc::setErrorChar('∴');
ChkEnc::setErrorChar(0x2234);
print "S::ERROR CHAR: " . ChkEnc::getErrorChar() . "<br>";
foreach ($enc_strings as $_string) {
$string = $encoding_class::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "S::ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
print "S::CONV ENCODING: $_string: " . $encoding_class::convertEncoding($_string, 'ISO-2022-JP') . "<br>";
$string = ChkEnc::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "S::ENC CHECK: $_string: " . ($string === false ? '<b>-OK-</b>' : print_r($string, true)) . "<br>";
print "S::CONV ENCODING: $_string: " . ConEnc::convertEncoding($_string, 'ISO-2022-JP') . "<br>";
print "S::CONV ENCODING (s): $_string: "
. $encoding_class::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
. ConEnc::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
print "S::CONV ENCODING (s,a-false): $_string: "
. $encoding_class::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
. ConEnc::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
}
print "S::ERROR CHAR: " . $encoding_class::getErrorChar() . "<br>";
// static use
$_string = $enc_strings[1];
$string = Encoding::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
$string = $chk_enc::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "S::ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
// error message

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-datetime';
ob_end_flush();
@@ -42,9 +38,12 @@ $log = new CoreLibs\Debug\Logging([
'print_all' => $PRINT_ALL ?? false,
]);
print "<html><head><title>TEST CLASS: FILE</title><head>";
$PAGE_NAME = 'TEST CLASS: FILE';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$file = '/some/path/to/some/file.txt';
print "GETFILENAMEENDING: $file: " . File::getFilenameEnding($file) . "<br>";

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-hash';
ob_end_flush();
@@ -45,9 +41,12 @@ $hash_class = 'CoreLibs\Create\Hash';
// define a list of from to color sets for conversion test
print "<html><head><title>TEST CLASS: HASH</title><head>";
$PAGE_NAME = 'TEST CLASS: HASH';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$to_crc = 'Some text block';
// static

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-html';
ob_end_flush();
@@ -49,9 +45,12 @@ $elements_class = 'CoreLibs\Output\Form\Elements';
// define a list of from to color sets for conversion test
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
$PAGE_NAME = 'TEST CLASS: HTML/ELEMENTS';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$string = "Something < = > Other <br> Next line";
print "HTMLENT: " . Html::htmlent($string) . ": " . $_html->htmlent($string) . "<br>";

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-image';
ob_end_flush();
@@ -46,9 +42,12 @@ $image_class = 'CoreLibs\Output\Image';
// define a list of from to color sets for conversion test
print "<html><head><title>TEST CLASS: IMAGE</title><head>";
$PAGE_NAME = 'TEST CLASS: IMAGE';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// thumb sizes
$thumb_width = 250;

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-json';
ob_end_flush();
@@ -46,9 +42,12 @@ $json_class = 'CoreLibs\Convert\Json';
// define a list of from to color sets for conversion test
print "<html><head><title>TEST CLASS: JSON</title><head>";
$PAGE_NAME = 'TEST CLASS: JSON';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$json = '{"foo": "bar"}';
$output = Json::jsonConvertToArray($json);

View File

@@ -19,38 +19,164 @@ ob_start();
// basic class test file
define('USE_DATABASE', false);
// init language
$lang = 'en_utf8';
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-lang';
$l = new CoreLibs\Language\L10n($lang);
ob_end_flush();
print "<html><head><title>TEST CLASS: LANG</title><head>";
$PAGE_NAME = 'TEST CLASS: LANG';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
use CoreLibs\Language\L10n;
use CoreLibs\Debug\Support;
echo "<br><b>LIST LOCALES</b><br>";
$locale = 'en_US.UTF-8';
$locales = CoreLibs\Language\L10n::listLocales($locale);
print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "<br>";
$locale = 'en.UTF-8';
$locales = CoreLibs\Language\L10n::listLocales($locale);
print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "<br>";
echo "<br><b>LOCALE INFO</b><br>";
$locale = 'en_US.UTF-8';
$locale_info = CoreLibs\Language\L10n::parseLocale($locale);
print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "<br>";
$locale = 'en.UTF-8';
$locale_info = CoreLibs\Language\L10n::parseLocale($locale);
print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "<br>";
echo "<br><b>AUTO DETECT</b><br>";
$get_locale = \CoreLibs\Language\GetLocale::setLocale();
print "[AUTO]: " . Support::printAr($get_locale) . "<br>";
$get_locale = \CoreLibs\Language\GetLocale::setLocale('en', 'foo', 'ISO-8895');
print "[OVERRIDE]: " . Support::printAr($get_locale) . "<br>";
// try to load non existing
echo "<br><b>NEW TYPE</b><br>";
// translate string
$string = 'INPUT TEST';
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
// new path test
$lang = 'ja';
$domain = 'admin';
$encoding = 'UTF-8';
$path = BASE . INCLUDES . LOCALE;
// load direct
$l = new CoreLibs\Language\L10n($lang, $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
// switch to other language
$lang = 'ja_utf8';
$l->l10nReloadMOfile($lang);
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
$single_string = 'single';
$multi_string = 'multi';
for ($n = 0; $n <= 3; $n++) {
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
. $l->__n($single_string, $multi_string, $n) . "<br>";
}
$context = "month name";
$context_string = "May";
echo "CONTEXT TRANSLATION: " . $context_string . " => " . $l->__p($context, $context_string) . "<br>";
$single_string = 'single';
$multi_string = 'multi';
for ($n = 0; $n <= 3; $n++) {
echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
. $l->__np($context, $single_string, $multi_string, $n) . "<br>";
}
// change domain
$domain = 'frontend';
$l->getTranslator('', $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
// TODO: run compare check input must match output
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
// change language short type
$lang = 'en';
$domain = 'admin';
$l->getTranslator($lang, $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
// chang to wrong language
$lang = 'tr';
$l->getTranslator($lang, $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
$lang = 'en';
$domain = 'admin';
echo "<br><b>STATIC TYPE TEST</b><br>";
// static tests from l10n_load
L10n::getInstance()->setLocale($lang);
echo "SET LOCALE: " . L10n::getInstance()->getLocale() . "<br>";
L10n::getInstance()->setDomain($domain);
echo "SET DOMAIN: " . L10n::getInstance()->getDomain() . "<br>";
L10n::getInstance()->setTextDomain($domain, $path);
echo "SET TEXT DOMAIN: " . L10n::getInstance()->getTextDomain($domain) . "<br>";
// null call __bind_textdomain_codeset
echo "INPUT TEST: " . $string . " => " . L10n::getInstance()->getTranslator()->gettext($string) . "<br>";
echo "<br><b>FUNCTIONS</b><br>";
// real statisc test
L10n::loadFunctions();
$locale = 'ja';
_setlocale(LC_MESSAGES, $locale);
_textdomain($domain);
_bindtextdomain($domain, $path);
_bind_textdomain_codeset($domain, $encoding);
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
$single_string = 'single';
$multi_string = 'multi';
for ($n = 0; $n <= 3; $n++) {
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
. _ngettext($single_string, $multi_string, $n) . "<br>";
}
$locale = 'en_US.UTF-8';
_setlocale(LC_MESSAGES, $locale);
_textdomain($domain);
_bindtextdomain($domain, $path);
_bind_textdomain_codeset($domain, $encoding);
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
$single_string = 'single';
$multi_string = 'multi';
for ($n = 0; $n <= 3; $n++) {
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
. _ngettext($single_string, $multi_string, $n) . "<br>";
}
print "</body></html>";

View File

@@ -0,0 +1,61 @@
<?php // phpcs:ignore warning
/**
* @phan-file-suppress PhanTypeSuspiciousStringExpression
*/
declare(strict_types=1);
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
ob_start();
// basic class test file
define('USE_DATABASE', false);
// sample config
require 'config.php';
// define log file id
$LOG_FILE_ID = 'classTest-login';
$SET_SESSION_NAME = EDIT_SESSION_NAME;
// init login & backend class
$session = new CoreLibs\Create\Session($SET_SESSION_NAME);
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$login = new CoreLibs\ACL\Login($db, $log, $session);
ob_end_flush();
$PAGE_NAME = 'TEST CLASS: LOGIN';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
echo "CHECK PERMISSION: " . ($login->loginCheckPermissions() ? 'OK' : 'BAD') . "<br>";
echo "IS ADMIN: " . ($login->loginIsAdmin() ? 'OK' : 'BAD') . "<br>";
echo "MIN ACCESS BASE: " . ($login->loginCheckAccessBase('admin') ? 'OK' : 'BAD') . "<br>";
echo "MIN ACCESS PAGE: " . ($login->loginCheckAccessPage('admin') ? 'OK' : 'BAD') . "<br>";
echo "ACL: " . \CoreLibs\Debug\Support::printAr($login->loginGetAcl()) . "<br>";
echo "ACL (MIN): " . \CoreLibs\Debug\Support::printAr($login->loginGetAcl()['min']) . "<br>";
// error message
print $log->printErrorMsg();
print "</body></html>";

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-math';
ob_end_flush();
@@ -44,9 +40,12 @@ $math_class = 'CoreLibs\Convert\Math';
// define a list of from to color sets for conversion test
print "<html><head><title>TEST CLASS: MATH</title><head>";
$PAGE_NAME = 'TEST CLASS: MATH';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "FCEIL: " . $_math->fceil(5.1234567890, 5) . "<br>";
print "FLOORP: " . $_math->floorp(5123456, -3) . "<br>";

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-mime';
ob_end_flush();
@@ -41,9 +37,12 @@ $log = new CoreLibs\Debug\Logging([
]);
$_mime = new CoreLibs\Convert\MimeAppName();
print "<html><head><title>TEST CLASS: MIME</title><head>";
$PAGE_NAME = 'TEST CLASS: MIME';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$mime = 'application/illustrator';
print "MIME $mime: " . $_mime->mimeGetAppName($mime) . "<br>";

View File

@@ -23,10 +23,6 @@ define('USE_DATABASE', true);
require 'config.php';
// override ECHO ALL FALSE
$ECHO_ALL = true;
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-form';
ob_end_flush();
@@ -69,9 +65,12 @@ $log = new CoreLibs\Debug\Logging([
]);
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
print "<html><head><title>TEST CLASS: FORM GENERATE</title><head>";
$PAGE_NAME = 'TEST CLASS: FORM GENERATE';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "MOBILE PHONE: " . $form->mobile_phone . "<br>";
// sets table array to include

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-pass';
ob_end_flush();
@@ -46,9 +42,12 @@ $password_class = 'CoreLibs\Check\Password';
// define a list of from to color sets for conversion test
print "<html><head><title>TEST CLASS: PASSWORD</title><head>";
$PAGE_NAME = 'TEST CLASS: PASSWORD';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$password = 'something1234';
$enc_password = $_password->passwordSet($password);

View File

@@ -21,14 +21,12 @@ ob_start();
define('USE_DATABASE', true);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest';
$SET_SESSION_NAME = EDIT_SESSION_NAME;
// init login & backend class
$session = new CoreLibs\Create\Session($SET_SESSION_NAME);
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
@@ -40,11 +38,18 @@ $log = new CoreLibs\Debug\Logging([
'print_all' => $PRINT_ALL ?? false,
]);
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$login = new CoreLibs\ACL\Login($db, $log);
$backend = new CoreLibs\Admin\Backend($db, $log);
$login = new CoreLibs\ACL\Login($db, $log, $session);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$backend = new CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
$backend->db->dbInfo(true);
ob_end_flush();
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS</title><head>";
print "<body>";
@@ -60,7 +65,7 @@ print '<div><a href="class_test.email.php">Class Test: EMAIL</a></div>';
print '<div><a href="class_test.uids.php">Class Test: UIDS</a></div>';
print '<div><a href="class_test.phpv.php">Class Test: PHP VERSION</a></div>';
print '<div><a href="class_test.hash.php">Class Test: HASH</a></div>';
print '<div><a href="class_test.encoding.php">Class Test: ENCODING</a></div>';
print '<div><a href="class_test.encoding.php">Class Test: ENCODING (CHECK/CONVERT/MIME)</a></div>';
print '<div><a href="class_test.image.php">Class Test: IMAGE</a></div>';
print '<div><a href="class_test.byte.php">Class Test: BYTE CONVERT</a></div>';
print '<div><a href="class_test.datetime.php">Class Test: DATE/TIME</a></div>';
@@ -74,13 +79,19 @@ print '<div><a href="class_test.debug.php">Class Test: DEBUG</a></div>';
print '<div><a href="class_test.output.form.php">Class Test: OUTPUT FORM</a></div>';
print '<div><a href="class_test.admin.backend.php">Class Test: BACKEND ADMIN CLASS</a></div>';
print '<div><a href="class_test.lang.php">Class Test: LANG/L10n</a></div>';
print '<div><a href="class_test.session.php">Class Test: SESSION</a></div>';
print '<div><a href="class_test.smarty.php">Class Test: SMARTY</a></div>';
print '<div><a href="class_test.login.php">Class Test: LOGIN</a></div>';
print '<div><a href="class_test.autoloader.php">Class Test: AUTOLOADER</a></div>';
print '<div><a href="class_test.config.link.php">Class Test: CONFIG LINK</a></div>';
print '<div><a href="class_test.config.direct.php">Class Test: CONFIG DIRECT</a></div>';
print '<div><a href="subfolder/class_test.config.direct.php">Class Test: CONFIG DIRECT SUB</a></div>';
print "<hr>";
print "L: " . CoreLibs\Debug\Support::printAr($locale) . "<br>";
// print all _ENV vars set
print "<div>READ _ENV ARRAY:</div>";
print "<pre>" . print_r(array_map('htmlentities', $_ENV), true) . "</pre>";
print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV));
// set + check edit access id
$edit_access_id = 3;
if (is_object($login) && isset($login->acl['unit'])) {

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-phpv';
ob_end_flush();
@@ -46,9 +42,12 @@ $phpv_class = 'CoreLibs\Check\PhpVersion';
// define a list of from to color sets for conversion test
print "<html><head><title>TEST CLASS: PHP VERSION</title><head>";
$PAGE_NAME = 'TEST CLASS: PHP VERSION';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$min_version_s = '7';
$min_version_ss = '7.1';

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-randomkey';
ob_end_flush();
@@ -43,9 +39,12 @@ $log = new CoreLibs\Debug\Logging([
]);
$array_class = 'CoreLibs\Create\RandomKey';
print "<html><head><title>TEST CLASS: RANDOM KEY</title><head>";
$PAGE_NAME = 'TEST CLASS: RANDOM KEY';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$key_length = 10;
$key_length_b = 5;

View File

@@ -14,10 +14,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-readEnvFile';
ob_end_flush();
@@ -34,9 +30,12 @@ $log = new CoreLibs\Debug\Logging([
]);
$ref_class = 'CoreLibs\Get\ReadEnvFile';
print "<html><head><title>TEST CLASS: READ ENV FILE</title><head>";
$PAGE_NAME = 'TEST CLASS: READ ENV FILE';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "ALREADY from config.php: " . \CoreLibs\Debug\Support::printAr($_ENV) . "<br>";

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-runningtime';
ob_end_flush();
@@ -42,9 +38,12 @@ $log = new CoreLibs\Debug\Logging([
'print_all' => $PRINT_ALL ?? false,
]);
print "<html><head><title>TEST CLASS: RUNNING IMTE</title><head>";
$PAGE_NAME = 'TEST CLASS: RUNNING TIME';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
RunningTime::hrRunningTime();
RunningTime::runningTime();

View File

@@ -0,0 +1,183 @@
<?php // phpcs:ignore warning
declare(strict_types=1);
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
/**
* Undocumented function
*
* @param int $status
* @return string
*/
/** @phan-suppress-next-line PhanRedefineFunction */
function getSessionStatusString(int $status): string
{
switch ($status) {
case PHP_SESSION_DISABLED:
$status = 'PHP_SESSION_DISABLED';
break;
case PHP_SESSION_NONE:
$status = 'PHP_SESSION_NONE';
break;
case PHP_SESSION_ACTIVE:
$status = 'PHP_SESSION_ACTIVE';
break;
default:
$status = '[!] UNDEFINED';
break;
}
return $status;
}
ob_start();
// basic class test file
define('USE_DATABASE', false);
// sample config
require 'config.php';
// define log file id
$LOG_FILE_ID = 'classTest-session';
ob_end_flush();
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
use CoreLibs\Create\Session;
$session = new Session();
$PAGE_NAME = 'TEST CLASS: SESSION';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$session_name = 'class-test-session';
$var = 'foo';
$value = 'bar';
foreach (['123', '123-123', '123abc'] as $_session_name) {
print "[UNSET] Session Name valid for " . $_session_name . ": "
. ($session->checkValidSessionName($_session_name) ? 'Valid' : 'Invalid') . "<br>";
}
echo "Global session name: " . ($GLOBALS['SET_SESSION_NAME'] ?? '-') . "<br>";
print "[UNSET] Current session id: " . $session->getSessionId() . "<br>";
print "[UNSET] Current session name: " . $session->getSessionName() . "<br>";
print "[UNSET] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
print "[UNSET] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
if (isset($_SESSION)) {
print "[UNSET] _SESSION is: set<br>";
} else {
print "[UNSET] _SESSION is: not set<br>";
}
#
print "[UNSET] To set session name valid: "
. ($session->checkValidSessionName($session_name) ? 'Valid' : 'Invalid') . "<br>";
if (false === ($session_id = $session->startSession($session_name))) {
print "[FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
} else {
print "[SET] Current session id: " . $session_id . "<br>";
}
// set again
if (false === ($session_id = $session->startSession($session_name))) {
print "[2 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
} else {
print "[2 SET] Current session id: " . $session_id . "<br>";
}
print "[SET] Current session id: " . $session->getSessionId() . "<br>";
print "[SET] Current session name: " . $session->getSessionName() . "<br>";
print "[SET] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
print "[SET] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
if (isset($_SESSION)) {
print "[SET] _SESSION is: set<br>";
} else {
print "[SET] _SESSION is: not set<br>";
}
if (!isset($_SESSION['counter'])) {
$_SESSION['counter'] = 0;
}
$_SESSION['counter']++;
print "[READ] A " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
$_SESSION[$var] = $value;
print "[READ] B " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
print "[READ] Confirm " . $var . " is " . $value . ": "
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
// test set wrappers methods
$session->setS('setwrap', 'YES, method set _SESSION var');
print "[READ WRAP] A setwrap: " . $session->getS('setwrap') . "<br>";
print "[READ WRAP] Isset: " . ($session->issetS('setwrap') ? 'Yes' : 'No') . "<br>";
$session->unsetS('setwrap');
print "[READ WRAP] unset setwrap: " . $session->getS('setwrap') . "<br>";
print "[READ WRAP] unset Isset: " . ($session->issetS('setwrap') ? 'Yes' : 'No') . "<br>";
// test __get/__set
$session->setwrap = 'YES, magic set _SESSION var';
print "[READ MAGIC] A setwrap: " . $session->setwrap . "<br>";
print "[READ MAGIC] Isset: " . (isset($session->setwrap) ? 'Yes' : 'No') . "<br>";
unset($session->setwrap);
print "[READ MAGIC] unset setwrap: " . $session->setwrap . "<br>";
print "[READ MAGIC] unset Isset: " . (isset($session->setwrap) ? 'Yes' : 'No') . "<br>";
// differnt session name
$session_name = 'class-test-session-ALT';
if (false === ($session_id = $session->startSession($session_name))) {
print "[3 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
} else {
print "[3 SET] Current session id: " . $session_id . "<br>";
}
print "[SET AGAIN] Current session id: " . $session->getSessionId() . "<br>";
print "[ALL SESSION]: " . \CoreLibs\Debug\Support::printAr($_SESSION) . "<br>";
// close session
$session->writeClose();
// will never be written
$_SESSION['will_never_be_written'] = 'empty';
// open again
$session_name = 'class-test-session';
if (false === ($session_id = $session->startSession($session_name))) {
print "[4 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
} else {
print "[4 SET] Current session id: " . $session_id . "<br>";
}
print "[START AGAIN] Current session id: " . $session->getSessionId() . "<br>";
$_SESSION['will_be_written_again'] = 'Full';
// close session
$session->writeClose();
// invalid
$session_name = '123';
if (false === ($session_id = $session->startSession($session_name))) {
print "[5 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
} else {
print "[5 SET] Current session id: " . $session_id . "<br>";
}
print "[BAD NAME] Current session id: " . $session->getSessionId() . "<br>";
print "[BAD NAME] Current session name: " . $session->getSessionName() . "<br>";
print "[BAD NAME] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
print "[BAD NAME] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
// error message
print $log->printErrorMsg();
print "</body></html>";
// __END__

View File

@@ -0,0 +1,110 @@
<?php // phpcs:ignore warning
declare(strict_types=1);
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
/**
* Undocumented function
*
* @param int $status
* @return string
*/
/** @phan-suppress-next-line PhanRedefineFunction */
function getSessionStatusString(int $status): string
{
switch ($status) {
case PHP_SESSION_DISABLED:
$status = 'PHP_SESSION_DISABLED';
break;
case PHP_SESSION_NONE:
$status = 'PHP_SESSION_NONE';
break;
case PHP_SESSION_ACTIVE:
$status = 'PHP_SESSION_ACTIVE';
break;
default:
$status = '[!] UNDEFINED';
break;
}
return $status;
}
ob_start();
// basic class test file
define('USE_DATABASE', false);
// sample config
require 'config.php';
// define log file id
$LOG_FILE_ID = 'classTest-session.read';
ob_end_flush();
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
use CoreLibs\Create\Session;
$session = new Session();
$PAGE_NAME = 'TEST CLASS: SESSION (READ)';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$session_name = 'class-test-session';
// $session_name = '';
$var = 'foo';
$value = 'bar';
echo "Global session name: " . ($GLOBALS['SET_SESSION_NAME'] ?? '-') . "<br>";
print "[UNSET] Current session id: " . $session->getSessionId() . "<br>";
print "[UNSET] Current session name: " . $session->getSessionName() . "<br>";
print "[UNSET] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
print "[UNSET] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
// start
if (false === ($session_id = $session->startSession($session_name))) {
print "Session start failed: " . $session->getErrorStr() . "<br>";
} else {
print "Current session id: " . $session_id . "<br>";
}
// set again
if (false === ($session_id = $session->startSession($session_name))) {
print "[2] Session start failed<br>";
} else {
print "[2] Current session id: " . $session_id . "<br>";
}
print "[SET] Current session id: " . $session->getSessionId() . "<br>";
print "[SET] Current session name: " . $session->getSessionName() . "<br>";
print "[SET] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
print "[SET] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
print "[READ] Confirm " . $var . " is " . $value . ": "
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
print "[ALL SESSION]: " . \CoreLibs\Debug\Support::printAr($_SESSION) . "<br>";
// error message
print $log->printErrorMsg();
print "</body></html>";
// __END__

View File

@@ -19,16 +19,10 @@ ob_start();
// basic class test file
define('USE_DATABASE', true);
// set language
$lang = 'en_utf8';
// sample config
require 'config.php';
// override ECHO ALL FALSE
$ECHO_ALL = true;
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-smarty';
ob_end_flush();
@@ -43,12 +37,20 @@ $log = new CoreLibs\Debug\Logging([
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$smarty = new CoreLibs\Template\SmartyExtend();
$l = new CoreLibs\Language\L10n($lang);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
$PAGE_NAME = 'TEST CLASS: SMARTY';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$smarty->DATA['JS_DEBUG'] = DEBUG;
$smarty->MASTER_TEMPLATE_NAME = 'main_body.tpl';
@@ -69,7 +71,8 @@ $smarty->setSmartyPaths();
// smarty test
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
$smarty->DATA['TRANSLATE_TEST'] = $l->__('Are we translated?');
$smarty->DATA['TRANSLATE_TEST'] = $l10n->__('Are we translated?');
$smarty->DATA['TRANSLATE_TEST_FUNCTION'] = _gettext('Are we translated?');
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
$smarty->DATA['replace'] = 'Replaced';
// variable variables

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-system';
ob_end_flush();
@@ -42,22 +38,31 @@ $log = new CoreLibs\Debug\Logging([
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$basic = new CoreLibs\Basic($log);
print "<html><head><title>TEST CLASS: SYSTEM</title><head>";
$PAGE_NAME = 'TEST CLASS: SYSTEM';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "System::getHostName():<br>";
print "GETHOSTNAME: " . DgS::printAr(System::getHostName()) . "<br>";
print "System::getPageName():<br>";
print "GETPAGENAME(0): " . System::getPageName() . "<br>";
print "GETPAGENAME(1): " . System::getPageName(System::NO_EXTENSION) . "<br>";
print "GETPAGENAME(2): " . System::getPageName(System::FULL_PATH) . "<br>";
print "System::getPageNameArray():<br>";
print "GETPAGENAMEARRAY: " . \CoreLibs\Debug\Support::printAr(System::getPageNameArray()) . "<br>";
// seting errro codes file upload
print "System::fileUploadErrorMessage():<br>";
print "FILEUPLOADERRORMESSAGE(): " . System::fileUploadErrorMessage(-1) . "<br>";
print "FILEUPLOADERRORMESSAGE(UPLOAD_ERR_CANT_WRITE): "
. System::fileUploadErrorMessage(UPLOAD_ERR_CANT_WRITE) . "<br>";
print "System::checkCLI():<br>";
print "Are we in an CLI: " . (System::checkCLI() ? 'Yes' : 'No') . "<br>";
// error message
print $log->printErrorMsg();

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-token';
ob_end_flush();
@@ -42,9 +38,12 @@ $log = new CoreLibs\Debug\Logging([
$_token = new CoreLibs\Output\Form\Token();
$token_class = 'CoreLibs\Output\Form\Token';
print "<html><head><title>TEST CLASS: FORM TOKEN</title><head>";
$PAGE_NAME = 'TEST CLASS: FORM TOKEN';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$token = 'test_form_token';
$token_id = $_token->setFormToken($token);

View File

@@ -21,10 +21,6 @@ ob_start();
define('USE_DATABASE', false);
// sample config
require 'config.php';
// set session name
if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
$LOG_FILE_ID = 'classTest-uids';
ob_end_flush();
@@ -43,9 +39,12 @@ $_uids = new CoreLibs\Create\Uids();
use CoreLibs\Create\Uids;
$uids_class = 'CoreLibs\Create\Uids';
print "<html><head><title>TEST CLASS: UIDS</title><head>";
$PAGE_NAME = 'TEST CLASS: UIDS';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
// class
print "UUIDV4: " . $_uids->uuidv4() . "<br>";

View File

@@ -0,0 +1,59 @@
<?php // phpcs:ignore warning
/**
* @phan-file-suppress PhanTypeSuspiciousStringExpression
*/
declare(strict_types=1);
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
ob_start();
// basic class test file
define('USE_DATABASE', false);
// sample config
require '../../configs/config.php';
// define log file id
$LOG_FILE_ID = 'classTest-config-direct';
ob_end_flush();
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$PAGE_NAME = 'TEST CLASS: CONFIG DIRECT SUB';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="../class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "DIR: " . DIR . "<br>";
print "BASE: " . BASE . "<br>";
print "ROOT: " . ROOT . "<br>";
print "BASE NAME: " . BASE_NAME . "<br>";
echo "Config path prefix: " . $CONFIG_PATH_PREFIX . "<br>";
print "DB Name: " . DB_CONFIG_NAME . "<br>";
print "DB Config: " . \CoreLibs\Debug\Support::printAr(DB_CONFIG) . "<br>";
// error message
print $log->printErrorMsg();
print "</body></html>";
// __END__

38
www/composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "fb2235a66a37d89e7941a863843d2e15",
"content-hash": "a71e6f4fbc06f0efb6ad34538b515c53",
"packages": [],
"packages-dev": [
{
@@ -415,16 +415,16 @@
},
{
"name": "phpdocumentor/type-resolver",
"version": "1.6.0",
"version": "1.6.1",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
"reference": "77a32518733312af16a44300404e945338981de3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3",
"reference": "77a32518733312af16a44300404e945338981de3",
"shasum": ""
},
"require": {
@@ -459,9 +459,9 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1"
},
"time": "2022-01-04T19:58:01+00:00"
"time": "2022-03-15T21:29:03+00:00"
},
{
"name": "phpspec/prophecy",
@@ -850,16 +850,16 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.19",
"version": "9.5.20",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807"
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807",
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba",
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba",
"shasum": ""
},
"require": {
@@ -937,7 +937,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20"
},
"funding": [
{
@@ -949,7 +949,7 @@
"type": "github"
}
],
"time": "2022-03-15T09:57:31+00:00"
"time": "2022-04-01T12:37:26+00:00"
},
{
"name": "sebastian/cli-parser",
@@ -1317,16 +1317,16 @@
},
{
"name": "sebastian/environment",
"version": "5.1.3",
"version": "5.1.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "388b6ced16caa751030f6a69e588299fa09200ac"
"reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/388b6ced16caa751030f6a69e588299fa09200ac",
"reference": "388b6ced16caa751030f6a69e588299fa09200ac",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7",
"reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7",
"shasum": ""
},
"require": {
@@ -1368,7 +1368,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/environment/issues",
"source": "https://github.com/sebastianbergmann/environment/tree/5.1.3"
"source": "https://github.com/sebastianbergmann/environment/tree/5.1.4"
},
"funding": [
{
@@ -1376,7 +1376,7 @@
"type": "github"
}
],
"time": "2020-09-28T05:52:38+00:00"
"time": "2022-04-03T09:37:03+00:00"
},
{
"name": "sebastian/exporter",

View File

@@ -27,7 +27,8 @@ $__LOCAL_CONFIG = [
'db_host' => 'test',
'location' => 'test',
'debug_flag' => true,
'site_lang' => 'en_utf8',
'site_locale' => 'en_US.UTF-8',
'site_encoding' => 'UTF-8',
'login_enabled' => true
];
@@ -44,13 +45,18 @@ $SITE_CONFIG = [
'location' => 'test',
// show DEBUG override
'debug_flag' => true,
// site language
'site_lang' => 'en_utf8',
// site locale
'site_locale' => 'en_US.UTF-8',
// site encoding
'site_encoding' => 'UTF-8',
// enable/disable login override
'login_enabled' => true
],
// 'other.host.com' => $__LOCAL_CONFIG
'soba-dev.tequila.jp' => $__LOCAL_CONFIG
'soba-dev.tequila.jp' => $__LOCAL_CONFIG,
'soba.tequila.jp' => $__LOCAL_CONFIG,
'soba.teq.jp' => $__LOCAL_CONFIG,
'soba-local.tokyo.tequila.jp' => $__LOCAL_CONFIG,
];
// __END__

View File

@@ -65,8 +65,8 @@ define('JS', 'javascript' . DIRECTORY_SEPARATOR);
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
// smarty libs path
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
// po langs
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
// po locale file
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
// cache path
define('CACHE', 'cache' . DIRECTORY_SEPARATOR);
// temp path
@@ -150,15 +150,14 @@ define('SERVER_PATH_HASH', hash('crc32b', BASE));
define('EDIT_SESSION_NAME', BASE_NAME . 'Admin' . SERVER_NAME_HASH . SERVER_PATH_HASH);
// frontend
define('SESSION_NAME', BASE_NAME . SERVER_NAME_HASH . SERVER_PATH_HASH);
// SET_SESSION_NAME should be set in the header if a special session name is needed
define('SET_SESSION_NAME', SESSION_NAME);
/************* CACHE/COMPILE IDS *************/
define('CACHE_ID', 'CACHE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
define('COMPILE_ID', 'COMPILE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
/************* LANGUAGE / ENCODING *******/
define('DEFAULT_LANG', 'en_utf8');
// default lang + encoding
define('DEFAULT_LOCALE', 'en_US.UTF-8');
// default web page encoding setting
define('DEFAULT_ENCODING', 'UTF-8');
@@ -258,7 +257,8 @@ $GLOBALS['DB_CONFIG'] = DB_CONFIG;
// debug settings, site lang, etc
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang'] ?? 'en_utf8');
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
// paths

View File

@@ -21,7 +21,10 @@ $paths = [
];
// find convert
foreach ($paths as $path) {
if (file_exists($path . DIRECTORY_SEPARATOR . 'convert') && is_file($path . DIRECTORY_SEPARATOR . 'convert')) {
if (
file_exists($path . DIRECTORY_SEPARATOR . 'convert') &&
is_file($path . DIRECTORY_SEPARATOR . 'convert')
) {
// image magick convert location
define('CONVERT', $path . DIRECTORY_SEPARATOR . 'convert');
break;

View File

@@ -11,51 +11,68 @@
declare(strict_types=1);
define('CONFIG_PATH', 'configs' . DIRECTORY_SEPARATOR);
// config path prefix search, start with 0, got down each level __DIR__ has, if nothing found -> bail
// config path prefix search, start with 0, got down each level __DIR__ has,
// if nothing found -> bail
$CONFIG_PATH_PREFIX = '';
// base path for loads
$__DIR__PATH = __DIR__ . DIRECTORY_SEPARATOR;
// don't load autoloader twice
$end_autoload = false;
for ($dir_pos = 0, $dir_max = count(explode(DIRECTORY_SEPARATOR, __DIR__)); $dir_pos <= $dir_max; $dir_pos++) {
for (
$dir_pos = 0, $dir_max = count(explode(DIRECTORY_SEPARATOR, __DIR__));
$dir_pos <= $dir_max;
$dir_pos++
) {
$CONFIG_PATH_PREFIX .= '..' . DIRECTORY_SEPARATOR;
if ($end_autoload === false) {
/************* AUTO LOADER *******************/
// read auto loader for lib only
// It is recommended to setup basic composer and use just one auto loader
// if (is_file($CONFIG_PATH_PREFIX . 'lib' . DIRECTORY_SEPARATOR . 'autoloader.php')) {
// require $CONFIG_PATH_PREFIX . 'lib' . DIRECTORY_SEPARATOR . 'autoloader.php';
// $end_autoload = true;
// }
// composer auto loader, IF composer.json file includes classmap for lib/:
// composer auto loader, in composer.json file add classmap for lib/:
// "autoload": {
// "classmap": [
// "lib/"
// ]
// },
// NOTE: MUST RUN composer dump-autoload if file/class names are changed or added
// load auto loader
if (is_file($CONFIG_PATH_PREFIX . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) {
require $CONFIG_PATH_PREFIX . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
// NOTE: MUST RUN composer dump-autoload if file/class names are
// changed or new ones are added
if (
is_file(
$__DIR__PATH . $CONFIG_PATH_PREFIX
. 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'
)
) {
require $__DIR__PATH . $CONFIG_PATH_PREFIX
. 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$end_autoload = true;
}
// load enviorment file if it exists
\CoreLibs\Get\ReadEnvFile::readEnvFile($CONFIG_PATH_PREFIX . CONFIG_PATH);
}
/************* MASTER CONFIG *******************/
if (is_file($CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')) {
if (
is_file($__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')
) {
// load enviorment file if it exists
\CoreLibs\Get\ReadEnvFile::readEnvFile(
$__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH
);
// load master config file that loads all other config files
require $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php';
require $__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php';
break;
}
}
// fail if no base DIR is not set
if (!defined('DIR')) {
exit('Base config unloadable');
exit('Base config could not be loaded');
}
// find trigger name "admin/" or "frontend/" in the getcwd() folder
foreach (['admin', 'frontend'] as $folder) {
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $folder)) {
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
break;
}
}
// if content path is empty, fallback is default
/** @phpstan-ignore-next-line can be empty */
if (empty($folder)) {
$folder = 'default';
}
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
// __END__

View File

@@ -1,77 +0,0 @@
<?php
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/19
* SHORT DESCRIPTION:
* preset date variables
* HISTORY:
*********************************************************************/
declare(strict_types=1);
/******
All moved to CoreLibs\Combined\DateTime
DAY_SHORT
DAY_LONG
MONTH_LONG
MONTH_SHORT
*******/
trigger_error(
'Date.VArs.php is deprecated. '
. 'Use CoreLibs\Combined\DateTime:: with upper case old variable name',
E_USER_DEPRECATED
);
$day_short = [
1 => 'Mon',
2 => 'Tue',
3 => 'Wed',
4 => 'Thu',
5 => 'Fri',
6 => 'Sat',
7 => 'Sun'
];
$day_long = [
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
7 => 'Sunday'
];
// months
$month_long = [
1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'August',
9 => 'September',
10 => 'October',
11 => 'November',
12 => 'December'
];
$month_short = [
1 => 'Jan',
2 => 'Feb',
3 => 'Mar',
4 => 'Apr',
5 => 'May',
6 => 'Jun',
7 => 'Jul',
8 => 'Aug',
9 => 'Sep',
10 => 'Oct',
11 => 'Nov',
12 => 'Dec'
];
// __END__

View File

@@ -19,15 +19,17 @@ if (!empty($DEBUG_ALL) && !empty($ENABLE_ERROR_HANDLING)) {
//------------------------------ library include start
// set output to quiet for load of classes & session settings
ob_start();
// set the session name
$SET_SESSION_NAME = EDIT_SESSION_NAME;
$LOG_FILE_ID = BASE_NAME . 'Admin';
//------------------------------ library include end
//------------------------------ basic variable settings start
// set the session name
$SET_SESSION_NAME = EDIT_SESSION_NAME;
$LOG_FILE_ID = BASE_NAME . 'Admin';
// ajax page flag
if (!isset($AJAX_PAGE)) {
$AJAX_PAGE = false;
}
// zip download flag
if (!isset($ZIP_STREAM)) {
$ZIP_STREAM = false;
}
@@ -42,15 +44,15 @@ if (isset($_POST['action']) && $_POST['action'] != 'download_csv' && !$AJAX_PAGE
if ($AJAX_PAGE && !$ZIP_STREAM) {
header("Content-Type: application/json; charset=UTF-8");
}
// start session
CoreLibs\Create\Session::startSession();
//------------------------------ basic variable settings start
//------------------------------ class init start
// start session
$session = new \CoreLibs\Create\Session($SET_SESSION_NAME);
// create logger
$log = new CoreLibs\Debug\Logging([
$log = new \CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => LOG_FILE_ID,
'file_id' => $LOG_FILE_ID,
'print_file_date' => true,
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
@@ -69,13 +71,22 @@ if (
}
}
// db config with logger
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$db = new \CoreLibs\DB\IO(DB_CONFIG, $log);
// login & page access check
$login = new CoreLibs\ACL\Login($db, $log);
$login = new \CoreLibs\ACL\Login($db, $log, $session);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
// create smarty object
$smarty = new CoreLibs\Template\SmartyExtend();
$smarty = new \CoreLibs\Template\SmartyExtend($l10n, $locale);
// create new Backend class with db and loger attached
$cms = new CoreLibs\Admin\Backend($db, $log);
$cms = new \CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
// the menu show flag (what menu to show)
$cms->menu_show_flag = 'main';
// db info

View File

@@ -1,22 +0,0 @@
<?php
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2007/09/03
* SHORT DESCRIPTION:
* set paths & language variables
* HISTORY:
*********************************************************************/
declare(strict_types=1);
/******
NOTE THAT THIS INCLUDE IS OBSOLETE
USE THE BELOW FUNCTION CALL IN THE SCRIPT ITSELF
*******/
trigger_error('admin_set_paths.php is deprecated. Use SmartyExtended->setSmartyPaths();', E_USER_DEPRECATED);
if ($smarty) {
$smarty->setSmartyPaths();
}
// __END__

View File

@@ -1,23 +0,0 @@
<?php
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/12
* SHORT DESCRIPTION:
* default smarty vars, and create output template for smarty
* HISTORY:
*********************************************************************/
declare(strict_types=1);
/******
NOTE THAT THIS INCLUDE IS OBSOLETE
USE THE BELOW FUNCTION CALL IN THE SCRIPT ITSELF
*******/
trigger_error(
'admin_smarty.php is deprecated. Use SmartyExtended->setSmartyVarsAdmin(); or setSmartyVarsFrontend();',
E_USER_DEPRECATED
);
$smarty->setSmartyVarsAdmin();
// __END__

View File

@@ -33,8 +33,6 @@ extract($_POST, EXTR_SKIP);
ob_start();
require 'config.php';
// set session name here
// $SET_SESSION_NAME = EDIT_SESSION_NAME;
// overrride debug flags
if (!DEBUG) {
$DEBUG_ALL = false;
@@ -45,8 +43,8 @@ if (!DEBUG) {
// should be utf8
header("Content-type: text/html; charset=" . DEFAULT_ENCODING);
// set session
\CoreLibs\Create\Session::startSession(EDIT_SESSION_NAME);
// start session
$session = new \CoreLibs\Create\Session(EDIT_SESSION_NAME);
// init logger
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
@@ -60,19 +58,28 @@ $log = new CoreLibs\Debug\Logging([
// db connection
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login page
$login = new CoreLibs\ACL\Login($db, $log);
$login = new CoreLibs\ACL\Login($db, $log, $session);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
// flush and start
ob_end_flush();
// turn off set log per class
$log->setLogPer('class', false);
// create form class
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log, $l10n, $locale);
if ($form->mobile_phone) {
echo "I am sorry, but this page cannot be viewed by a mobile phone";
exit;
}
// smarty template engine (extended Translation version)
$smarty = new CoreLibs\Template\SmartyExtend();
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
// $form->log->debug('POST', $form->log->prAr($_POST));
@@ -437,16 +444,15 @@ if ($form->my_page_name == 'edit_order') {
$t_q = '';
foreach ($output as $output_file) {
// split the ouput into folder and file
// eg ../admin/test.php is ../admin/ and test.php
preg_match("/([\.\/\w]+\/)+(\w+\.\w{1,})$/", $output_file, $matches);
// if named config.php, skip
if ($matches[2] != 'config.php') {
if ($t_q) {
$t_q .= ', ';
}
$t_q .= "('" . $form->dbEscapeString($matches[1]) . "', '"
. $form->dbEscapeString($matches[2]) . "')";
$pathinfo = pathinfo($output_file);
if (!empty($pathinfo['dirname'])) {
$pathinfo['dirname'] .= DIRECTORY_SEPARATOR;
}
if ($t_q) {
$t_q .= ', ';
}
$t_q .= "('" . $form->dbEscapeString($pathinfo['dirname']) . "', '"
. $form->dbEscapeString($pathinfo['basename']) . "')";
}
$form->dbExec($q . $t_q, 'NULL');
$elements[] = $form->formCreateElement('filename');

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -7,13 +7,19 @@
<div>
<b>Outside translation test</b><br>
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
TRANSLATION CLASS (OUT FUNCTION): {$TRANSLATE_TEST_FUNCTION}<br>
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}<br>
</div>
<div>
<b>Translate Test with replace:</b><br>
ORIGINAL: Original with string: %1 ({$replace})<br>
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}<br>
{capture assign="extra_title"}{t}INPUT TEST{/t}{/capture}
Capture test: {$extra_title}<br>
{section name=plural_test start=0 loop=3}
Plural test {$smarty.section.plural_test.index}: {t count=$smarty.section.plural_test.index plural="multi"}single{/t}<br>
{/section}
</div>
<div>
<b>Variable variables:</b><br>

View File

@@ -1,37 +0,0 @@
<div>
{$SMARTY_TEST}
</div>
<div>
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}
</div>
<div>
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
</div>
<div>
<select id="drop_down_test" name="drop_down_test">
{html_options options=$drop_down_test selected=$drop_down_test_selected}
</select>
</div>
<div class="jq-container">
<div id="jq-test" class="jp-test">
<div id="test-div" class="test-div">
Some content here or asdfasdfasf
</div>
<div id="translate-div">
{* TRANSLATION SMARTY: {t}I should be translated{/t} *}
TRANSLATION SMARTY: I should be translated
</div>
</div>
</div>
<div class="loop-test">
<div>LOOP TEST</div>
{section name=page_list start=1 loop=$loop_start+1}
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
{/section}
</div>
{* progresss indicator *}
<div id="indicator"></div>
{* the action confirm box *}
<div id="actionBox" class="actionBoxElement"></div>
{* The Overlay box *}
<div id="overlayBox" class="overlayBoxElement"></div>

File diff suppressed because it is too large Load Diff

View File

@@ -101,6 +101,8 @@ class Backend
public $db;
/** @var \CoreLibs\Language\L10n language */
public $l;
/** @var \CoreLibs\Create\Session session class */
public $session;
// smarty publics [end processing in smarty class]
/** @var array<mixed> */
public $DATA;
@@ -114,26 +116,36 @@ class Backend
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
/**
* main class constructor
* @param \CoreLibs\DB\IO $db Database connection class
* @param \CoreLibs\Debug\Logging $log Logging class
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
* if null, auto set
* @param \CoreLibs\DB\IO $db Database connection class
* @param \CoreLibs\Debug\Logging $log Logging class
* @param \CoreLibs\Create\Session $session Session interface class
* @param \CoreLibs\Language\L10n $l10n l10n language class
* @param array<string,string> $locale locale data read from setLocale
*/
public function __construct(
\CoreLibs\DB\IO $db,
\CoreLibs\Debug\Logging $log,
?\CoreLibs\Language\L10n $l10n = null
\CoreLibs\Create\Session $session,
\CoreLibs\Language\L10n $l10n,
array $locale
) {
// attach db class
$this->db = $db;
// set to log not per class
$log->setLogPer('class', false);
// attach logger
$this->log = $log;
// attach db class
$this->db = $db;
// TODO lang create outside of class
$this->setLangEncoding();
// attach session class
$this->session = $session;
// get the language sub class & init it
$this->l = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
$this->l = $l10n;
// parse and read, legacy stuff
$this->encoding = $locale['encoding'];
$this->lang = $locale['lang'];
// get first part from lang
$this->lang_short = explode('_', $locale['lang'])[0];
$this->domain = $this->l->getDomain();
$this->lang_dir = $this->l->getBaseLocalePath();
// set the page name
$this->page_name = \CoreLibs\Get\System::getPageName();
@@ -159,29 +171,6 @@ class Backend
// NO OP
}
// INTERNAL METHODS |===============================================>
/**
* set the language encoding and language settings
* use $OVERRIDE_LANG to override all language settings
* the default charset from _SESSION login or from
* config DEFAULT ENCODING
* the lang full name for mo loading from _SESSION login
* or SITE LANG or DEFAULT LANG from config
* creates short lang (only first two chars) from the lang
* @return void
*/
private function setLangEncoding(): void
{
list (
$this->encoding,
$this->lang,
$this->lang_short,
$this->domain,
$this->lang_dir
) = \CoreLibs\Language\GetSettings::setLangEncoding();
}
// PUBLIC METHODS |=================================================>
/**
@@ -249,9 +238,9 @@ class Backend
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT'] ?? '') . "', "
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT_CHARSET'] ?? '') . "', "
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT_ENCODING'] ?? '') . "', "
. (\CoreLibs\Create\Session::getSessionId() === false ?
. ($this->session->getSessionId() === false ?
"NULL" :
"'" . \CoreLibs\Create\Session::getSessionId() . "'")
"'" . $this->session->getSessionId() . "'")
. ", "
. "'" . $this->db->dbEscapeString($this->action) . "', "
. "'" . $this->db->dbEscapeString($this->action_id) . "', "

View File

@@ -66,6 +66,8 @@ class Basic
// logging interface, Debug\Logging class
/** @var \CoreLibs\Debug\Logging */
public $log;
/** @var\CoreLibs\Create\Session */
public $session;
// email valid checks
/** @var array<mixed> */
@@ -85,11 +87,13 @@ class Basic
* main Basic constructor to init and check base settings
* @param \CoreLibs\Debug\Logging|null $log Logging class
* @param string|null $session_name Set session name
* @deprecated DO NOT USE Class\Basic anymore. Use dedicated logger and sub classes
*/
public function __construct(
\CoreLibs\Debug\Logging $log = null,
?string $session_name = null
) {
trigger_error('Class \CoreLibs\Basic is deprected', E_USER_DEPRECATED);
// TODO make check dynamic for entries we MUST have depending on load type
// before we start any work, we should check that all MUST constants are defined
$abort = false;
@@ -146,7 +150,7 @@ class Basic
$this->email_regex_check = \CoreLibs\Check\Email::getEmailRegexCheck();
// initial the session if there is no session running already
\CoreLibs\Create\Session::startSession($session_name);
$this->session = new \CoreLibs\Create\Session($session_name ?? '');
}
/**
@@ -715,20 +719,20 @@ class Basic
// *** ARRAY HANDLING END
// [!!! DEPRECATED !!!]
// Moved to \CoreLibs\Language\Encoding
// Moved to \CoreLibs\Convert\MimeEncode
/**
* wrapper function for mb mime convert, for correct conversion with long strings
* @param string $string string to encode
* @param string $encoding target encoding
* @return string encoded string
* @deprecated Use \CoreLibs\Language\Encoding::__mbMimeEncode() instead
* @deprecated Use \CoreLibs\Convert\MimeEncode::__mbMimeEncode() instead
*/
public static function __mbMimeEncode(string $string, string $encoding): string
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::__mbMimeEncode()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::__mbMimeEncode($string, $encoding);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\MimeEncode::__mbMimeEncode()', E_USER_DEPRECATED);
return \CoreLibs\Convert\MimeEncode::__mbMimeEncode($string, $encoding);
}
// *** HUMAND BYTE READABLE CONVERT
@@ -1009,7 +1013,7 @@ class Basic
// *** ENCODING FUNCTIONS
// [!!! DEPRECATED !!!]
// Moved to \CoreLibs\Language\Encoding
// Moved to \CoreLibs\Check\Encoding and \CoreLibs\Convert\Encoding
/**
* test if a string can be safely convert between encodings. mostly utf8 to shift jis
@@ -1026,12 +1030,12 @@ class Basic
* @param string $from_encoding encoding of string to test
* @param string $to_encoding target encoding
* @return bool|array<mixed> false if no error or array with failed characters
* @deprecated use \CoreLibs\Language\Encoding::checkConvertEncoding() instead
* @deprecated use \CoreLibs\Check\Encoding::checkConvertEncoding() instead
*/
public function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Check\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
}
/**
@@ -1047,12 +1051,12 @@ class Basic
* check that the source is actually matching
* to what we sav the source is
* @return string encoding converted string
* @deprecated use \CoreLibs\Language\Encoding::convertEncoding() instead
* @deprecated use \CoreLibs\Convert\Encoding::convertEncoding() instead
*/
public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = '', bool $auto_check = true): string
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::convertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Encoding::convertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
}
// *** ENCODING FUNCTIONS END

View File

@@ -0,0 +1,117 @@
<?php
/*
* check if string is valid in target encoding
*/
declare(strict_types=1);
namespace CoreLibs\Check;
class Encoding
{
/** @var int<min, -1>|int<1, max>|string */
private static $mb_error_char = '';
/**
* set error char
*
* @param string|int|null $string The character to use to represent
* error chars
* "long" for long, "none" for none
* or a valid code point in int
* like 0x2234 (8756, ∴)
* default character is ? (63)
* if null is set then "none"
* @return void
*/
public static function setErrorChar($string): void
{
if (empty($string)) {
$string = 'none';
}
// if not special string or char but code point
if (in_array($string, ['none', 'long', 'entity'])) {
self::$mb_error_char = $string;
} else {
// always convert to char for internal use
self::$mb_error_char = \IntlChar::chr($string);
// if string convert to code point
if (is_string($string)) {
$string = \IntlChar::ord($string);
}
}
mb_substitute_character($string);
}
/**
* get the current set error character
*
* @param bool $return_substitute_func if set to true return the set
* character from the php function
* directly
* @return string|int Set error character
*/
public static function getErrorChar(bool $return_substitute_func = false)
{
// return mb_substitute_character();
if ($return_substitute_func === true) {
return mb_substitute_character();
} else {
return self::$mb_error_char;
}
}
/**
* test if a string can be safely convert between encodings.
* mostly utf8 to shift jis
* the default compare has a possibility of failure, especially with windows
* it is recommended to the following in the script which uses this method:
* mb_substitute_character(0x2234);
* $class->mb_error_char = '∴';
* if check to Shift JIS
* if check to ISO-2022-JP
* if check to ISO-2022-JP-MS
* set three dots (∴) as wrong character for correct convert error detect
* (this char is used, because it is one of the least used ones)
*
* @param string $string string to test
* @param string $from_encoding encoding of string to test
* @param string $to_encoding target encoding
* @return bool|array<string> false if no error or
* array with failed characters
*/
public static function checkConvertEncoding(
string $string,
string $from_encoding,
string $to_encoding
) {
// convert to target encoding and convert back
$temp = mb_convert_encoding($string, $to_encoding, $from_encoding);
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
// if string does not match anymore we have a convert problem
if ($string != $compare) {
$failed = [];
// go through each character and find the ones that do not match
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i++) {
$char = mb_substr($string, $i, 1, $from_encoding);
$r_char = mb_substr($compare, $i, 1, $from_encoding);
// the ord 194 is a hack to fix the IE7/IE8
// bug with line break and illegal character
if (
(($char != $r_char && (!self::$mb_error_char ||
in_array(self::$mb_error_char, ['none', 'long', 'entity']))) ||
($char != $r_char && $r_char == self::$mb_error_char && self::$mb_error_char)) &&
ord($char) != 194
) {
$failed[] = $char;
}
}
return $failed;
} else {
return false;
}
}
}
// __END__

View File

@@ -218,7 +218,8 @@ class ArrayHandler
continue;
}
foreach ($array as $key => $value) {
// if string or if key is assumed to be string do key match else add new entry
// if string or if key is assumed to be string do key match
// else add new entry
if (is_string($key) || $key_is_string === false) {
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
// $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string);

Some files were not shown because too many files have changed in this diff Show More