diff options
7 files changed, 94 insertions, 34 deletions
diff --git a/js/src/normalization.js b/js/src/normalization.js index fd48a502a1..3fc98a9f93 100644 --- a/js/src/normalization.js +++ b/js/src/normalization.js @@ -755,13 +755,12 @@ window.AJAX.registerOnload('normalization.js', function () { $('#newCols').insertAfter('#mainContent h4'); $('#newCols').html('<div class="text-center">' + window.Messages.strLoading + '<br>' + window.Messages.strWaitForPd + '</div>'); $.post( - 'index.php?route=/normalization', + 'index.php?route=/normalization/partial-dependencies', { 'ajax_request': true, 'db': window.CommonParams.get('db'), 'table': window.CommonParams.get('table'), 'server': window.CommonParams.get('server'), - 'findPdl': true }, function (data) { $('#showPossiblePd').html('- ' + window.Messages.strHidePd); $('#showPossiblePd').addClass('hideList'); diff --git a/libraries/classes/Controllers/Normalization/MainController.php b/libraries/classes/Controllers/Normalization/MainController.php index 571dde45d2..91bde1300b 100644 --- a/libraries/classes/Controllers/Normalization/MainController.php +++ b/libraries/classes/Controllers/Normalization/MainController.php @@ -6,35 +6,15 @@ namespace PhpMyAdmin\Controllers\Normalization; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Http\ServerRequest; -use PhpMyAdmin\Normalization; -use PhpMyAdmin\ResponseRenderer; -use PhpMyAdmin\Template; /** * Normalization process (temporarily specific to 1NF). */ class MainController extends AbstractController { - /** @var Normalization */ - private $normalization; - - public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization) - { - parent::__construct($response, $template); - $this->normalization = $normalization; - } - public function __invoke(ServerRequest $request): void { - if (isset($_POST['findPdl'])) { - $html = $this->normalization->findPartialDependencies($GLOBALS['table'], $GLOBALS['db']); - echo $html; - - return; - } - $this->addScriptFiles(['normalization.js', 'vendor/jquery/jquery.uitablefilter.js']); - $this->render('table/normalization/normalization', [ 'db' => $GLOBALS['db'], 'table' => $GLOBALS['table'], diff --git a/libraries/classes/Controllers/Normalization/PartialDependenciesController.php b/libraries/classes/Controllers/Normalization/PartialDependenciesController.php new file mode 100644 index 0000000000..a847ef6832 --- /dev/null +++ b/libraries/classes/Controllers/Normalization/PartialDependenciesController.php @@ -0,0 +1,29 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Normalization; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Normalization; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +final class PartialDependenciesController extends AbstractController +{ + /** @var Normalization */ + private $normalization; + + public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization) + { + parent::__construct($response, $template); + $this->normalization = $normalization; + } + + public function __invoke(ServerRequest $request): void + { + $html = $this->normalization->findPartialDependencies($GLOBALS['table'], $GLOBALS['db']); + $this->response->addHTML($html); + } +} diff --git a/libraries/routes.php b/libraries/routes.php index a71f637d20..44f1062780 100644 --- a/libraries/routes.php +++ b/libraries/routes.php @@ -145,6 +145,7 @@ return static function (RouteCollector $routes): void { $routes->post('/get-columns', Normalization\GetColumnsController::class); $routes->post('/create-new-column', Normalization\CreateNewColumnController::class); $routes->post('/move-repeating-group', Normalization\MoveRepeatingGroup::class); + $routes->post('/partial-dependencies', Normalization\PartialDependenciesController::class); }); $routes->get('/phpinfo', PhpInfoController::class); $routes->addGroup('/preferences', static function (RouteCollector $routes): void { diff --git a/libraries/services_controllers.php b/libraries/services_controllers.php index ddc00d922f..02725969a4 100644 --- a/libraries/services_controllers.php +++ b/libraries/services_controllers.php @@ -688,6 +688,10 @@ return [ '$normalization' => '@normalization', ], ], + Normalization\MainController::class => [ + 'class' => Normalization\MainController::class, + 'arguments' => ['$response' => '@response', '$template' => '@template'], + ], Normalization\MoveRepeatingGroup::class => [ 'class' => Normalization\MoveRepeatingGroup::class, 'arguments' => [ @@ -696,8 +700,8 @@ return [ '$normalization' => '@normalization', ], ], - Normalization\MainController::class => [ - 'class' => Normalization\MainController::class, + Normalization\PartialDependenciesController::class => [ + 'class' => Normalization\PartialDependenciesController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', diff --git a/test/classes/Controllers/Normalization/MainControllerTest.php b/test/classes/Controllers/Normalization/MainControllerTest.php index dd4ad90ad0..803967e84c 100644 --- a/test/classes/Controllers/Normalization/MainControllerTest.php +++ b/test/classes/Controllers/Normalization/MainControllerTest.php @@ -4,16 +4,13 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Normalization; -use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\Controllers\Normalization\MainController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Http\ServerRequest; -use PhpMyAdmin\Normalization; use PhpMyAdmin\Template; use PhpMyAdmin\Tests\AbstractTestCase; use PhpMyAdmin\Tests\Stubs\DbiDummy; use PhpMyAdmin\Tests\Stubs\ResponseRenderer; -use PhpMyAdmin\Transformations; use function in_array; @@ -49,15 +46,9 @@ class MainControllerTest extends AbstractTestCase { $GLOBALS['db'] = 'test_db'; $GLOBALS['table'] = 'test_table'; - $dbi = $this->createDatabaseInterface(); $response = new ResponseRenderer(); - $template = new Template(); - $controller = new MainController( - $response, - $template, - new Normalization($dbi, new Relation($dbi), new Transformations(), $template) - ); + $controller = new MainController($response, new Template()); $controller($this->createStub(ServerRequest::class)); $files = $response->getHeader()->getScripts()->getFiles(); diff --git a/test/classes/Controllers/Normalization/PartialDependenciesControllerTest.php b/test/classes/Controllers/Normalization/PartialDependenciesControllerTest.php new file mode 100644 index 0000000000..2d01962001 --- /dev/null +++ b/test/classes/Controllers/Normalization/PartialDependenciesControllerTest.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Normalization; + +use PhpMyAdmin\ConfigStorage\Relation; +use PhpMyAdmin\Controllers\Normalization\PartialDependenciesController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Normalization; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; +use PhpMyAdmin\Transformations; + +/** + * @covers \PhpMyAdmin\Controllers\Normalization\PartialDependenciesController + */ +class PartialDependenciesControllerTest extends AbstractTestCase +{ + public function testDefault(): void + { + $GLOBALS['db'] = 'test_db'; + $GLOBALS['table'] = 'test_table'; + + // phpcs:disable Generic.Files.LineLength.TooLong + $dbiDummy = $this->createDbiDummy(); + $dbiDummy->addSelectDb('test_db'); + $dbiDummy->addResult('SELECT COUNT(*) FROM (SELECT * FROM `test_table` LIMIT 500) as dt;', [['0']], ['dt']); + $dbiDummy->addResult( + 'SELECT COUNT(DISTINCT `id`) as \'`id`_cnt\', COUNT(DISTINCT `name`) as \'`name`_cnt\', COUNT(DISTINCT `datetimefield`) as \'`datetimefield`_cnt\' FROM (SELECT * FROM `test_table` LIMIT 500) as dt;', + [], + ['`id`_cnt', '`name`_cnt', '`datetimefield`_cnt', '`datetimefield`_cnt', 'dt'] + ); + // phpcs:enable + + $dbi = $this->createDatabaseInterface($dbiDummy); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + $template = new Template(); + + $controller = new PartialDependenciesController( + $response, + $template, + new Normalization($dbi, new Relation($dbi), new Transformations(), $template) + ); + $controller($this->createStub(ServerRequest::class)); + + // phpcs:disable Generic.Files.LineLength.TooLong + $this->assertSame( + 'This list is based on a subset of the table\'s data and is not necessarily accurate. <div class="dependencies_box"><p class="d-block m-1">No partial dependencies found!</p></div>', + $response->getHTMLResult() + ); + // phpcs:enable + } +} |