Remove Display\Error class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
65c93872f0
commit
0e3a82bd86
@ -9,7 +9,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\Display\Error as DisplayError;
|
||||
use PhpMyAdmin\Plugins\AuthenticationPlugin;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use const DATE_RFC1123;
|
||||
@ -291,11 +290,13 @@ class Core
|
||||
);
|
||||
} else {
|
||||
$error_message = strtr($error_message, ['<br>' => '[br]']);
|
||||
$error_header = __('Error');
|
||||
$lang = $GLOBALS['lang'] ?? 'en';
|
||||
$dir = $GLOBALS['text_dir'] ?? 'ltr';
|
||||
$template = new Template();
|
||||
|
||||
echo DisplayError::display(new Template(), $lang, $dir, $error_header, $error_message);
|
||||
echo $template->render('error/generic', [
|
||||
'lang' => $GLOBALS['lang'] ?? 'en',
|
||||
'dir' => $GLOBALS['text_dir'] ?? 'ltr',
|
||||
'error_message' => Sanitize::sanitizeMessage($error_message),
|
||||
]);
|
||||
}
|
||||
if (! defined('TESTSUITE')) {
|
||||
exit;
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Displays Error
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Display;
|
||||
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Template;
|
||||
use Throwable;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
|
||||
/**
|
||||
* Displays Error
|
||||
*/
|
||||
class Error
|
||||
{
|
||||
/**
|
||||
* @param Template $template Template object used to render the error
|
||||
* @param string $lang Lang of the HTML page
|
||||
* @param string $dir Direction of text of the HTML page
|
||||
* @param string $errorHeader Error header
|
||||
* @param string $errorMessage Error message
|
||||
*
|
||||
* @throws Throwable
|
||||
* @throws LoaderError
|
||||
* @throws RuntimeError
|
||||
* @throws SyntaxError
|
||||
*/
|
||||
public static function display(
|
||||
Template $template,
|
||||
string $lang,
|
||||
string $dir,
|
||||
string $errorHeader,
|
||||
string $errorMessage
|
||||
): string {
|
||||
return $template->render(
|
||||
'error/generic',
|
||||
[
|
||||
'lang' => $lang,
|
||||
'dir' => $dir,
|
||||
'error_header' => $errorHeader,
|
||||
'error_message' => Sanitize::sanitizeMessage($errorMessage),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,7 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>phpMyAdmin - {{ error_header }}</h1>
|
||||
<h1>phpMyAdmin - {% trans 'Error' %}</h1>
|
||||
<p>{{ error_message|raw }}</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* tests for PhpMyAdmin\Display\Error
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Tests\Display;
|
||||
|
||||
use PhpMyAdmin\Display\Error;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
use Throwable;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
|
||||
/**
|
||||
* ErrorTest class
|
||||
*
|
||||
* this class is for testing PhpMyAdmin\Display\Error functions
|
||||
*/
|
||||
class ErrorTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* Test for Error::display
|
||||
*
|
||||
* @throws Throwable
|
||||
* @throws LoaderError
|
||||
* @throws RuntimeError
|
||||
* @throws SyntaxError
|
||||
*/
|
||||
public function testDisplaySimple(): void
|
||||
{
|
||||
$lang = 'fr';
|
||||
$dir = 'ltr';
|
||||
$error_header = 'Error';
|
||||
$error_message = 'Failure';
|
||||
|
||||
$html = Error::display(new Template(), $lang, $dir, $error_header, $error_message);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<html lang="fr" dir="ltr">',
|
||||
$html
|
||||
);
|
||||
$this->assertStringContainsString(
|
||||
'Failure',
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Error::display
|
||||
*
|
||||
* @throws Throwable
|
||||
* @throws LoaderError
|
||||
* @throws RuntimeError
|
||||
* @throws SyntaxError
|
||||
*/
|
||||
public function testDisplayToSanitize(): void
|
||||
{
|
||||
$lang = 'fr';
|
||||
$dir = 'ltr';
|
||||
$error_header = 'Error';
|
||||
$error_message = '[em]Failure[/em]';
|
||||
|
||||
$html = Error::display(new Template(), $lang, $dir, $error_header, $error_message);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<html lang="fr" dir="ltr">',
|
||||
$html
|
||||
);
|
||||
$this->assertStringContainsString(
|
||||
'<em>Failure</em>',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user