Skip to content

Commit

Permalink
Remove Message::display method
Browse files Browse the repository at this point in the history
Related to #16258.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jul 20, 2020
1 parent 78e1b40 commit 3f01cd8
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 92 deletions.
16 changes: 8 additions & 8 deletions libraries/classes/Controllers/Database/TrackingController.php
Expand Up @@ -74,29 +74,29 @@ public function index(): void

if (isset($_POST['delete_tracking'], $_POST['table'])) {
Tracker::deleteTracking($db, $_POST['table']);
Message::success(
echo Message::success(
__('Tracking data deleted successfully.')
)->display();
)->getDisplay();
} elseif (isset($_POST['submit_create_version'])) {
$this->tracking->createTrackingForMultipleTables($_POST['selected']);
Message::success(
echo Message::success(
sprintf(
__(
'Version %1$s was created for selected tables,'
. ' tracking is active for them.'
),
htmlspecialchars($_POST['version'])
)
)->display();
)->getDisplay();
} elseif (isset($_POST['submit_mult'])) {
if (! empty($_POST['selected_tbl'])) {
if ($_POST['submit_mult'] === 'delete_tracking') {
foreach ($_POST['selected_tbl'] as $table) {
Tracker::deleteTracking($db, $table);
}
Message::success(
echo Message::success(
__('Tracking data deleted successfully.')
)->display();
)->getDisplay();
} elseif ($_POST['submit_mult'] === 'track') {
echo $this->template->render('create_tracking_version', [
'route' => '/database/tracking',
Expand All @@ -111,9 +111,9 @@ public function index(): void
return;
}
} else {
Message::notice(
echo Message::notice(
__('No tables selected.')
)->display();
)->getDisplay();
}
}

Expand Down
Expand Up @@ -54,7 +54,7 @@ public function index(): void
}

$twoFactor->configure('');
Message::rawNotice(__('Two-factor authentication has been removed.'))->display();
echo Message::rawNotice(__('Two-factor authentication has been removed.'))->getDisplay();
} elseif (isset($_POST['2fa_configure'])) {
if (! $twoFactor->configure($_POST['2fa_configure'])) {
echo $this->template->render('preferences/two_factor/configure', [
Expand All @@ -65,7 +65,7 @@ public function index(): void
return;
}

Message::rawNotice(__('Two-factor authentication has been configured.'))->display();
echo Message::rawNotice(__('Two-factor authentication has been configured.'))->getDisplay();
}

$backend = $twoFactor->getBackend();
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Database/Events.php
Expand Up @@ -576,7 +576,7 @@ private function sendEditor($mode, ?array $item, $title, $db, $operation)
exit;
}

$message->display();
echo $message->getDisplay();
}

public function export(): void
Expand Down Expand Up @@ -628,6 +628,6 @@ public function export(): void
exit;
}

$message->display();
echo $message->getDisplay();
}
}
2 changes: 1 addition & 1 deletion libraries/classes/Database/Qbe.php
Expand Up @@ -356,7 +356,7 @@ private function setCriteriaTablesAndColumns()
);
$all_tables_count = $this->dbi->numRows($all_tables);
if ($all_tables_count == 0) {
Message::error(__('No tables found in database.'))->display();
echo Message::error(__('No tables found in database.'))->getDisplay();
exit;
}
// The tables list gets from MySQL
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Database/Routines.php
Expand Up @@ -220,7 +220,7 @@ public function handleEditor()
exit;
}

$message->display();
echo $message->getDisplay();
}

