Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/src/normalization.js3
-rw-r--r--libraries/classes/Controllers/Normalization/ThirdNormalForm/FirstStepController.php30
-rw-r--r--libraries/classes/Controllers/NormalizationController.php8
-rw-r--r--libraries/routes.php1
-rw-r--r--libraries/services_controllers.php8
-rw-r--r--psalm-baseline.xml14
-rw-r--r--test/classes/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php2
-rw-r--r--test/classes/Controllers/Normalization/ThirdNormalForm/FirstStepControllerTest.php51
8 files changed, 101 insertions, 16 deletions
diff --git a/js/src/normalization.js b/js/src/normalization.js
index 4e734e240e..c800ff634d 100644
--- a/js/src/normalization.js
+++ b/js/src/normalization.js
@@ -40,13 +40,12 @@ function goTo3NFStep1 (newTables) {
tables = [window.CommonParams.get('table')];
}
$.post(
- 'index.php?route=/normalization',
+ 'index.php?route=/normalization/3nf/step1',
{
'ajax_request': true,
'db': window.CommonParams.get('db'),
'server': window.CommonParams.get('server'),
'tables': tables,
- 'step': '3.1'
}, function (data) {
$('#page_content').find('h3').html(window.Messages.str3NFNormalization);
$('#mainContent').find('legend').html(data.legendText);
diff --git a/libraries/classes/Controllers/Normalization/ThirdNormalForm/FirstStepController.php b/libraries/classes/Controllers/Normalization/ThirdNormalForm/FirstStepController.php
new file mode 100644
index 0000000000..5b50da6a87
--- /dev/null
+++ b/libraries/classes/Controllers/Normalization/ThirdNormalForm/FirstStepController.php
@@ -0,0 +1,30 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Normalization\ThirdNormalForm;
+
+use PhpMyAdmin\Controllers\AbstractController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Normalization;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Template;
+
+final class FirstStepController 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
+ {
+ $tables = $_POST['tables'];
+ $res = $this->normalization->getHtmlFor3NFstep1($GLOBALS['db'], $tables);
+ $this->response->addJSON($res);
+ }
+}
diff --git a/libraries/classes/Controllers/NormalizationController.php b/libraries/classes/Controllers/NormalizationController.php
index 02451e26fa..1dbf6586bd 100644
--- a/libraries/classes/Controllers/NormalizationController.php
+++ b/libraries/classes/Controllers/NormalizationController.php
@@ -135,14 +135,6 @@ class NormalizationController extends AbstractController
return;
}
- if (isset($_POST['step']) && $_POST['step'] == '3.1') {
- $tables = $_POST['tables'];
- $res = $this->normalization->getHtmlFor3NFstep1($GLOBALS['db'], $tables);
- $this->response->addJSON($res);
-
- return;
- }
-
$this->render('table/normalization/normalization', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
diff --git a/libraries/routes.php b/libraries/routes.php
index d150421a99..7f17bbf603 100644
--- a/libraries/routes.php
+++ b/libraries/routes.php
@@ -138,6 +138,7 @@ return static function (RouteCollector $routes): void {
$routes->post('/1nf/step4', Normalization\FirstNormalForm\FourthStepController::class);
$routes->post('/2nf/new-tables', Normalization\SecondNormalForm\NewTablesController::class);
$routes->post('/2nf/step1', Normalization\SecondNormalForm\FirstStepController::class);
+ $routes->post('/3nf/step1', Normalization\ThirdNormalForm\FirstStepController::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 dc7fa99985..3d9eb312ea 100644
--- a/libraries/services_controllers.php
+++ b/libraries/services_controllers.php
@@ -633,6 +633,14 @@ return [
'$normalization' => '@normalization',
],
],
+ Normalization\ThirdNormalForm\FirstStepController::class => [
+ 'class' => Normalization\ThirdNormalForm\FirstStepController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$normalization' => '@normalization',
+ ],
+ ],
NormalizationController::class => [
'class' => NormalizationController::class,
'arguments' => [
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 91aa5a2050..98672f2a3c 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -2416,8 +2416,16 @@
<code>$partialDependencies</code>
</MixedAssignment>
</file>
+ <file src="libraries/classes/Controllers/Normalization/ThirdNormalForm/FirstStepController.php">
+ <MixedArgument occurrences="1">
+ <code>$tables</code>
+ </MixedArgument>
+ <MixedAssignment occurrences="1">
+ <code>$tables</code>
+ </MixedAssignment>
+ </file>
<file src="libraries/classes/Controllers/NormalizationController.php">
- <MixedArgument occurrences="15">
+ <MixedArgument occurrences="14">
<code>$_POST['newTables']</code>
<code>$_POST['newTablesName']</code>
<code>$_POST['pd']</code>
@@ -2431,10 +2439,9 @@
<code>$primary_columns</code>
<code>$repeatingColumns</code>
<code>$tables</code>
- <code>$tables</code>
<code>$tablesName</code>
</MixedArgument>
- <MixedAssignment occurrences="10">
+ <MixedAssignment occurrences="9">
<code>$dependencies</code>
<code>$newColumn</code>
<code>$newTable</code>
@@ -2443,7 +2450,6 @@
<code>$primary_columns</code>
<code>$repeatingColumns</code>
<code>$tables</code>
- <code>$tables</code>
<code>$tablesName</code>
</MixedAssignment>
</file>
diff --git a/test/classes/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php b/test/classes/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php
index 52cb33daaa..c5ec7dda6f 100644
--- a/test/classes/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php
+++ b/test/classes/Controllers/Normalization/SecondNormalForm/FirstStepControllerTest.php
@@ -35,7 +35,6 @@ class FirstStepControllerTest extends AbstractTestCase
);
$controller($this->createStub(ServerRequest::class));
- // phpcs:disable Generic.Files.LineLength.TooLong
$this->assertSame([
'legendText' => 'Step 2.1 Find partial dependencies',
'headText' => 'No partial dependencies possible as the primary key ( id ) has just one column.<br>',
@@ -43,6 +42,5 @@ class FirstStepControllerTest extends AbstractTestCase
'extra' => '<h3>Table is already in second normal form.</h3>',
'primary_key' => 'id',
], $response->getJSONResult());
- // phpcs:enable
}
}
diff --git a/test/classes/Controllers/Normalization/ThirdNormalForm/FirstStepControllerTest.php b/test/classes/Controllers/Normalization/ThirdNormalForm/FirstStepControllerTest.php
new file mode 100644
index 0000000000..dd55cef91e
--- /dev/null
+++ b/test/classes/Controllers/Normalization/ThirdNormalForm/FirstStepControllerTest.php
@@ -0,0 +1,51 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Normalization\ThirdNormalForm;
+
+use PhpMyAdmin\ConfigStorage\Relation;
+use PhpMyAdmin\Controllers\Normalization\ThirdNormalForm\FirstStepController;
+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\ThirdNormalForm\FirstStepController
+ */
+class FirstStepControllerTest extends AbstractTestCase
+{
+ public function testDefault(): void
+ {
+ $GLOBALS['db'] = 'test_db';
+ $GLOBALS['table'] = 'test_table';
+ $_POST['tables'] = ['test_table'];
+
+ $dbiDummy = $this->createDbiDummy();
+ $dbiDummy->addSelectDb('test_db');
+
+ $dbi = $this->createDatabaseInterface($dbiDummy);
+ $GLOBALS['dbi'] = $dbi;
+ $response = new ResponseRenderer();
+ $template = new Template();
+
+ $controller = new FirstStepController(
+ $response,
+ $template,
+ new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
+ );
+ $controller($this->createStub(ServerRequest::class));
+
+ // phpcs:disable Generic.Files.LineLength.TooLong
+ $this->assertSame([
+ 'legendText' => 'Step 3.1 Find transitive dependencies',
+ 'headText' => 'Please answer the following question(s) carefully to obtain a correct normalization.',
+ 'subText' => 'For each column below, please select the <b>minimal set</b> of columns among given set whose values combined together are sufficient to determine the value of the column.<br>Note: A column may have no transitive dependency, in that case you don\'t have to select any.',
+ 'extra' => '<b>\'name\' depends on:</b><br><form id="td_1" data-colname="name" data-tablename="test_table" class="smallIndent"><input type="checkbox" name="pd" value="name"><span>name</span><input type="checkbox" name="pd" value="datetimefield"><span>datetimefield</span></form><br><br><b>\'datetimefield\' depends on:</b><br><form id="td_2" data-colname="datetimefield" data-tablename="test_table" class="smallIndent"><input type="checkbox" name="pd" value="name"><span>name</span><input type="checkbox" name="pd" value="datetimefield"><span>datetimefield</span></form><br><br>',
+ ], $response->getJSONResult());
+ // phpcs:enable
+ }
+}