Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 872409ef54 | |||
| c4d5cad9e8 | |||
| 90550746ab | |||
| 724031b944 | |||
| 027c35f9f0 | |||
| 6ad844b519 | |||
| e10987ce8b | |||
| b3617954eb | |||
| 67fd7b172a | |||
| fe729453ac | |||
| b939edac3f | |||
| 00528cb7d7 | |||
| 3b8583de61 | |||
| f6821b7c21 |
@@ -1 +1 @@
|
|||||||
9.6.2
|
9.7.6
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ class EditBase
|
|||||||
private \CoreLibs\Output\Form\Generate $form;
|
private \CoreLibs\Output\Form\Generate $form;
|
||||||
/** @var \CoreLibs\Logging\Logging */
|
/** @var \CoreLibs\Logging\Logging */
|
||||||
public \CoreLibs\Logging\Logging $log;
|
public \CoreLibs\Logging\Logging $log;
|
||||||
|
/** @var \CoreLibs\Language\L10n */
|
||||||
|
public \CoreLibs\Language\L10n $l;
|
||||||
/** @var \CoreLibs\ACL\Login */
|
/** @var \CoreLibs\ACL\Login */
|
||||||
public \CoreLibs\ACL\Login $login;
|
public \CoreLibs\ACL\Login $login;
|
||||||
|
|
||||||
@@ -57,6 +59,7 @@ class EditBase
|
|||||||
) {
|
) {
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
$this->login = $login;
|
$this->login = $login;
|
||||||
|
$this->l = $l10n;
|
||||||
// smarty template engine (extended Translation version)
|
// smarty template engine (extended Translation version)
|
||||||
$this->smarty = new \CoreLibs\Template\SmartyExtend(
|
$this->smarty = new \CoreLibs\Template\SmartyExtend(
|
||||||
$l10n,
|
$l10n,
|
||||||
@@ -77,7 +80,7 @@ class EditBase
|
|||||||
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
// $this->form->log->debug('POST', $this->form->log->prAr($_POST));
|
// $this->log->debug('POST', $this->log->prAr($_POST));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,7 +182,7 @@ class EditBase
|
|||||||
} // while read data ...
|
} // while read data ...
|
||||||
|
|
||||||
// html title
|
// html title
|
||||||
$this->HEADER['HTML_TITLE'] = $this->form->l->__('Edit Order');
|
$this->HEADER['HTML_TITLE'] = $this->l->__('Edit Order');
|
||||||
|
|
||||||
$messages = [];
|
$messages = [];
|
||||||
$error = $_POST['error'] ?? 0;
|
$error = $_POST['error'] ?? 0;
|
||||||
@@ -632,7 +635,7 @@ class EditBase
|
|||||||
'editAdmin_' . $this->smarty->lang
|
'editAdmin_' . $this->smarty->lang
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->form->log->debug('DEBUGEND', '==================================== [Form END]');
|
$this->log->debug('DEBUGEND', '==================================== [Form END]');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
public function dbCheckPkSet(): bool
|
public function dbCheckPkSet(): bool
|
||||||
{
|
{
|
||||||
// if pk_id is set, overrule ...
|
// if pk_id is set, overrule ...
|
||||||
if ($this->pk_id) {
|
if (!empty($this->pk_id)) {
|
||||||
$this->table_array[$this->pk_name]['value'] = $this->pk_id;
|
$this->table_array[$this->pk_name]['value'] = $this->pk_id;
|
||||||
}
|
}
|
||||||
// if not set ... produce error
|
// if not set ... produce error
|
||||||
|
|||||||
@@ -3232,7 +3232,7 @@ class IO
|
|||||||
*
|
*
|
||||||
* @param array<mixed> $write_array list of elements to write
|
* @param array<mixed> $write_array list of elements to write
|
||||||
* @param array<mixed> $not_write_array list of elements not to write
|
* @param array<mixed> $not_write_array list of elements not to write
|
||||||
* @param int $primary_key id key to decide if we write insert or update
|
* @param int|null $primary_key id key to decide if we write insert or update
|
||||||
* @param string $table name for the target table
|
* @param string $table name for the target table
|
||||||
* @param array<mixed> $data data array to override _POST data
|
* @param array<mixed> $data data array to override _POST data
|
||||||
* @return int|false primary key
|
* @return int|false primary key
|
||||||
@@ -3240,7 +3240,7 @@ class IO
|
|||||||
public function dbWriteData(
|
public function dbWriteData(
|
||||||
array $write_array,
|
array $write_array,
|
||||||
array $not_write_array,
|
array $not_write_array,
|
||||||
int $primary_key,
|
?int $primary_key,
|
||||||
string $table,
|
string $table,
|
||||||
array $data = []
|
array $data = []
|
||||||
): int|false {
|
): int|false {
|
||||||
@@ -3260,19 +3260,19 @@ class IO
|
|||||||
* PARAM INFO: $primary key
|
* PARAM INFO: $primary key
|
||||||
* this can be a plain string/int and will be internal transformed into the array form
|
* this can be a plain string/int and will be internal transformed into the array form
|
||||||
* or it takes the array form of array [row => column, value => pk value]
|
* or it takes the array form of array [row => column, value => pk value]
|
||||||
* @param array<mixed> $write_array list of elements to write
|
* @param array<mixed> $write_array list of elements to write
|
||||||
* @param int|string|array<mixed> $primary_key primary key string or array set
|
* @param null|int|string|array<mixed> $primary_key primary key string or array set
|
||||||
* @param string $table name for the target table
|
* @param string $table name for the target table
|
||||||
* @param array<mixed> $not_write_array list of elements not to write (optional)
|
* @param array<mixed> $not_write_array list of elements not to write (optional)
|
||||||
* @param array<mixed> $not_write_update_array list of elements not
|
* @param array<mixed> $not_write_update_array list of elements not
|
||||||
* to write during update (optional)
|
* to write during update (optional)
|
||||||
* @param array<mixed> $data optional array with data
|
* @param array<mixed> $data optional array with data
|
||||||
* if not _POST vars are used
|
* if not _POST vars are used
|
||||||
* @return int|false primary key
|
* @return int|false primary key
|
||||||
*/
|
*/
|
||||||
public function dbWriteDataExt(
|
public function dbWriteDataExt(
|
||||||
array $write_array,
|
array $write_array,
|
||||||
int|string|array $primary_key,
|
null|int|string|array $primary_key,
|
||||||
string $table,
|
string $table,
|
||||||
array $not_write_array = [],
|
array $not_write_array = [],
|
||||||
array $not_write_update_array = [],
|
array $not_write_update_array = [],
|
||||||
|
|||||||
@@ -15,15 +15,26 @@ use CoreLibs\Logging\Logger\MessageLevel;
|
|||||||
|
|
||||||
class ErrorMessage
|
class ErrorMessage
|
||||||
{
|
{
|
||||||
/** @var array<int,array{id:string,level:string,str:string,target:string,highlight:string[]}> */
|
/** @var array<int,array{id:string,level:string,str:string,target:string,target_style:string,highlight:string[]}> */
|
||||||
private array $error_str = [];
|
private array $error_str = [];
|
||||||
/** @var \CoreLibs\Logging\Logging $log */
|
/** @var \CoreLibs\Logging\Logging $log */
|
||||||
public \CoreLibs\Logging\Logging $log;
|
public \CoreLibs\Logging\Logging $log;
|
||||||
|
|
||||||
|
/** @var bool $log_error global flag to log error level message */
|
||||||
|
private bool $log_error = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init ErrorMessage
|
||||||
|
*
|
||||||
|
* @param \CoreLibs\Logging\Logging $log
|
||||||
|
* @param bool $log_error [=false]
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\CoreLibs\Logging\Logging $log
|
\CoreLibs\Logging\Logging $log,
|
||||||
|
bool $log_error = false
|
||||||
) {
|
) {
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
|
$this->log_error = $log_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,25 +52,36 @@ class ErrorMessage
|
|||||||
* not set: unkown, will be logged as "emergency"
|
* not set: unkown, will be logged as "emergency"
|
||||||
* target/highlight: id target name for frontend where to attach this message
|
* target/highlight: id target name for frontend where to attach this message
|
||||||
* highlight is a list of other target points to highlight
|
* highlight is a list of other target points to highlight
|
||||||
|
* for highlight targets css names are $level without a prefix and should be
|
||||||
|
* nested in the target element "input .error { ... }"
|
||||||
|
* target_style: if not set uses 'error-' $level as css style. applies to targets or main only
|
||||||
*
|
*
|
||||||
* @param string $error_id Any internal error ID for this error
|
* @param string $error_id Any internal error ID for this error
|
||||||
* @param string $level Error level in ok/info/warn/error
|
* @param string $level Error level in ok/info/warn/error
|
||||||
* @param string $str Error message (out)
|
* @param string $str Error message (out)
|
||||||
* @param string $target alternate attachment point for this error message
|
* @param string $target alternate attachment point for this error message
|
||||||
* @param array<string> $highlight Any additional error data as error OR
|
* @param string $target_style Alternate color style for the error message
|
||||||
* highlight points for field highlights
|
* @param array<string> $highlight Any additional error data as error OR
|
||||||
* @param string|null $message If abort/crash, non localized $str
|
* highlight points for field highlights
|
||||||
* @param array<mixed> $context Additionl info for abort/crash messages
|
* @param string|null $message If abort/crash, non localized $str
|
||||||
|
* @param array<mixed> $context Additionl info for abort/crash messages
|
||||||
|
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
||||||
|
* else set for this call only
|
||||||
*/
|
*/
|
||||||
public function setErrorMsg(
|
public function setErrorMsg(
|
||||||
string $error_id,
|
string $error_id,
|
||||||
string $level,
|
string $level,
|
||||||
string $str,
|
string $str,
|
||||||
string $target = '',
|
string $target = '',
|
||||||
|
string $target_style = '',
|
||||||
array $highlight = [],
|
array $highlight = [],
|
||||||
?string $message = null,
|
?string $message = null,
|
||||||
array $context = [],
|
array $context = [],
|
||||||
|
?bool $log_error = null,
|
||||||
): void {
|
): void {
|
||||||
|
if ($log_error === null) {
|
||||||
|
$log_error = $this->log_error;
|
||||||
|
}
|
||||||
$original_level = $level;
|
$original_level = $level;
|
||||||
$level = MessageLevel::fromName($level)->name;
|
$level = MessageLevel::fromName($level)->name;
|
||||||
// if not string set, write message string if set, else level/error id
|
// if not string set, write message string if set, else level/error id
|
||||||
@@ -71,10 +93,19 @@ class ErrorMessage
|
|||||||
'level' => $level,
|
'level' => $level,
|
||||||
'str' => $str,
|
'str' => $str,
|
||||||
'target' => $target,
|
'target' => $target,
|
||||||
|
'target_style' => $target_style,
|
||||||
'highlight' => $highlight,
|
'highlight' => $highlight,
|
||||||
];
|
];
|
||||||
// write to log for abort/crash
|
// write to log for abort/crash
|
||||||
switch ($level) {
|
switch ($level) {
|
||||||
|
case 'error':
|
||||||
|
if ($log_error) {
|
||||||
|
$this->log->error($message ?? $str, array_merge([
|
||||||
|
'id' => $error_id,
|
||||||
|
'level' => $original_level,
|
||||||
|
], $context));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'abort':
|
case 'abort':
|
||||||
$this->log->critical($message ?? $str, array_merge([
|
$this->log->critical($message ?? $str, array_merge([
|
||||||
'id' => $error_id,
|
'id' => $error_id,
|
||||||
@@ -101,25 +132,40 @@ class ErrorMessage
|
|||||||
* Note, the parameter order is different and does not need an error id
|
* Note, the parameter order is different and does not need an error id
|
||||||
* This is for backend alerts
|
* This is for backend alerts
|
||||||
*
|
*
|
||||||
* @param string $level error level (ok/warn/info/error)
|
* @param string $level error level (ok/warn/info/error)
|
||||||
* @param string $str error string
|
* @param string $str error string
|
||||||
* @param string|null $error_id optional error id for precise error lookup
|
* @param string|null $error_id optional error id for precise error lookup
|
||||||
* @param string $target Alternate id name for output target on frontend
|
* @param string $target Alternate id name for output target on frontend
|
||||||
* @param array<string> $highlight Any additional error data as error OR
|
* @param string $target_style Alternate color style for the error message
|
||||||
* highlight points for field highlights
|
* @param array<string> $highlight Any additional error data as error OR
|
||||||
* @param string|null $message If abort/crash, non localized $str
|
* highlight points for field highlights
|
||||||
* @param array<mixed> $context Additionl info for abort/crash messages
|
* @param string|null $message If abort/crash, non localized $str
|
||||||
|
* @param array<mixed> $context Additionl info for abort/crash messages
|
||||||
|
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
||||||
|
* else set for this call only
|
||||||
*/
|
*/
|
||||||
public function setErrorMsgLevel(
|
public function setMessage(
|
||||||
string $level,
|
string $level,
|
||||||
string $str,
|
string $str,
|
||||||
?string $error_id = null,
|
?string $error_id = null,
|
||||||
string $target = '',
|
string $target = '',
|
||||||
|
string $target_style = '',
|
||||||
array $highlight = [],
|
array $highlight = [],
|
||||||
?string $message = null,
|
?string $message = null,
|
||||||
array $context = [],
|
array $context = [],
|
||||||
|
?bool $log_error = null,
|
||||||
): void {
|
): void {
|
||||||
$this->setErrorMsg($error_id ?? '', $level, $str, $target, $highlight, $message, $context);
|
$this->setErrorMsg(
|
||||||
|
$error_id ?? '',
|
||||||
|
$level,
|
||||||
|
$str,
|
||||||
|
$target,
|
||||||
|
$target_style,
|
||||||
|
$highlight,
|
||||||
|
$message,
|
||||||
|
$context,
|
||||||
|
$log_error
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
@@ -150,7 +196,7 @@ class ErrorMessage
|
|||||||
* Gets the LAST entry in the array list.
|
* Gets the LAST entry in the array list.
|
||||||
* If nothing found returns empty array set
|
* If nothing found returns empty array set
|
||||||
*
|
*
|
||||||
* @return array{id:string,level:string,str:string,target:string,highlight:string[]} Error block
|
* @return array{id:string,level:string,str:string,target:string,target:string,highlight:string[]} Error block
|
||||||
*/
|
*/
|
||||||
public function getLastErrorMsg(): array
|
public function getLastErrorMsg(): array
|
||||||
{
|
{
|
||||||
@@ -159,9 +205,35 @@ class ErrorMessage
|
|||||||
'str' => '',
|
'str' => '',
|
||||||
'id' => '',
|
'id' => '',
|
||||||
'target' => '',
|
'target' => '',
|
||||||
|
'target_string' => '',
|
||||||
'highlight' => [],
|
'highlight' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *********************************************************************
|
||||||
|
// FLAG SETTERS
|
||||||
|
// *********************************************************************
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the log error flag
|
||||||
|
*
|
||||||
|
* @param bool $flag True to log level error too, False for do not (Default)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setFlagLogError(bool $flag): void
|
||||||
|
{
|
||||||
|
$this->log_error = $flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current log error flag
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getFlagLogError(): bool
|
||||||
|
{
|
||||||
|
return $this->log_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -46,6 +46,39 @@ enum MessageLevel: int
|
|||||||
{
|
{
|
||||||
return self::tryFrom($value) ?? self::unknown;
|
return self::tryFrom($value) ?? self::unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the passed $level is higher or equal to $this
|
||||||
|
*
|
||||||
|
* @param MessageLevel $level
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function includes(MessageLevel $level): bool
|
||||||
|
{
|
||||||
|
return $this->value <= $level->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If level is higher than set one
|
||||||
|
*
|
||||||
|
* @param MessageLevel $level
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isHigherThan(MessageLevel $level): bool
|
||||||
|
{
|
||||||
|
return $this->value > $level->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if level is lower than set one
|
||||||
|
*
|
||||||
|
* @param MessageLevel $level
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isLowerThan(MessageLevel $level): bool
|
||||||
|
{
|
||||||
|
return $this->value < $level->value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -300,7 +300,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
// log
|
// log
|
||||||
/** @var \CoreLibs\Logging\Logging */
|
/** @var \CoreLibs\Logging\Logging */
|
||||||
public \CoreLibs\Logging\Logging $log;
|
public \CoreLibs\Logging\Logging $log;
|
||||||
|
/** @var \CoreLibs\DB\Extended\ArrayIO */
|
||||||
|
public \CoreLibs\DB\Extended\ArrayIO $dba;
|
||||||
// now some default error msgs (english)
|
// now some default error msgs (english)
|
||||||
/** @var array<mixed> */
|
/** @var array<mixed> */
|
||||||
public array $language_array = [];
|
public array $language_array = [];
|
||||||
@@ -382,6 +383,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
$this->base_acl_level,
|
$this->base_acl_level,
|
||||||
$this->acl_admin
|
$this->acl_admin
|
||||||
);
|
);
|
||||||
|
$this->dba = new \CoreLibs\DB\Extended\ArrayIO(
|
||||||
|
$db_config,
|
||||||
|
$config_array['table_array'],
|
||||||
|
$config_array['table_name'],
|
||||||
|
$this->log,
|
||||||
|
// set the ACL
|
||||||
|
$this->base_acl_level,
|
||||||
|
$this->acl_admin
|
||||||
|
);
|
||||||
// here should be a check if the config_array is correct ...
|
// here should be a check if the config_array is correct ...
|
||||||
if (isset($config_array['show_fields']) && is_array($config_array['show_fields'])) {
|
if (isset($config_array['show_fields']) && is_array($config_array['show_fields'])) {
|
||||||
$this->field_array = $config_array['show_fields'];
|
$this->field_array = $config_array['show_fields'];
|
||||||
|
|||||||
40
src/Output/Form/TableArrays/EditOrder.php
Normal file
40
src/Output/Form/TableArrays/EditOrder.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Output\Form\TableArrays;
|
||||||
|
|
||||||
|
class EditOrder implements Interface\TableArraysInterface
|
||||||
|
{
|
||||||
|
/** @var \CoreLibs\Output\Form\Generate */
|
||||||
|
private \CoreLibs\Output\Form\Generate $form;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor
|
||||||
|
* @param \CoreLibs\Output\Form\Generate $form base form class
|
||||||
|
*/
|
||||||
|
public function __construct(\CoreLibs\Output\Form\Generate $form)
|
||||||
|
{
|
||||||
|
$this->form = $form;
|
||||||
|
$this->form->log->debug('CLASS LOAD', __NAMESPACE__ . __CLASS__);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOTE: this is a dummy array to just init the Form\Generate class and is not used for anything else
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function setTableArray(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'table_array' => [
|
||||||
|
'-'
|
||||||
|
],
|
||||||
|
'table_name' => '-',
|
||||||
|
'load_query' => '',
|
||||||
|
'show_fields' => [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -96,7 +96,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'log_level' => Level::Debug,
|
'log_level' => Level::Debug,
|
||||||
]);
|
]);
|
||||||
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
$em = new \CoreLibs\Logging\ErrorMessage($log);
|
||||||
$em->setErrorMsgLevel(
|
$em->setMessage(
|
||||||
$level,
|
$level,
|
||||||
$str
|
$str
|
||||||
);
|
);
|
||||||
@@ -106,6 +106,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'str' => $str,
|
'str' => $str,
|
||||||
'id' => '',
|
'id' => '',
|
||||||
'target' => '',
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
'highlight' => [],
|
'highlight' => [],
|
||||||
],
|
],
|
||||||
$em->getLastErrorMsg()
|
$em->getLastErrorMsg()
|
||||||
@@ -139,6 +140,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'info',
|
'level' => 'info',
|
||||||
'str' => 'INFO MESSAGE',
|
'str' => 'INFO MESSAGE',
|
||||||
'target' => '',
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
'highlight' => [],
|
'highlight' => [],
|
||||||
],
|
],
|
||||||
$em->getLastErrorMsg()
|
$em->getLastErrorMsg()
|
||||||
@@ -154,6 +156,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'info',
|
'level' => 'info',
|
||||||
'str' => 'INFO MESSAGE',
|
'str' => 'INFO MESSAGE',
|
||||||
'target' => '',
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
'highlight' => [],
|
'highlight' => [],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@@ -171,6 +174,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'error',
|
'level' => 'error',
|
||||||
'str' => 'ERROR MESSAGE',
|
'str' => 'ERROR MESSAGE',
|
||||||
'target' => '',
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
'highlight' => [],
|
'highlight' => [],
|
||||||
],
|
],
|
||||||
$em->getLastErrorMsg()
|
$em->getLastErrorMsg()
|
||||||
@@ -186,6 +190,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'info',
|
'level' => 'info',
|
||||||
'str' => 'INFO MESSAGE',
|
'str' => 'INFO MESSAGE',
|
||||||
'target' => '',
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
'highlight' => [],
|
'highlight' => [],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@@ -193,6 +198,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'error',
|
'level' => 'error',
|
||||||
'str' => 'ERROR MESSAGE',
|
'str' => 'ERROR MESSAGE',
|
||||||
'target' => '',
|
'target' => '',
|
||||||
|
'target_style' => '',
|
||||||
'highlight' => [],
|
'highlight' => [],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@@ -200,14 +206,44 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function providerErrorMessageLog(): array
|
public function providerErrorMessageLog(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'error, not logged' => [
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
|
'expected' => '<ERROR> ERROR MESSAGE',
|
||||||
|
],
|
||||||
|
'error, logged' => [
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR MESSAGE',
|
||||||
|
'message' => null,
|
||||||
|
'log_error' => true,
|
||||||
|
'expected' => '<ERROR> ERROR MESSAGE',
|
||||||
|
],
|
||||||
|
'error, logged, message' => [
|
||||||
|
'id' => '200',
|
||||||
|
'level' => 'error',
|
||||||
|
'str' => 'ERROR MESSAGE',
|
||||||
|
'message' => 'OTHER ERROR MESSAGE',
|
||||||
|
'log_error' => true,
|
||||||
|
'expected' => '<ERROR> OTHER ERROR MESSAGE',
|
||||||
|
],
|
||||||
'crash' => [
|
'crash' => [
|
||||||
'id' => '300',
|
'id' => '300',
|
||||||
'level' => 'crash',
|
'level' => 'crash',
|
||||||
'str' => 'CRASH MESSAGE',
|
'str' => 'CRASH MESSAGE',
|
||||||
'message' => null,
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
'expected' => '<ALERT> CRASH MESSAGE',
|
'expected' => '<ALERT> CRASH MESSAGE',
|
||||||
],
|
],
|
||||||
'crash, message' => [
|
'crash, message' => [
|
||||||
@@ -215,6 +251,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'crash',
|
'level' => 'crash',
|
||||||
'str' => 'CRASH MESSAGE',
|
'str' => 'CRASH MESSAGE',
|
||||||
'message' => 'OTHER CRASH MESSAGE',
|
'message' => 'OTHER CRASH MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
'expected' => '<ALERT> OTHER CRASH MESSAGE',
|
'expected' => '<ALERT> OTHER CRASH MESSAGE',
|
||||||
],
|
],
|
||||||
'abort' => [
|
'abort' => [
|
||||||
@@ -222,6 +259,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'abort',
|
'level' => 'abort',
|
||||||
'str' => 'ABORT MESSAGE',
|
'str' => 'ABORT MESSAGE',
|
||||||
'message' => null,
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
'expected' => '<CRITICAL> ABORT MESSAGE',
|
'expected' => '<CRITICAL> ABORT MESSAGE',
|
||||||
],
|
],
|
||||||
'abort, message' => [
|
'abort, message' => [
|
||||||
@@ -229,6 +267,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'abort',
|
'level' => 'abort',
|
||||||
'str' => 'ABORT MESSAGE',
|
'str' => 'ABORT MESSAGE',
|
||||||
'message' => 'OTHER ABORT MESSAGE',
|
'message' => 'OTHER ABORT MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
'expected' => '<CRITICAL> OTHER ABORT MESSAGE',
|
'expected' => '<CRITICAL> OTHER ABORT MESSAGE',
|
||||||
],
|
],
|
||||||
'unknown' => [
|
'unknown' => [
|
||||||
@@ -236,6 +275,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'wrong level',
|
'level' => 'wrong level',
|
||||||
'str' => 'WRONG LEVEL MESSAGE',
|
'str' => 'WRONG LEVEL MESSAGE',
|
||||||
'message' => null,
|
'message' => null,
|
||||||
|
'log_error' => null,
|
||||||
'expected' => '<EMERGENCY> WRONG LEVEL MESSAGE',
|
'expected' => '<EMERGENCY> WRONG LEVEL MESSAGE',
|
||||||
],
|
],
|
||||||
'unknown, message' => [
|
'unknown, message' => [
|
||||||
@@ -243,6 +283,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
'level' => 'wrong level',
|
'level' => 'wrong level',
|
||||||
'str' => 'WRONG LEVEL MESSAGE',
|
'str' => 'WRONG LEVEL MESSAGE',
|
||||||
'message' => 'OTHER WRONG LEVEL MESSAGE',
|
'message' => 'OTHER WRONG LEVEL MESSAGE',
|
||||||
|
'log_error' => null,
|
||||||
'expected' => '<EMERGENCY> OTHER WRONG LEVEL MESSAGE',
|
'expected' => '<EMERGENCY> OTHER WRONG LEVEL MESSAGE',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -254,10 +295,22 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
* @dataProvider providerErrorMessageLog
|
* @dataProvider providerErrorMessageLog
|
||||||
* @testdox Test Log writing [$_dataName]
|
* @testdox Test Log writing [$_dataName]
|
||||||
*
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param string $level
|
||||||
|
* @param string $str
|
||||||
|
* @param string|null $message
|
||||||
|
* @param bool|null $log_error
|
||||||
|
* @param string $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testErrorMessageLog(string $id, string $level, string $str, ?string $message, string $expected)
|
public function testErrorMessageLog(
|
||||||
{
|
string $id,
|
||||||
|
string $level,
|
||||||
|
string $str,
|
||||||
|
?string $message,
|
||||||
|
?bool $log_error,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
$log = new \CoreLibs\Logging\Logging([
|
$log = new \CoreLibs\Logging\Logging([
|
||||||
'log_file_id' => 'testErrorMessages',
|
'log_file_id' => 'testErrorMessages',
|
||||||
'log_folder' => self::LOG_FOLDER,
|
'log_folder' => self::LOG_FOLDER,
|
||||||
@@ -269,15 +322,27 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
|||||||
$id,
|
$id,
|
||||||
$level,
|
$level,
|
||||||
$str,
|
$str,
|
||||||
message: $message
|
message: $message,
|
||||||
);
|
log_error: $log_error
|
||||||
$file_content = file_get_contents(
|
|
||||||
$log->getLogFolder() . $log->getLogFile()
|
|
||||||
) ?: '';
|
|
||||||
$this->assertStringContainsString(
|
|
||||||
$expected,
|
|
||||||
$file_content
|
|
||||||
);
|
);
|
||||||
|
$file_content = '';
|
||||||
|
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||||
|
$file_content = file_get_contents(
|
||||||
|
$log->getLogFolder() . $log->getLogFile()
|
||||||
|
) ?: '';
|
||||||
|
}
|
||||||
|
// if n
|
||||||
|
if ($level == 'error' && ($log_error === null || $log_error === false)) {
|
||||||
|
$this->assertStringNotContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$file_content
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user