/**
Expand Down Expand Up @@ -1979,6 +1979,6 @@ private function export(): void
exit;
}

$message->display();
echo $message->getDisplay();
}
}
4 changes: 2 additions & 2 deletions libraries/classes/Database/Triggers.php
Expand Up @@ -589,7 +589,7 @@ private function sendEditor($mode, ?array $item, $title, $db)
exit;
}

$message->display();
echo $message->getDisplay();
}

private function export(): void
Expand Down Expand Up @@ -645,6 +645,6 @@ private function export(): void
exit;
}

$message->display();
echo $message->getDisplay();
}
}
4 changes: 2 additions & 2 deletions libraries/classes/Display/Export.php
Expand Up @@ -659,9 +659,9 @@ public function getDisplay(

/* Fail if we didn't find any plugin */
if (empty($exportList)) {
Message::error(
echo Message::error(
__('Could not load export plugins, please check your installation!')
)->display();
)->getDisplay();
exit;
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Display/Import.php
Expand Up @@ -57,11 +57,11 @@ public static function get($importType, $db, $table, $maxUploadSize)

/* Fail if we didn't find any plugin */
if (empty($importList)) {
Message::error(
echo Message::error(
__(
'Could not load import plugins, please check your installation!'
)
)->display();
)->getDisplay();
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/ErrorHandler.php
Expand Up @@ -294,7 +294,7 @@ protected function dispFatalError(Error $error): void
if (! headers_sent()) {
$this->dispPageStart($error);
}
$error->display();
echo $error->getDisplay();
$this->dispPageEnd();
exit;
}
Expand Down
10 changes: 0 additions & 10 deletions libraries/classes/Menu.php
Expand Up @@ -59,16 +59,6 @@ public function __construct($db, $table)
$this->template = new Template();
}

/**
* Prints the menu and the breadcrumbs
*
* @return void
*/
public function display()
{
echo $this->getDisplay();
}

/**
* Returns the menu and the breadcrumbs as a string
*
Expand Down
10 changes: 1 addition & 9 deletions libraries/classes/Message.php
Expand Up @@ -23,7 +23,7 @@
* simple usage examples:
* <code>
* // display simple error message 'Error'
* Message::error()->display();
* echo Message::error()->getDisplay();
*
* // get simple success message 'Success'
* $message = Message::success();
Expand Down Expand Up @@ -739,14 +739,6 @@ public function getLevel(): string
return self::$level[$this->getNumber()];
}

/**
* Displays the message in HTML
*/
public function display(): void
{
echo $this->getDisplay();
}

