Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1203164d7e | ||
|
|
b82e08ba05 | ||
|
|
6dfb68a6da | ||
|
|
5b944cd12d | ||
|
|
65cac4c6e2 | ||
|
|
1c1ace58db | ||
|
|
16e12b5b8f | ||
|
|
73063d28b2 | ||
|
|
e80d8006a2 | ||
|
|
d648e4339a | ||
|
|
4b084f8785 | ||
|
|
d0d088b354 | ||
|
|
e0d42af1d2 | ||
|
|
c1d26f122e | ||
|
|
2c2826ac24 | ||
|
|
72f0810898 | ||
|
|
b69539b340 | ||
|
|
0b133133dd | ||
|
|
8fbe855fd4 | ||
|
|
d7410dfe78 | ||
|
|
5d36ac2f3e | ||
|
|
2e4ace1a39 |
@@ -1 +1 @@
|
||||
8.5.0
|
||||
9.0.8
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
VERSION=$(git tag --list | sort -V | tail -n1 | sed -e "s/^v//");
|
||||
file_last_published="${BASE_FOLDER}last.published";
|
||||
go_flag="$1";
|
||||
|
||||
if [ -z "${VERSION}" ]; then
|
||||
echo "Version must be set in the form x.y.z without any leading characters";
|
||||
@@ -35,6 +36,13 @@ source .env.deploy;
|
||||
cd -;
|
||||
set +o allexport;
|
||||
|
||||
if [ "${go_flag}" != "go" ]; then
|
||||
echo "No go flag given";
|
||||
echo "Would publish ${VERSION}";
|
||||
echo "[END]";
|
||||
exit;
|
||||
fi;
|
||||
|
||||
echo "[START]";
|
||||
# gitea
|
||||
if [ ! -z "${GITEA_URL_DL}" ] && [ ! -z "${GITEA_URL_PUSH}" ] &&
|
||||
|
||||
@@ -41,7 +41,8 @@ class EditBase
|
||||
/**
|
||||
* construct form generator
|
||||
*
|
||||
* @param array<mixed> $db_config db config array, mandatory
|
||||
* phpcs:ignore
|
||||
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config db config array, mandatory
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class, null auto set
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class, null auto set
|
||||
* @param \CoreLibs\ACL\Login $login login class for ACL settings
|
||||
|
||||
@@ -54,7 +54,8 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
* constructor for the array io class, set the
|
||||
* primary key name automatically (from array)
|
||||
*
|
||||
* @param array<mixed> $db_config db connection config
|
||||
* phpcs:ignore
|
||||
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config db connection config
|
||||
* @param array<mixed> $table_array table array config
|
||||
* @param string $table_name table name string
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
|
||||
585
src/DB/IO.php
585
src/DB/IO.php
File diff suppressed because it is too large
Load Diff
63
src/DB/Options/Convert.php
Normal file
63
src/DB/Options/Convert.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AUTOR: Clemens Schwaighofer
|
||||
* CREATED: 2023/6/9
|
||||
* DESCRIPTION:
|
||||
* DB Options for convert type
|
||||
*
|
||||
* off: no conversion (all string)
|
||||
* on: int/bool only
|
||||
* json: json/jsonb to array
|
||||
* numeric: any numeric or float to float
|
||||
* bytes: decode bytea to string
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\DB\Options;
|
||||
|
||||
enum Convert: int
|
||||
{
|
||||
/** do not convert */
|
||||
case off = 0;
|
||||
/** convert only int/bool */
|
||||
case on = 1;
|
||||
/** also convert json to php array */
|
||||
case json = 2;
|
||||
/** also convert any float/real/numeric to php float */
|
||||
case numeric = 4;
|
||||
/** also decode bytea string to php string */
|
||||
case bytea = 8;
|
||||
|
||||
/**
|
||||
* get internal name from string value
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @return self
|
||||
*/
|
||||
public static function fromName(string $name): self
|
||||
{
|
||||
return match ($name) {
|
||||
'Off', 'off', 'OFF', 'convert_off', 'CONVERT_OFF' => self::off,
|
||||
'On', 'on', 'ON', 'convert_on', 'CONVERT_ON' => self::on,
|
||||
'Json', 'json', 'JSON', 'convert_json', 'CONVERT_JSON' => self::json,
|
||||
'Numeric', 'numeric', 'NUMERIC', 'convert_numeric', 'CONVERT_NUMERIC' => self::numeric,
|
||||
'Bytea', 'bytea', 'BYTEA', 'convert_bytea', 'CONVERT_BYTEA' => self::bytea,
|
||||
default => self::off,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get internal name from int value
|
||||
*
|
||||
* @param int $value
|
||||
* @return self
|
||||
*/
|
||||
public static function fromValue(int $value): self
|
||||
{
|
||||
return self::from($value);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -34,29 +34,29 @@ class Support
|
||||
}
|
||||
|
||||
/**
|
||||
* prints a html formatted (pre) array
|
||||
* prints a html formatted (pre) data
|
||||
*
|
||||
* @param array<mixed> $array any array
|
||||
* @param bool $no_html default add <pre>
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
* @param mixed $data any data
|
||||
* @param bool $no_html default add <pre>
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
*/
|
||||
public static function printAr(array $array, bool $no_html = false): string
|
||||
public static function printAr(mixed $data, bool $no_html = false): string
|
||||
{
|
||||
return $no_html ?
|
||||
print_r($array, true) :
|
||||
'<pre>' . print_r($array, true) . '</pre>';
|
||||
print_r($data, true) :
|
||||
'<pre>' . print_r($data, true) . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* alternate name for printAr function
|
||||
*
|
||||
* @param array<mixed> $array any array
|
||||
* @param bool $no_html default add <pre>
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
* @param mixed $data any array
|
||||
* @param bool $no_html default add <pre>
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
*/
|
||||
public static function printArray(array $array, bool $no_html = false): string
|
||||
public static function printArray(mixed $data, bool $no_html = false): string
|
||||
{
|
||||
return self::printAr($array, $no_html);
|
||||
return self::printAr($data, $no_html);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,12 +65,12 @@ class Support
|
||||
* Do not use this without using it in a string in debug function
|
||||
* Note: for full data debug dumps use Support::dumpVar()
|
||||
*
|
||||
* @param array<mixed> $a Array to format
|
||||
* @return string print_r formated
|
||||
* @param mixed $data Data to print
|
||||
* @return string print_r formated
|
||||
*/
|
||||
public static function prAr(array $a): string
|
||||
public static function prAr(mixed $data): string
|
||||
{
|
||||
return self::printAr($a, true);
|
||||
return self::printAr($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +177,6 @@ class Support
|
||||
$caller_level = 1;
|
||||
$caller_list = self::getCallerMethodList();
|
||||
if ($caller_list[0] == 'dV') {
|
||||
echo "Raise caller level<br>: " . $caller_list[0] . "<br>";
|
||||
$caller_level = 2;
|
||||
}
|
||||
// we need to strip the string in <small></small that is
|
||||
|
||||
@@ -213,7 +213,7 @@ class Logging
|
||||
$settings['mandatory'] && !isset($options[$name]) &&
|
||||
empty($settings['alias'])
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
'Missing mandatory option: "' . $name . '"',
|
||||
E_USER_WARNING
|
||||
);
|
||||
@@ -230,7 +230,7 @@ class Logging
|
||||
switch ($settings['type']) {
|
||||
case 'bool':
|
||||
if (!is_bool($this->options[$name])) {
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
'Option: "' . $name . '" is not of type bool',
|
||||
E_USER_ERROR
|
||||
);
|
||||
@@ -238,7 +238,7 @@ class Logging
|
||||
break;
|
||||
case 'string':
|
||||
if (!is_string($this->options[$name])) {
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
'Option: "' . $name . '" is not of type string',
|
||||
E_USER_ERROR
|
||||
);
|
||||
@@ -249,7 +249,7 @@ class Logging
|
||||
empty($settings['type_info']) ||
|
||||
!$this->options[$name] instanceof $settings['type_info']
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
'Option: "' . $name . '" is not of instance '
|
||||
. ($settings['type_info'] ?? 'NO INSTANCE DEFINED'),
|
||||
E_USER_ERROR
|
||||
@@ -407,13 +407,6 @@ class Logging
|
||||
}
|
||||
$this->setLogFlag($log_flag_key);
|
||||
}
|
||||
// init per run uid
|
||||
if ($this->getLogFlag(Flag::per_run)) {
|
||||
$this->setLogUniqueId();
|
||||
} elseif ($this->getLogFlag(Flag::per_date)) {
|
||||
// init file date
|
||||
$this->log_file_date = date('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -535,7 +528,7 @@ class Logging
|
||||
* Prepare the log message with all needed info blocks:
|
||||
* [timestamp] [host name] [file path + file] [running uid] {class} <debug level/group id> - message
|
||||
*
|
||||
* @param string $level_str Log level we will write to
|
||||
* @param Level $level Log level we will write to
|
||||
* @param string|Stringable $message The message to write
|
||||
* @param mixed[] $context Any additional info we want to attach in any format
|
||||
* @param string $group_id A group id, only used in DEBUG level,
|
||||
@@ -543,11 +536,15 @@ class Logging
|
||||
* @return string
|
||||
*/
|
||||
private function prepareLog(
|
||||
string $level_str,
|
||||
Level $level,
|
||||
string|\Stringable $message,
|
||||
array $context = [],
|
||||
string $group_id = '',
|
||||
): string {
|
||||
// only prepare if to write log level is in set log level
|
||||
if (!$this->checkLogLevel($level)) {
|
||||
return '';
|
||||
}
|
||||
// file + line: call not this but one before (the one that calls this)
|
||||
$file_line = Support::getCallerFileLine(2) ??
|
||||
System::getPageName(System::FULL_PATH);
|
||||
@@ -562,7 +559,7 @@ class Logging
|
||||
$timestamp = Support::printTime();
|
||||
|
||||
// if group id is empty replace it with current level
|
||||
$group_str = $level_str;
|
||||
$group_str = $level->getName();
|
||||
if (!empty($group_id)) {
|
||||
$group_str .= ':' . $group_id;
|
||||
}
|
||||
@@ -675,9 +672,11 @@ class Logging
|
||||
*
|
||||
* @return bool True, we are at debug level
|
||||
*/
|
||||
public function getJsDebug(): bool
|
||||
public function loggingLevelIsDebug(): bool
|
||||
{
|
||||
return $this->log_level === Level::Debug ? true : false;
|
||||
return $this->getLoggingLevel()->includes(
|
||||
Level::Debug
|
||||
);
|
||||
}
|
||||
|
||||
// log file id set (file name prefix)
|
||||
@@ -774,6 +773,13 @@ class Logging
|
||||
public function setLogFlag(Flag $flag): void
|
||||
{
|
||||
$this->log_flags |= $flag->value;
|
||||
// init per run uid
|
||||
if ($this->getLogFlag(Flag::per_run)) {
|
||||
$this->setLogUniqueId();
|
||||
} elseif ($this->getLogFlag(Flag::per_date)) {
|
||||
// init file date
|
||||
$this->setLogDate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -904,6 +910,42 @@ class Logging
|
||||
// MAIN CALLS
|
||||
// *********************************************************************
|
||||
|
||||
/**
|
||||
* Commong log interface
|
||||
*
|
||||
* extended with group_id, prefix that are ONLY used for debug level
|
||||
*
|
||||
* @param Level $level
|
||||
* @param string|\Stringable $message
|
||||
* @param mixed[] $context
|
||||
* @param string $group_id
|
||||
* @param string $prefix
|
||||
* @return bool
|
||||
*/
|
||||
public function log(
|
||||
Level $level,
|
||||
string|\Stringable $message,
|
||||
array $context = [],
|
||||
string $group_id = '',
|
||||
string $prefix = '',
|
||||
): bool {
|
||||
// if we are not debug, ignore group_id and prefix
|
||||
if ($level != Level::Debug) {
|
||||
$group_id = '';
|
||||
$prefix = '';
|
||||
}
|
||||
return $this->writeErrorMsg(
|
||||
$level,
|
||||
$this->prepareLog(
|
||||
$level,
|
||||
$prefix . $message,
|
||||
$context,
|
||||
$group_id
|
||||
),
|
||||
$group_id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* DEBUG: 100
|
||||
*
|
||||
@@ -911,23 +953,23 @@ class Logging
|
||||
*
|
||||
* @param string $group_id id for error message, groups messages together
|
||||
* @param string|Stringable $message the actual error message
|
||||
* @param mixed[] $context
|
||||
* @param string $prefix Attach some block before $string.
|
||||
* Will not be stripped even
|
||||
* when strip is true
|
||||
* if strip is false, recommended to add that to $string
|
||||
* @param mixed[] $context
|
||||
* @return bool True if logged, false if not logged
|
||||
*/
|
||||
public function debug(
|
||||
string $group_id,
|
||||
string|\Stringable $message,
|
||||
string $prefix = '',
|
||||
array $context = []
|
||||
array $context = [],
|
||||
string $prefix = ''
|
||||
): bool {
|
||||
return $this->writeErrorMsg(
|
||||
$this->log_level,
|
||||
Level::Debug,
|
||||
$this->prepareLog(
|
||||
Level::Debug->getName(),
|
||||
Level::Debug,
|
||||
$prefix . $message,
|
||||
$context,
|
||||
$group_id
|
||||
@@ -948,7 +990,7 @@ class Logging
|
||||
return $this->writeErrorMsg(
|
||||
Level::Info,
|
||||
$this->prepareLog(
|
||||
Level::Info->getName(),
|
||||
Level::Info,
|
||||
$message,
|
||||
$context,
|
||||
)
|
||||
@@ -967,7 +1009,7 @@ class Logging
|
||||
return $this->writeErrorMsg(
|
||||
Level::Notice,
|
||||
$this->prepareLog(
|
||||
Level::Notice->getName(),
|
||||
Level::Notice,
|
||||
$message,
|
||||
$context,
|
||||
)
|
||||
@@ -986,7 +1028,7 @@ class Logging
|
||||
return $this->writeErrorMsg(
|
||||
Level::Warning,
|
||||
$this->prepareLog(
|
||||
Level::Warning->getName(),
|
||||
Level::Warning,
|
||||
$message,
|
||||
$context,
|
||||
)
|
||||
@@ -1005,7 +1047,7 @@ class Logging
|
||||
return $this->writeErrorMsg(
|
||||
Level::Error,
|
||||
$this->prepareLog(
|
||||
Level::Error->getName(),
|
||||
Level::Error,
|
||||
$message,
|
||||
$context,
|
||||
)
|
||||
@@ -1024,7 +1066,7 @@ class Logging
|
||||
return $this->writeErrorMsg(
|
||||
Level::Critical,
|
||||
$this->prepareLog(
|
||||
Level::Critical->getName(),
|
||||
Level::Critical,
|
||||
$message,
|
||||
$context,
|
||||
)
|
||||
@@ -1043,7 +1085,7 @@ class Logging
|
||||
return $this->writeErrorMsg(
|
||||
Level::Alert,
|
||||
$this->prepareLog(
|
||||
Level::Alert->getName(),
|
||||
Level::Alert,
|
||||
$message,
|
||||
$context,
|
||||
)
|
||||
@@ -1062,7 +1104,7 @@ class Logging
|
||||
return $this->writeErrorMsg(
|
||||
Level::Emergency,
|
||||
$this->prepareLog(
|
||||
Level::Emergency->getName(),
|
||||
Level::Emergency,
|
||||
$message,
|
||||
$context,
|
||||
)
|
||||
@@ -1080,12 +1122,12 @@ class Logging
|
||||
* But this does not wrap it in <pre></pre>
|
||||
* Do not use this without using it in a string in debug function
|
||||
*
|
||||
* @param array<mixed> $a Array to format
|
||||
* @return string print_r formated
|
||||
* @param mixed $data Data to format
|
||||
* @return string print_r formated
|
||||
*/
|
||||
public function prAr(array $a): string
|
||||
public function prAr(mixed $data): string
|
||||
{
|
||||
return Support::printArray($a, true);
|
||||
return Support::printArray($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -232,13 +232,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
/** @var string */
|
||||
public string $col_name; // the name of the columen (before _<type>) [used for order button]
|
||||
/** @var int */
|
||||
public int $yes; // the yes flag that triggers the template to show ALL and not only new/load
|
||||
public int $yes = 0; // the yes flag that triggers the template to show ALL and not only new/load
|
||||
/** @var string */
|
||||
public string $msg; // the error msg
|
||||
public string $msg = ''; // the error msg
|
||||
/** @var int */
|
||||
public int $error; // the error flag set for printing red error msg
|
||||
public int $error = 0; // the error flag set for printing red error msg
|
||||
/** @var int */
|
||||
public int $warning; // warning flag, for information (saved, loaded, etc)
|
||||
public int $warning = 0; // warning flag, for information (saved, loaded, etc)
|
||||
/** @var string */
|
||||
public string $archive_pk_name; // the pk name for the load select form
|
||||
/** @var string */
|
||||
@@ -282,7 +282,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
public array $login_acl = [];
|
||||
// layout publics
|
||||
/** @var int */
|
||||
public int $table_width;
|
||||
public int $table_width = 0;
|
||||
// internal lang & encoding vars
|
||||
/** @var string */
|
||||
public string $lang_dir = '';
|
||||
@@ -308,7 +308,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
/**
|
||||
* construct form generator
|
||||
*
|
||||
* @param array<mixed> $db_config db config array, mandatory
|
||||
* phpcs:ignore
|
||||
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config db config array, mandatory
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param array<string,mixed> $login_acl Login ACL array,
|
||||
|
||||
@@ -36,6 +36,7 @@ class Image
|
||||
): string|false {
|
||||
// get image type flags
|
||||
$image_types = [
|
||||
0 => 'UNKOWN-IMAGE',
|
||||
1 => 'gif',
|
||||
2 => 'jpg',
|
||||
3 => 'png'
|
||||
@@ -69,7 +70,7 @@ class Image
|
||||
}
|
||||
// does this picture exist and is it a picture
|
||||
if (file_exists($filename) && is_file($filename)) {
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [];
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, 0];
|
||||
$convert_prefix = '';
|
||||
$create_file = false;
|
||||
$delete_filename = '';
|
||||
@@ -98,7 +99,7 @@ class Image
|
||||
if (!is_file($filename)) {
|
||||
$filename .= '-0';
|
||||
}
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [];
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, 0];
|
||||
}
|
||||
// if no size given, set size to original
|
||||
if (!$size_x || $size_x < 1) {
|
||||
@@ -117,7 +118,7 @@ class Image
|
||||
$status = exec($convert_string, $output, $return);
|
||||
// get the size of the converted data, if converted
|
||||
if (is_file($thumbnail)) {
|
||||
[$width, $height, $type] = getimagesize($thumbnail) ?: [];
|
||||
[$width, $height, $type] = getimagesize($thumbnail) ?: [0, 0, 0];
|
||||
}
|
||||
}
|
||||
if ($height > $size_y) {
|
||||
@@ -217,7 +218,7 @@ class Image
|
||||
return $thumbnail;
|
||||
}
|
||||
// $this->debug('IMAGE PREPARE', "FILENAME OK, THUMB WIDTH/HEIGHT OK");
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [];
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [0, 0, null];
|
||||
$thumbnail_write_path = null;
|
||||
$thumbnail_web_path = null;
|
||||
// path set first
|
||||
@@ -447,7 +448,7 @@ class Image
|
||||
if (!function_exists('exif_read_data') || !is_writeable($filename)) {
|
||||
return;
|
||||
}
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [];
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [0, 0, null];
|
||||
// add @ to avoid "file not supported error"
|
||||
$exif = @exif_read_data($filename);
|
||||
$orientation = null;
|
||||
|
||||
@@ -77,79 +77,79 @@ class SmartyExtend extends \Smarty
|
||||
public string $COMPILE_ID = '';
|
||||
// template vars
|
||||
/** @var string */
|
||||
public string $MASTER_TEMPLATE_NAME;
|
||||
public string $MASTER_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public string $PAGE_FILE_NAME;
|
||||
public string $PAGE_FILE_NAME = '';
|
||||
/** @var string */
|
||||
public string $CONTENT_INCLUDE;
|
||||
public string $CONTENT_INCLUDE = '';
|
||||
/** @var string */
|
||||
public string $FORM_NAME;
|
||||
public string $FORM_NAME = '';
|
||||
/** @var string */
|
||||
public string $FORM_ACTION;
|
||||
public string $FORM_ACTION = '';
|
||||
/** @var string */
|
||||
public string $L_TITLE;
|
||||
public string $L_TITLE = '';
|
||||
/** @var string|int */
|
||||
public string|int $PAGE_WIDTH;
|
||||
// smarty include/set var
|
||||
/** @var string */
|
||||
public string $TEMPLATE_PATH;
|
||||
public string $TEMPLATE_PATH = '';
|
||||
/** @var string */
|
||||
public string $TEMPLATE_NAME;
|
||||
public string $TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public string $INC_TEMPLATE_NAME;
|
||||
public string $INC_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public string $JS_TEMPLATE_NAME;
|
||||
public string $JS_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public string $CSS_TEMPLATE_NAME;
|
||||
public string $CSS_TEMPLATE_NAME = '';
|
||||
/** @var string|null */
|
||||
public string|null $TEMPLATE_TRANSLATE;
|
||||
/** @var string|null */
|
||||
public string|null $JS_TRANSLATE;
|
||||
// core group
|
||||
/** @var string */
|
||||
public string $JS_CORE_TEMPLATE_NAME;
|
||||
public string $JS_CORE_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public string $CSS_CORE_TEMPLATE_NAME;
|
||||
public string $CSS_CORE_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public string $JS_CORE_INCLUDE;
|
||||
public string $JS_CORE_INCLUDE = '';
|
||||
/** @var string */
|
||||
public string $CSS_CORE_INCLUDE;
|
||||
public string $CSS_CORE_INCLUDE = '';
|
||||
// local names
|
||||
/** @var string */
|
||||
public string $JS_SPECIAL_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public string $CSS_SPECIAL_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public string $JS_INCLUDE;
|
||||
public string $JS_INCLUDE = '';
|
||||
/** @var string */
|
||||
public string $CSS_INCLUDE;
|
||||
public string $CSS_INCLUDE = '';
|
||||
/** @var string */
|
||||
public string $JS_SPECIAL_INCLUDE;
|
||||
public string $JS_SPECIAL_INCLUDE = '';
|
||||
/** @var string */
|
||||
public string $CSS_SPECIAL_INCLUDE;
|
||||
public string $CSS_SPECIAL_INCLUDE = '';
|
||||
/** @var string */
|
||||
public string $ADMIN_JAVASCRIPT;
|
||||
public string $ADMIN_JAVASCRIPT = '';
|
||||
/** @var string */
|
||||
public string $ADMIN_STYLESHEET;
|
||||
public string $ADMIN_STYLESHEET = '';
|
||||
/** @var string */
|
||||
public string $FRONTEND_JAVASCRIPT;
|
||||
public string $FRONTEND_JAVASCRIPT = '';
|
||||
/** @var string */
|
||||
public string $FRONTEND_STYLESHEET;
|
||||
public string $FRONTEND_STYLESHEET = '';
|
||||
// other smarty folder vars
|
||||
/** @var string */
|
||||
public string $INCLUDES;
|
||||
public string $INCLUDES = '';
|
||||
/** @var string */
|
||||
public string $JAVASCRIPT;
|
||||
public string $JAVASCRIPT = '';
|
||||
/** @var string */
|
||||
public string $CSS;
|
||||
public string $CSS = '';
|
||||
/** @var string */
|
||||
public string $FONT;
|
||||
public string $FONT = '';
|
||||
/** @var string */
|
||||
public string $PICTURES;
|
||||
public string $PICTURES = '';
|
||||
/** @var string */
|
||||
public string $CACHE_PICTURES;
|
||||
public string $CACHE_PICTURES = '';
|
||||
/** @var string */
|
||||
public string $CACHE_PICTURES_ROOT;
|
||||
public string $CACHE_PICTURES_ROOT = '';
|
||||
|
||||
// constructor class, just sets the language stuff
|
||||
/**
|
||||
@@ -373,7 +373,7 @@ class SmartyExtend extends \Smarty
|
||||
// check for template include
|
||||
if (
|
||||
$this->USE_INCLUDE_TEMPLATE === true &&
|
||||
!$this->TEMPLATE_NAME
|
||||
empty($this->TEMPLATE_NAME)
|
||||
) {
|
||||
$this->TEMPLATE_NAME = $this->CONTENT_INCLUDE;
|
||||
// add to cache & compile id
|
||||
@@ -390,7 +390,7 @@ class SmartyExtend extends \Smarty
|
||||
exit('MASTER TEMPLATE: ' . $this->MASTER_TEMPLATE_NAME . ' could not be found');
|
||||
}
|
||||
if (
|
||||
$this->TEMPLATE_NAME &&
|
||||
!empty($this->TEMPLATE_NAME) &&
|
||||
!file_exists($this->getTemplateDir()[0] . DIRECTORY_SEPARATOR . $this->TEMPLATE_NAME)
|
||||
) {
|
||||
exit('INCLUDE TEMPLATE: ' . $this->TEMPLATE_NAME . ' could not be found');
|
||||
@@ -418,7 +418,12 @@ class SmartyExtend extends \Smarty
|
||||
}
|
||||
}
|
||||
// if we can't find it, dump it
|
||||
if (!file_exists($this->getTemplateDir()[0] . DIRECTORY_SEPARATOR . $this->TEMPLATE_TRANSLATE)) {
|
||||
if (
|
||||
!file_exists(
|
||||
$this->getTemplateDir()[0] . DIRECTORY_SEPARATOR
|
||||
. $this->TEMPLATE_TRANSLATE
|
||||
)
|
||||
) {
|
||||
$this->TEMPLATE_TRANSLATE = null;
|
||||
}
|
||||
if (empty($this->JS_TRANSLATE)) {
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use CoreLibs\Logging\Logger\Level;
|
||||
use CoreLibs\DB\Options\Convert;
|
||||
|
||||
/**
|
||||
* Test class for DB\IO + DB\SQL\PgSQL
|
||||
@@ -59,20 +61,6 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => true,
|
||||
],
|
||||
// same as valid, but db debug is off
|
||||
'valid_debug_false' => [
|
||||
'db_name' => 'corelibs_db_io_test',
|
||||
'db_user' => 'corelibs_db_io_test',
|
||||
'db_pass' => 'corelibs_db_io_test',
|
||||
'db_host' => 'localhost',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => 'public',
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => false,
|
||||
],
|
||||
// same as valid, but encoding is set
|
||||
'valid_with_encoding_utf8' => [
|
||||
@@ -85,7 +73,6 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => 'UTF-8',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => true,
|
||||
],
|
||||
// valid with no schema set
|
||||
'valid_no_schema' => [
|
||||
@@ -98,7 +85,6 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => true,
|
||||
],
|
||||
// invalid (missing db name)
|
||||
'invalid' => [
|
||||
@@ -111,7 +97,6 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => true,
|
||||
],
|
||||
];
|
||||
private static $log;
|
||||
@@ -137,6 +122,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'log_file_id' => 'CoreLibs-DB-IO-Test',
|
||||
]);
|
||||
// will be true, default logging is true
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config['valid'],
|
||||
self::$log
|
||||
@@ -534,6 +520,9 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
*/
|
||||
public function debugSetProvider(): array
|
||||
{
|
||||
// 0: db connecdtion
|
||||
// 1: override log flag, null for default
|
||||
// 2: set flag
|
||||
return [
|
||||
'default debug set' => [
|
||||
// what base connection
|
||||
@@ -541,11 +530,6 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
// actions (set)
|
||||
null,
|
||||
// set exepected
|
||||
self::$db_config['valid']['db_debug'],
|
||||
],
|
||||
'set debug to true' => [
|
||||
'valid_debug_false',
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'set debug to false' => [
|
||||
@@ -556,99 +540,46 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test set for toggleDEbug
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function debugToggleProvider(): array
|
||||
{
|
||||
return [
|
||||
'default debug set' => [
|
||||
// what base connection
|
||||
'valid',
|
||||
// actions
|
||||
null,
|
||||
// toggle is inverse
|
||||
self::$db_config['valid']['db_debug'] ? false : true,
|
||||
],
|
||||
'toggle debug to true' => [
|
||||
'valid_debug_false',
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'toggle debug to false' => [
|
||||
'valid',
|
||||
false,
|
||||
false,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dbSetDbug, dbGetDebug
|
||||
*
|
||||
* @covers ::dbGetDbug
|
||||
* @covers ::dbSetDebug
|
||||
* @dataProvider debugSetProvider
|
||||
* @testdox Setting debug $set will be $expected [$_dataName]
|
||||
* @testdox Set and Get Debug flag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDbSetDebug(
|
||||
string $connection,
|
||||
?bool $set,
|
||||
bool $expected
|
||||
): void {
|
||||
public function testDbSetDebug(): void
|
||||
{
|
||||
$connection = 'valid';
|
||||
// default set, expect true
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config[$connection],
|
||||
self::$log
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set === null ?
|
||||
$db->dbSetDebug() :
|
||||
$db->dbSetDebug($set)
|
||||
$this->assertTrue(
|
||||
$db->dbGetDebug()
|
||||
);
|
||||
// must always match
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
// switch off
|
||||
$db->dbSetDebug(false);
|
||||
$this->assertFalse(
|
||||
$db->dbGetDebug()
|
||||
);
|
||||
$db->dbClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dbToggleDebug, dbGetDebug
|
||||
*
|
||||
* @covers ::dbGetDbug
|
||||
* @covers ::dbSetDebug
|
||||
* @dataProvider debugToggleProvider
|
||||
* @testdox Toggle debug $toggle will be $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDbToggleDebug(
|
||||
string $connection,
|
||||
?bool $toggle,
|
||||
bool $expected
|
||||
): void {
|
||||
// second conenction with log set NOT debug
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'log_file_id' => 'CoreLibs-DB-IO-Test',
|
||||
'log_level' => \CoreLibs\Logging\Logger\Level::Notice,
|
||||
]);
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config[$connection],
|
||||
self::$log
|
||||
$log
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$toggle === null ?
|
||||
$db->dbToggleDebug() :
|
||||
$db->dbToggleDebug($toggle)
|
||||
);
|
||||
// must always match
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->assertFalse(
|
||||
$db->dbGetDebug()
|
||||
);
|
||||
$db->dbClose();
|
||||
}
|
||||
|
||||
// - set max query call sets
|
||||
@@ -806,7 +737,6 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
'host' => 'db_host',
|
||||
'port' => 'db_port',
|
||||
'ssl' => 'db_ssl',
|
||||
'debug' => 'db_debug',
|
||||
'password' => '***',
|
||||
] as $read => $compare
|
||||
) {
|
||||
@@ -4628,6 +4558,176 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
$db->dbClose();
|
||||
}
|
||||
|
||||
// testing auto convert
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::dbSetConvertFlag
|
||||
* @testdox Check convert type works
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConvertType(): void
|
||||
{
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config['valid'],
|
||||
self::$log
|
||||
);
|
||||
$bytea_data = $db->dbEscapeBytea(
|
||||
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'CoreLibsDBIOTest.php') ?: ''
|
||||
);
|
||||
$query_insert = <<<SQL
|
||||
INSERT INTO table_with_primary_key (
|
||||
uid,
|
||||
row_int, row_numeric, row_varchar, row_varchar_literal,
|
||||
row_json, row_jsonb, row_bytea, row_timestamp,
|
||||
row_date, row_interval, row_array_int, row_array_varchar
|
||||
) VALUES (
|
||||
$1,
|
||||
$2, $3, $4, $5,
|
||||
$6, $7, $8, $9,
|
||||
$10, $11, $12, $13
|
||||
)
|
||||
SQL;
|
||||
$db->dbExecParams(
|
||||
$query_insert,
|
||||
[
|
||||
'CONVERT_TYPE_TEST',
|
||||
1, 1.5, 'varchar', 'varchar literla',
|
||||
json_encode(['json', 'a', 1, true, 'sub' => ['b', 'c']]),
|
||||
json_encode(['jsonb', 'a', 1, true, 'sub' => ['b', 'c']]),
|
||||
$bytea_data, date('Y-m-d H:i:s'), date('Y-m-d'), date('H:m:s'),
|
||||
'{1,2,3}', '{"a","b","c"}'
|
||||
]
|
||||
);
|
||||
$type_layout = [
|
||||
'uid' => 'string',
|
||||
'row_int' => 'int',
|
||||
'row_numeric' => 'float',
|
||||
'row_varchar' => 'string',
|
||||
'row_varchar_literal' => 'string',
|
||||
'row_json' => 'json',
|
||||
'row_jsonb' => 'json',
|
||||
'row_bytea' => 'bytea',
|
||||
'row_timestamp' => 'string',
|
||||
'row_date' => 'string',
|
||||
'row_interval' => 'string',
|
||||
'row_array_int' => 'string',
|
||||
'row_array_varchar' => 'string'
|
||||
];
|
||||
$query_select = <<<SQL
|
||||
SELECT
|
||||
uid,
|
||||
row_int, row_numeric, row_varchar, row_varchar_literal,
|
||||
row_json, row_jsonb, row_bytea, row_timestamp,
|
||||
row_date, row_interval, row_array_int, row_array_varchar
|
||||
FROM
|
||||
table_with_primary_key
|
||||
WHERE
|
||||
uid = $1
|
||||
SQL;
|
||||
$res = $db->dbReturnRowParams($query_select, ['CONVERT_TYPE_TEST']);
|
||||
// all hast to be string
|
||||
foreach ($res as $key => $value) {
|
||||
$this->assertIsString($value, 'Aseert string for column: ' . $key);
|
||||
}
|
||||
// convert base only
|
||||
$db->dbSetConvertFlag(Convert::on);
|
||||
$res = $db->dbReturnRowParams($query_select, ['CONVERT_TYPE_TEST']);
|
||||
foreach ($res as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
$name = $db->dbGetFieldName($key);
|
||||
} else {
|
||||
$name = $key;
|
||||
}
|
||||
switch ($type_layout[$name]) {
|
||||
case 'int':
|
||||
$this->assertIsInt($value, 'Aseert int for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
default:
|
||||
$this->assertIsString($value, 'Aseert string for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$db->dbSetConvertFlag(Convert::numeric);
|
||||
$res = $db->dbReturnRowParams($query_select, ['CONVERT_TYPE_TEST']);
|
||||
foreach ($res as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
$name = $db->dbGetFieldName($key);
|
||||
} else {
|
||||
$name = $key;
|
||||
}
|
||||
switch ($type_layout[$name]) {
|
||||
case 'int':
|
||||
$this->assertIsInt($value, 'Aseert int for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
case 'float':
|
||||
$this->assertIsFloat($value, 'Aseert float for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
default:
|
||||
$this->assertIsString($value, 'Aseert string for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$db->dbSetConvertFlag(Convert::json);
|
||||
$res = $db->dbReturnRowParams($query_select, ['CONVERT_TYPE_TEST']);
|
||||
foreach ($res as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
$name = $db->dbGetFieldName($key);
|
||||
} else {
|
||||
$name = $key;
|
||||
}
|
||||
switch ($type_layout[$name]) {
|
||||
case 'int':
|
||||
$this->assertIsInt($value, 'Aseert int for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
case 'float':
|
||||
$this->assertIsFloat($value, 'Aseert float for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
case 'json':
|
||||
case 'jsonb':
|
||||
$this->assertIsArray($value, 'Aseert array for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
default:
|
||||
$this->assertIsString($value, 'Aseert string for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$db->dbSetConvertFlag(Convert::bytea);
|
||||
$res = $db->dbReturnRowParams($query_select, ['CONVERT_TYPE_TEST']);
|
||||
foreach ($res as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
$name = $db->dbGetFieldName($key);
|
||||
} else {
|
||||
$name = $key;
|
||||
}
|
||||
switch ($type_layout[$name]) {
|
||||
case 'int':
|
||||
$this->assertIsInt($value, 'Aseert int for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
case 'float':
|
||||
$this->assertIsFloat($value, 'Aseert float for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
case 'json':
|
||||
case 'jsonb':
|
||||
$this->assertIsArray($value, 'Aseert array for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
case 'bytea':
|
||||
// for hex types it must not start with \x
|
||||
$this->assertStringStartsNotWith(
|
||||
'\x',
|
||||
$value,
|
||||
'Aseert bytes not starts with \x for column: ' . $key . '/' . $name
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$this->assertIsString($value, 'Aseert string for column: ' . $key . '/' . $name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// - internal read data (post exec)
|
||||
// dbGetNumRows, dbGetNumFields, dbGetFieldNames,
|
||||
// dbGetQuery, dbGetQueryHash, dbGetDbh
|
||||
@@ -4659,7 +4759,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
. "('Foxtrott', 'Tango', 789, '1982-10-15') ",
|
||||
null,
|
||||
//
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
['row_varchar', 'row_varchar_literal', 'row_int', 'row_date'],
|
||||
['varchar', 'varchar', 'int4', 'date'],
|
||||
@@ -4776,9 +4876,16 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
$db->dbExecParams($query, $params);
|
||||
}
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'PgSql\Result',
|
||||
$db->dbGetCursor(),
|
||||
'Failed assert dbGetCursor'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$compare_query ?? $query,
|
||||
$db->dbGetQuery()
|
||||
$db->dbGetQuery(),
|
||||
'Failed assert dbGetQuery'
|
||||
);
|
||||
$this->assertEquals(
|
||||
// perhaps move that somewhere else?
|
||||
@@ -4791,7 +4898,8 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
($params === null ?
|
||||
$db->dbGetQueryHash($query) :
|
||||
$db->dbGetQueryHash($query, $params)
|
||||
)
|
||||
),
|
||||
'Failed assertdbGetQueryHash '
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_rows,
|
||||
@@ -4813,6 +4921,35 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
$db->dbGetFieldTypes(),
|
||||
'Failed assert dbGetFieldTypes'
|
||||
);
|
||||
// check FieldNameTypes matches
|
||||
$this->assertEquals(
|
||||
array_combine(
|
||||
$expected_col_names,
|
||||
$expected_col_types
|
||||
),
|
||||
$db->dbGetFieldNameTypes(),
|
||||
'Failed assert dbGetFieldNameTypes'
|
||||
);
|
||||
// check pos matches name
|
||||
// name matches type
|
||||
// pos matches type
|
||||
foreach ($expected_col_names as $pos => $name) {
|
||||
$this->assertEquals(
|
||||
$name,
|
||||
$db->dbGetFieldName($pos),
|
||||
'Failed assert dbGetFieldName: ' . $pos . ' => ' . $name
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_col_types[$pos],
|
||||
$db->dbGetFieldType($name),
|
||||
'Failed assert dbGetFieldType: ' . $name . ' => ' . $expected_col_types[$pos]
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_col_types[$pos],
|
||||
$db->dbGetFieldType($pos),
|
||||
'Failed assert dbGetFieldType: ' . $pos . ' => ' . $expected_col_types[$pos]
|
||||
);
|
||||
}
|
||||
$dbh = $db->dbGetDbh();
|
||||
$this->assertIsObject(
|
||||
$dbh
|
||||
|
||||
@@ -460,16 +460,18 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @cover ::getCallerFileLine
|
||||
* @testWith ["/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/www/vendor/phpunit/phpunit/src/Framework/TestCase.php:1608"]
|
||||
* @testdox getCallerFileLine check if it returns $expected [$_dataName]
|
||||
* @testWith ["vendor/phpunit/phpunit/src/Framework/TestCase.php:"]
|
||||
* @testdox getCallerFileLine check based on regex /[\w\-\/]/vendor/phpunit/phpunit/src/Framework/TestCase.php:\d+ [$_dataName]
|
||||
*
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCallerFileLine(string $expected): void
|
||||
public function testGetCallerFileLine(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
// regex prefix with path "/../" and then fixed vendor + \d+
|
||||
$regex = "/^\/[\w\-\/]+\/vendor\/phpunit\/phpunit\/src\/Framework\/TestCase.php:\d+$/";
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
Support::getCallerFileLine()
|
||||
);
|
||||
}
|
||||
@@ -518,11 +520,17 @@ final class CoreLibsDebugSupportTest extends TestCase
|
||||
break;
|
||||
case 11:
|
||||
// add one "run" before "runBare"
|
||||
// array_splice(
|
||||
// $expected,
|
||||
// 7,
|
||||
// 0,
|
||||
// ['run']
|
||||
// );
|
||||
array_splice(
|
||||
$expected,
|
||||
7,
|
||||
0,
|
||||
['run']
|
||||
0,
|
||||
['include']
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
|
||||
@@ -20,10 +20,15 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
private const LOG_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;
|
||||
private const REGEX_BASE = "\[[\d\-\s\.:]+\]\s{1}" // date
|
||||
. "\[[\w\.]+(:\d+)?\]\s{1}" // host:port
|
||||
. "\[[\w+\.\/]+:\d+\]\s{1}" // folder/file
|
||||
. "\[[\w\-\.\/]+:\d+\]\s{1}" // folder/file
|
||||
. "\[\w+\]\s{1}" // run id
|
||||
. "{[\w\\\\]+(::\w+)?}\s{1}"; // class
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
array_map('unlink', glob(self::LOG_FOLDER . '*.log'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test set for options BASIC
|
||||
*
|
||||
@@ -217,14 +222,14 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
|
||||
// setLoggingLevel
|
||||
// getLoggingLevel
|
||||
// getJsDebug
|
||||
// loggingLevelIsDebug
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLoggingLevel
|
||||
* @covers ::getLoggingLevel
|
||||
* @covers ::getJsDebug
|
||||
* @covers ::loggingLevelIsDebug
|
||||
* @testdox setLoggingLevel set/get checks
|
||||
*
|
||||
* @return void
|
||||
@@ -242,7 +247,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertFalse(
|
||||
$log->getJsDebug()
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// not set, should be debug]
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
@@ -254,7 +259,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertTrue(
|
||||
$log->getJsDebug()
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// invalid, should be debug, will throw excpetion too
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
@@ -269,7 +274,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertTrue(
|
||||
$log->getJsDebug()
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// set valid, then change
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
@@ -686,6 +691,11 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerLoggingLevelWrite(): array
|
||||
{
|
||||
return [
|
||||
@@ -791,6 +801,46 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
// check log level that writer writes in correct level
|
||||
// also that non debug ignores prefix/group
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::log
|
||||
* @testdox log() general call test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoggingLog(): void
|
||||
{
|
||||
// init logger
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
'log_file_id' => 'testLoggingLog',
|
||||
'log_folder' => self::LOG_FOLDER,
|
||||
'log_per_level' => true,
|
||||
]);
|
||||
$log_ok = $log->log(Level::Debug, 'DEBUG', group_id: 'GROUP_ID', prefix: 'PREFIX:');
|
||||
$this->assertTrue($log_ok, 'assert ::log (debug) OK');
|
||||
$this->assertEquals(
|
||||
$log->getLogFile(),
|
||||
$log->getLogFileId() . '_DEBUG.log'
|
||||
);
|
||||
$log_ok = $log->log(Level::Info, 'INFO', group_id: 'GROUP_ID', prefix: 'PREFIX:');
|
||||
$this->assertTrue($log_ok, 'assert ::log (info) OK');
|
||||
$this->assertEquals(
|
||||
$log->getLogFile(),
|
||||
$log->getLogFileId() . '_INFO.log'
|
||||
);
|
||||
}
|
||||
|
||||
// must test flow:
|
||||
// init normal
|
||||
// log -> check file name
|
||||
// set per date
|
||||
// log -> check file name
|
||||
// and same for per_run
|
||||
|
||||
// deprecated calls check?
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user