phpmyadmin/tests/unit/Controllers/Server/Status/Processes/RefreshControllerTest.php
Kamil Tekiela f708e074c9
Clean up config again (#20264)
* MaxTableList/MaxDbList/QueryHistoryMax
* UserprefsDisallow
* NaturalOrder
* Update TableTest.php
* MaxExactCountViews
* Update ReplicationGuiTest.php
* Update RoutinesTest.php
* Update StructureControllerTest.php
* Update ExportControllerTest.php
* Update StructureControllerTest.php
* Update BookmarkTest.php
* MaxCharactersInDisplayedSQL
* ActionLinksMode/ShowSQL/MysqlSslWarningSafeHosts
* Update TwoFactorTest.php
* ForeignKeyMaxLimit/ForeignKeyDropdownOrder
* QueryHistoryDB
* ZeroConf
* UseDbSearch
* MaxRoutineList
* NumFavoriteTables
* EnableAutocompleteForTablesAndColumns
* MaxExactCount/ShowStats
* InitialSlidersState
* Remove isset in Results
* Remove isset and fix tests
* PmaNoRelation_DisableWarning
* ShowCreateDb
* Update phpstan-baseline.neon
* Navigation
* Upgrading vimeo/psalm (6.15.0 => 6.16.1)

---------

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
2026-04-10 16:33:08 -03:00

119 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Server\Status\Processes;
use PhpMyAdmin\Config;
use PhpMyAdmin\Controllers\Server\Status\Processes\RefreshController;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\Server\Status\Processes;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Url;
use PHPUnit\Framework\Attributes\CoversClass;
use function __;
use function htmlspecialchars;
#[CoversClass(RefreshController::class)]
class RefreshControllerTest extends AbstractTestCase
{
private Data $data;
protected function setUp(): void
{
parent::setUp();
DatabaseInterface::$instance = $this->createDatabaseInterface();
Current::$database = 'db';
Current::$table = 'table';
$config = Config::getInstance();
$config->selectedServer['DisableIS'] = false;
$config->selectedServer['host'] = 'localhost';
$this->data = new Data(DatabaseInterface::getInstance(), $config);
}
public function testRefresh(): void
{
$process = [
'User' => 'User1',
'Host' => 'Host1',
'Id' => 'Id1',
'Db' => 'db1',
'Command' => 'Command1',
'Info' => 'Info1',
'State' => 'State1',
'Time' => 'Time1',
];
$config = Config::getInstance();
$response = new ResponseRenderer();
$controller = new RefreshController(
$response,
new Template($config),
$this->data,
new Processes(DatabaseInterface::getInstance()),
);
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody([
'ajax_request' => 'true',
'column_name' => '',
'order_by_field' => 'process',
'sort_order' => 'DESC',
'full' => 'true',
]);
$controller($request);
$html = $response->getHTMLResult();
self::assertStringContainsString('index.php?route=/server/status/processes', $html);
$killProcess = 'data-post="'
. Url::getCommon(['kill' => $process['Id']], '') . '"';
self::assertStringContainsString($killProcess, $html);
self::assertStringContainsString('ajax kill_process', $html);
self::assertStringContainsString(
__('Kill'),
$html,
);
//validate 2: $process['User']
self::assertStringContainsString(
htmlspecialchars($process['User']),
$html,
);
//validate 3: $process['Host']
self::assertStringContainsString(
htmlspecialchars($process['Host']),
$html,
);
//validate 4: $process['db']
self::assertStringContainsString($process['Db'], $html);
//validate 5: $process['Command']
self::assertStringContainsString(
htmlspecialchars($process['Command']),
$html,
);
//validate 6: $process['Time']
self::assertStringContainsString($process['Time'], $html);
//validate 7: $process['state']
self::assertStringContainsString($process['State'], $html);
//validate 8: $process['info']
self::assertStringContainsString($process['Info'], $html);
}
}