/**
* returns HTML code for displaying this message
*
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Pdf.php
Expand Up @@ -152,9 +152,9 @@ public function _putpages()
// @codingStandardsIgnoreLine
public function Error($error_message = '')
{
Message::error(
echo Message::error(
__('Error while creating PDF:') . ' ' . $error_message
)->display();
)->getDisplay();
exit;
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/Plugins/AuthenticationPlugin.php
Expand Up @@ -358,9 +358,9 @@ public function checkTwoFactor(): void
exit;
}
echo $this->template->render('login/header', ['theme' => $GLOBALS['PMA_Theme']]);
Message::rawNotice(
echo Message::rawNotice(
__('You have enabled two factor authentication, please confirm your login.')
)->display();
)->getDisplay();
echo $this->template->render('login/twofactor', [
'form' => $twofactor->render(),
'show_submit' => $twofactor->showSubmit(),
Expand Down
10 changes: 4 additions & 6 deletions libraries/classes/Plugins/Import/ImportXml.php
Expand Up @@ -108,13 +108,12 @@ public function doImport(array &$sql_data = [])
* The XML was malformed
*/
if ($xml === false) {
Message::error(
echo Message::error(
__(
'The XML file specified was either malformed or incomplete.'
. ' Please correct the issue and try again.'
)
)
->display();
)->getDisplay();
unset($xml);
$GLOBALS['finished'] = false;

Expand Down Expand Up @@ -173,13 +172,12 @@ public function doImport(array &$sql_data = [])
* The XML was malformed
*/
if ($db_name === null) {
Message::error(
echo Message::error(
__(
'The XML file specified was either malformed or incomplete.'
. ' Please correct the issue and try again.'
)
)
->display();
)->getDisplay();
unset($xml);
$GLOBALS['finished'] = false;

Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/Routing.php
Expand Up @@ -66,10 +66,10 @@ public static function callControllerForRoute(
/** @var Response $response */
$response = $container->get(Response::class);
$response->setHttpResponseCode(404);
Message::error(sprintf(
echo Message::error(sprintf(
__('Error 404! The page %s was not found.'),
'<code>' . htmlspecialchars($route) . '</code>'
))->display();
))->getDisplay();

return;
}
Expand All @@ -78,7 +78,7 @@ public static function callControllerForRoute(
/** @var Response $response */
$response = $container->get(Response::class);
$response->setHttpResponseCode(405);
Message::error(__('Error 405! Request method not allowed.'))->display();
echo Message::error(__('Error 405! Request method not allowed.'))->getDisplay();

return;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Tracking.php
Expand Up @@ -280,7 +280,7 @@ public function getHtmlForTrackingReport(
*/
if (count($data['ddlog']) == 0 && count($data['dmlog']) === 0) {
$msg = Message::notice(__('No data'));
$msg->display();
echo $msg->getDisplay();
}

$html .= $this->getHtmlForTrackingReportExportForm1(
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/TwoFactor.php
Expand Up @@ -269,7 +269,7 @@ public function configure($name)
}
$result = $this->save();
if ($result !== true) {
$result->display();
echo $result->getDisplay();
}

return true;
Expand Down
12 changes: 0 additions & 12 deletions test/classes/MenuTest.php
Expand Up @@ -76,18 +76,6 @@ public function testTable(): void
);
}

/**
* Table menu display test
*/
public function testTableDisplay(): void
{
$menu = new Menu('pma_test', '');
$this->expectOutputString(
$menu->getDisplay()
);
$menu->display();
}

/**
* Table menu setTable test
*/
Expand Down
29 changes: 5 additions & 24 deletions test/classes/MessageTest.php
Expand Up @@ -490,36 +490,20 @@ public function testGetLevel(): void
$this->assertEquals('error', $this->object->getLevel());
}

/**
* testing display method (output string and _is_displayed variable)
*/
public function testDisplay(): void
{
$this->assertFalse($this->object->isDisplayed());
$this->object->setMessage('Test Message');

$this->expectOutputString(
'<div class="alert alert-primary" role="alert">' . "\n"
. ' <img src="themes/dot.gif" title="" alt="" class="icon ic_s_notice"> Test Message' . "\n"
. '</div>' . "\n"
);
$this->object->display();

$this->assertTrue($this->object->isDisplayed());
}

/**
* getDisplay test
*/
public function testGetDisplay(): void
{
$this->assertFalse($this->object->isDisplayed());
$this->object->setMessage('Test Message');
$this->assertEquals(
'<div class="alert alert-primary" role="alert">' . "\n"
. ' <img src="themes/dot.gif" title="" alt="" class="icon ic_s_notice"> Test Message' . "\n"
. '</div>' . "\n",
$this->object->getDisplay()
);
$this->assertTrue($this->object->isDisplayed());
}

/**
Expand Down Expand Up @@ -574,8 +558,7 @@ public function testAffectedRows(int $rows, string $output): void
$this->object = new Message();
$msg = $this->object->getMessageForAffectedRows($rows);
$this->object->addMessage($msg);
$this->expectOutputString($output);
$this->object->display();
$this->assertEquals($output, $this->object->getDisplay());
}

/**
Expand Down Expand Up @@ -620,8 +603,7 @@ public function testInsertedRows(int $rows, string $output): void
$this->object = new Message();
$msg = $this->object->getMessageForInsertedRows($rows);
$this->object->addMessage($msg);
$this->expectOutputString($output);
$this->object->display();
$this->assertEquals($output, $this->object->getDisplay());
}

/**
Expand Down Expand Up @@ -666,7 +648,6 @@ public function testDeletedRows(int $rows, string $output): void
$this->object = new Message();
$msg = $this->object->getMessageForDeletedRows($rows);
$this->object->addMessage($msg);
$this->expectOutputString($output);
$this->object->display();
$this->assertEquals($output, $this->object->getDisplay());
}
}

0 comments on commit 3f01cd8

Please sign in to comment.