Merge pull request #17671 from MauricioFauth/normalization

Extract actions from NormalizationController class
This commit is contained in:
Maurício Meneghini Fauth 2022-08-03 07:26:07 -03:00 committed by GitHub
commit d51eadcae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 970 additions and 429 deletions

View File

@ -18,13 +18,12 @@ var dataParsed = null;
function appendHtmlColumnsList () {
$.post(
'index.php?route=/normalization',
'index.php?route=/normalization/get-columns',
{
'ajax_request': true,
'db': window.CommonParams.get('db'),
'table': window.CommonParams.get('table'),
'server': window.CommonParams.get('server'),
'getColumns': true
},
function (data) {
if (data.success === true) {
@ -220,11 +219,11 @@ function goTo2NFFinish (pd) {
'table': window.CommonParams.get('table'),
'server': window.CommonParams.get('server'),
'pd': JSON.stringify(pd),
'newTablesName':JSON.stringify(tables),
'createNewTables2NF':1 };
'newTablesName': JSON.stringify(tables),
};
$.ajax({
type: 'POST',
url: 'index.php?route=/normalization',
url: 'index.php?route=/normalization/2nf/create-new-tables',
data: datastring,
async:false,
success: function (data) {
@ -265,11 +264,11 @@ function goTo3NFFinish (newTables) {
'ajax_request': true,
'db': window.CommonParams.get('db'),
'server': window.CommonParams.get('server'),
'newTables':JSON.stringify(newTables),
'createNewTables3NF':1 };
'newTables': JSON.stringify(newTables),
};
$.ajax({
type: 'POST',
url: 'index.php?route=/normalization',
url: 'index.php?route=/normalization/3nf/create-new-tables',
data: datastring,
async:false,
success: function (data) {
@ -366,10 +365,10 @@ function goTo3NFStep2 (pd, tablesTds) {
'tables': JSON.stringify(tablesTds),
'server': window.CommonParams.get('server'),
'pd': JSON.stringify(pd),
'getNewTables3NF':1 };
};
$.ajax({
type: 'POST',
url: 'index.php?route=/normalization',
url: 'index.php?route=/normalization/3nf/new-tables',
data: datastring,
async:false,
success: function (data) {
@ -465,7 +464,7 @@ function moveRepeatingGroup (repeatingCols) {
};
$.ajax({
type: 'POST',
url: 'index.php?route=/normalization',
url: 'index.php?route=/normalization/move-repeating-group',
data: datastring,
async:false,
success: function (data) {
@ -511,13 +510,12 @@ window.AJAX.registerOnload('normalization.js', function () {
}
var numField = $('#numField').val();
$.post(
'index.php?route=/normalization',
'index.php?route=/normalization/create-new-column',
{
'ajax_request': true,
'db': window.CommonParams.get('db'),
'table': window.CommonParams.get('table'),
'server': window.CommonParams.get('server'),
'splitColumn': true,
'numFields': numField
},
function (data) {
@ -594,13 +592,12 @@ window.AJAX.registerOnload('normalization.js', function () {
$('#extra').on('click', '#addNewPrimary', function () {
$.post(
'index.php?route=/normalization',
'index.php?route=/normalization/add-new-primary',
{
'ajax_request': true,
'db': window.CommonParams.get('db'),
'table': window.CommonParams.get('table'),
'server': window.CommonParams.get('server'),
'addNewPrimary': true
},
function (data) {
if (data.success === true) {
@ -758,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');

View File

@ -0,0 +1,41 @@
<?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;
use PhpMyAdmin\Url;
final class AddNewPrimaryController 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
{
$num_fields = 1;
$columnMeta = [
'Field' => $GLOBALS['table'] . '_id',
'Extra' => 'auto_increment',
];
$html = $this->normalization->getHtmlForCreateNewColumn(
$num_fields,
$GLOBALS['db'],
$GLOBALS['table'],
$columnMeta
);
$html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
$this->response->addHTML($html);
}
}

View File

@ -0,0 +1,35 @@
<?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;
use PhpMyAdmin\Url;
use function intval;
use function min;
final class CreateNewColumnController 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
{
$num_fields = min(4096, intval($_POST['numFields']));
$html = $this->normalization->getHtmlForCreateNewColumn($num_fields, $GLOBALS['db'], $GLOBALS['table']);
$html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
$this->response->addHTML($html);
}
}

View File

@ -0,0 +1,39 @@
<?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;
use function __;
use function _pgettext;
final class GetColumnsController 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 = '<option selected disabled>' . __('Select one…') . '</option>'
. '<option value="no_such_col">' . __('No such column') . '</option>';
//get column whose datatype falls under string category
$html .= $this->normalization->getHtmlForColumnsList(
$GLOBALS['db'],
$GLOBALS['table'],
_pgettext('string types', 'String')
);
$this->response->addHTML($html);
}
}

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Normalization;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Http\ServerRequest;
/**
* Normalization process (temporarily specific to 1NF).
*/
class MainController extends AbstractController
{
public function __invoke(ServerRequest $request): void
{
$this->addScriptFiles(['normalization.js', 'vendor/jquery/jquery.uitablefilter.js']);
$this->render('table/normalization/normalization', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
]);
}
}

View File

@ -0,0 +1,40 @@
<?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 MoveRepeatingGroup 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
{
$repeatingColumns = $_POST['repeatingColumns'];
$newTable = $_POST['newTable'];
$newColumn = $_POST['newColumn'];
$primary_columns = $_POST['primary_columns'];
$res = $this->normalization->moveRepeatingGroup(
$repeatingColumns,
$primary_columns,
$newTable,
$newColumn,
$GLOBALS['table'],
$GLOBALS['db']
);
$this->response->addJSON($res);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Normalization\SecondNormalForm;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Normalization;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use function json_decode;
final class CreateNewTablesController 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
{
$partialDependencies = json_decode($_POST['pd'], true);
$tablesName = json_decode($_POST['newTablesName']);
$res = $this->normalization->createNewTablesFor2NF(
$partialDependencies,
$tablesName,
$GLOBALS['table'],
$GLOBALS['db']
);
$this->response->addJSON($res);
}
}

View File

@ -0,0 +1,32 @@
<?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;
use function json_decode;
final class CreateNewTablesController 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
{
$newtables = json_decode($_POST['newTables'], true);
$res = $this->normalization->createNewTablesFor3NF($newtables, $GLOBALS['db']);
$this->response->addJSON($res);
}
}

View File

@ -0,0 +1,33 @@
<?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;
use function json_decode;
final class NewTablesController 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
{
$dependencies = json_decode($_POST['pd']);
$tables = json_decode($_POST['tables'], true);
$newTables = $this->normalization->getHtmlForNewTables3NF($dependencies, $tables, $GLOBALS['db']);
$this->response->addJSON($newTables);
}
}

View File

@ -1,143 +0,0 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\Core;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Normalization;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use function __;
use function _pgettext;
use function intval;
use function json_decode;
use function json_encode;
use function min;
/**
* Normalization process (temporarily specific to 1NF).
*/
class NormalizationController 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['getColumns'])) {
$html = '<option selected disabled>' . __('Select one…') . '</option>'
. '<option value="no_such_col">' . __('No such column') . '</option>';
//get column whose datatype falls under string category
$html .= $this->normalization->getHtmlForColumnsList(
$GLOBALS['db'],
$GLOBALS['table'],
_pgettext('string types', 'String')
);
echo $html;
return;
}
if (isset($_POST['splitColumn'])) {
$num_fields = min(4096, intval($_POST['numFields']));
$html = $this->normalization->getHtmlForCreateNewColumn($num_fields, $GLOBALS['db'], $GLOBALS['table']);
$html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
echo $html;
return;
}
if (isset($_POST['addNewPrimary'])) {
$num_fields = 1;
$columnMeta = [
'Field' => $GLOBALS['table'] . '_id',
'Extra' => 'auto_increment',
];
$html = $this->normalization->getHtmlForCreateNewColumn(
$num_fields,
$GLOBALS['db'],
$GLOBALS['table'],
$columnMeta
);
$html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
echo $html;
return;
}
if (isset($_POST['findPdl'])) {
$html = $this->normalization->findPartialDependencies($GLOBALS['table'], $GLOBALS['db']);
echo $html;
return;
}
if (isset($_POST['getNewTables3NF'])) {
$dependencies = json_decode($_POST['pd']);
$tables = json_decode($_POST['tables'], true);
$newTables = $this->normalization->getHtmlForNewTables3NF($dependencies, $tables, $GLOBALS['db']);
$this->response->disable();
Core::headerJSON();
echo json_encode($newTables);
return;
}
$this->addScriptFiles(['normalization.js', 'vendor/jquery/jquery.uitablefilter.js']);
if (isset($_POST['createNewTables2NF'])) {
$partialDependencies = json_decode($_POST['pd'], true);
$tablesName = json_decode($_POST['newTablesName']);
$res = $this->normalization->createNewTablesFor2NF(
$partialDependencies,
$tablesName,
$GLOBALS['table'],
$GLOBALS['db']
);
$this->response->addJSON($res);
return;
}
if (isset($_POST['createNewTables3NF'])) {
$newtables = json_decode($_POST['newTables'], true);
$res = $this->normalization->createNewTablesFor3NF($newtables, $GLOBALS['db']);
$this->response->addJSON($res);
return;
}
if (isset($_POST['repeatingColumns'])) {
$repeatingColumns = $_POST['repeatingColumns'];
$newTable = $_POST['newTable'];
$newColumn = $_POST['newColumn'];
$primary_columns = $_POST['primary_columns'];
$res = $this->normalization->moveRepeatingGroup(
$repeatingColumns,
$primary_columns,
$newTable,
$newColumn,
$GLOBALS['table'],
$GLOBALS['db']
);
$this->response->addJSON($res);
return;
}
$this->render('table/normalization/normalization', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
]);
}
}

View File

@ -22,7 +22,6 @@ use PhpMyAdmin\Controllers\LintController;
use PhpMyAdmin\Controllers\LogoutController;
use PhpMyAdmin\Controllers\NavigationController;
use PhpMyAdmin\Controllers\Normalization;
use PhpMyAdmin\Controllers\NormalizationController;
use PhpMyAdmin\Controllers\PhpInfoController;
use PhpMyAdmin\Controllers\Preferences;
use PhpMyAdmin\Controllers\RecentTablesListController;
@ -131,14 +130,22 @@ return static function (RouteCollector $routes): void {
$routes->addRoute(['GET', 'POST'], '/logout', LogoutController::class);
$routes->addRoute(['GET', 'POST'], '/navigation', NavigationController::class);
$routes->addGroup('/normalization', static function (RouteCollector $routes): void {
$routes->addRoute(['GET', 'POST'], '', NormalizationController::class);
$routes->addRoute(['GET', 'POST'], '', Normalization\MainController::class);
$routes->post('/1nf/step1', Normalization\FirstNormalForm\FirstStepController::class);
$routes->post('/1nf/step2', Normalization\FirstNormalForm\SecondStepController::class);
$routes->post('/1nf/step3', Normalization\FirstNormalForm\ThirdStepController::class);
$routes->post('/1nf/step4', Normalization\FirstNormalForm\FourthStepController::class);
$routes->post('/2nf/create-new-tables', Normalization\SecondNormalForm\CreateNewTablesController::class);
$routes->post('/2nf/new-tables', Normalization\SecondNormalForm\NewTablesController::class);
$routes->post('/2nf/step1', Normalization\SecondNormalForm\FirstStepController::class);
$routes->post('/3nf/create-new-tables', Normalization\ThirdNormalForm\CreateNewTablesController::class);
$routes->post('/3nf/new-tables', Normalization\ThirdNormalForm\NewTablesController::class);
$routes->post('/3nf/step1', Normalization\ThirdNormalForm\FirstStepController::class);
$routes->post('/add-new-primary', Normalization\AddNewPrimaryController::class);
$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 {

View File

@ -22,7 +22,6 @@ use PhpMyAdmin\Controllers\LintController;
use PhpMyAdmin\Controllers\LogoutController;
use PhpMyAdmin\Controllers\NavigationController;
use PhpMyAdmin\Controllers\Normalization;
use PhpMyAdmin\Controllers\NormalizationController;
use PhpMyAdmin\Controllers\PhpInfoController;
use PhpMyAdmin\Controllers\Preferences;
use PhpMyAdmin\Controllers\RecentTablesListController;
@ -617,6 +616,14 @@ return [
'$normalization' => '@normalization',
],
],
Normalization\SecondNormalForm\CreateNewTablesController::class => [
'class' => Normalization\SecondNormalForm\CreateNewTablesController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$normalization' => '@normalization',
],
],
Normalization\SecondNormalForm\FirstStepController::class => [
'class' => Normalization\SecondNormalForm\FirstStepController::class,
'arguments' => [
@ -633,6 +640,14 @@ return [
'$normalization' => '@normalization',
],
],
Normalization\ThirdNormalForm\CreateNewTablesController::class => [
'class' => Normalization\ThirdNormalForm\CreateNewTablesController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$normalization' => '@normalization',
],
],
Normalization\ThirdNormalForm\FirstStepController::class => [
'class' => Normalization\ThirdNormalForm\FirstStepController::class,
'arguments' => [
@ -641,8 +656,52 @@ return [
'$normalization' => '@normalization',
],
],
NormalizationController::class => [
'class' => NormalizationController::class,
Normalization\ThirdNormalForm\NewTablesController::class => [
'class' => Normalization\ThirdNormalForm\NewTablesController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$normalization' => '@normalization',
],
],
Normalization\AddNewPrimaryController::class => [
'class' => Normalization\AddNewPrimaryController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$normalization' => '@normalization',
],
],
Normalization\CreateNewColumnController::class => [
'class' => Normalization\CreateNewColumnController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$normalization' => '@normalization',
],
],
Normalization\GetColumnsController::class => [
'class' => Normalization\GetColumnsController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$normalization' => '@normalization',
],
],
Normalization\MainController::class => [
'class' => Normalization\MainController::class,
'arguments' => ['$response' => '@response', '$template' => '@template'],
],
Normalization\MoveRepeatingGroup::class => [
'class' => Normalization\MoveRepeatingGroup::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$normalization' => '@normalization',
],
],
Normalization\PartialDependenciesController::class => [
'class' => Normalization\PartialDependenciesController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',

View File

@ -1220,35 +1220,35 @@ parameters:
count: 1
path: libraries/classes/Controllers/HomeController.php
-
message: "#^Parameter \\#1 \\$partialDependencies of method PhpMyAdmin\\\\Normalization\\:\\:createNewTablesFor2NF\\(\\) expects array, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Normalization/SecondNormalForm/CreateNewTablesController.php
-
message: "#^Parameter \\#2 \\$tablesName of method PhpMyAdmin\\\\Normalization\\:\\:createNewTablesFor2NF\\(\\) expects object, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Normalization/SecondNormalForm/CreateNewTablesController.php
-
message: "#^Parameter \\#1 \\$partialDependencies of method PhpMyAdmin\\\\Normalization\\:\\:getHtmlForNewTables2NF\\(\\) expects array, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Normalization/SecondNormalForm/NewTablesController.php
-
message: "#^Parameter \\#1 \\$dependencies of method PhpMyAdmin\\\\Normalization\\:\\:getHtmlForNewTables3NF\\(\\) expects object, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/NormalizationController.php
-
message: "#^Parameter \\#1 \\$newTables of method PhpMyAdmin\\\\Normalization\\:\\:createNewTablesFor3NF\\(\\) expects array, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/NormalizationController.php
path: libraries/classes/Controllers/Normalization/ThirdNormalForm/CreateNewTablesController.php
-
message: "#^Parameter \\#1 \\$partialDependencies of method PhpMyAdmin\\\\Normalization\\:\\:createNewTablesFor2NF\\(\\) expects array, mixed given\\.$#"
message: "#^Parameter \\#1 \\$dependencies of method PhpMyAdmin\\\\Normalization\\:\\:getHtmlForNewTables3NF\\(\\) expects object, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/NormalizationController.php
path: libraries/classes/Controllers/Normalization/ThirdNormalForm/NewTablesController.php
-
message: "#^Parameter \\#2 \\$tables of method PhpMyAdmin\\\\Normalization\\:\\:getHtmlForNewTables3NF\\(\\) expects array, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/NormalizationController.php
-
message: "#^Parameter \\#2 \\$tablesName of method PhpMyAdmin\\\\Normalization\\:\\:createNewTablesFor2NF\\(\\) expects object, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/NormalizationController.php
path: libraries/classes/Controllers/Normalization/ThirdNormalForm/NewTablesController.php
-
message: "#^Property PhpMyAdmin\\\\Controllers\\\\Server\\\\BinlogController\\:\\:\\$binaryLogs type has no value type specified in iterable type array\\.$#"

View File

@ -2407,6 +2407,32 @@
<code>$normalForm</code>
</MixedAssignment>
</file>
<file src="libraries/classes/Controllers/Normalization/MoveRepeatingGroup.php">
<MixedArgument occurrences="4">
<code>$newColumn</code>
<code>$newTable</code>
<code>$primary_columns</code>
<code>$repeatingColumns</code>
</MixedArgument>
<MixedAssignment occurrences="4">
<code>$newColumn</code>
<code>$newTable</code>
<code>$primary_columns</code>
<code>$repeatingColumns</code>
</MixedAssignment>
</file>
<file src="libraries/classes/Controllers/Normalization/SecondNormalForm/CreateNewTablesController.php">
<MixedArgument occurrences="4">
<code>$_POST['newTablesName']</code>
<code>$_POST['pd']</code>
<code>$partialDependencies</code>
<code>$tablesName</code>
</MixedArgument>
<MixedAssignment occurrences="2">
<code>$partialDependencies</code>
<code>$tablesName</code>
</MixedAssignment>
</file>
<file src="libraries/classes/Controllers/Normalization/SecondNormalForm/NewTablesController.php">
<MixedArgument occurrences="2">
<code>$_POST['pd']</code>
@ -2416,6 +2442,15 @@
<code>$partialDependencies</code>
</MixedAssignment>
</file>
<file src="libraries/classes/Controllers/Normalization/ThirdNormalForm/CreateNewTablesController.php">
<MixedArgument occurrences="2">
<code>$_POST['newTables']</code>
<code>$newtables</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$newtables</code>
</MixedAssignment>
</file>
<file src="libraries/classes/Controllers/Normalization/ThirdNormalForm/FirstStepController.php">
<MixedArgument occurrences="1">
<code>$tables</code>
@ -2424,33 +2459,16 @@
<code>$tables</code>
</MixedAssignment>
</file>
<file src="libraries/classes/Controllers/NormalizationController.php">
<MixedArgument occurrences="14">
<code>$_POST['newTables']</code>
<code>$_POST['newTablesName']</code>
<code>$_POST['pd']</code>
<file src="libraries/classes/Controllers/Normalization/ThirdNormalForm/NewTablesController.php">
<MixedArgument occurrences="4">
<code>$_POST['pd']</code>
<code>$_POST['tables']</code>
<code>$dependencies</code>
<code>$newColumn</code>
<code>$newTable</code>
<code>$newtables</code>
<code>$partialDependencies</code>
<code>$primary_columns</code>
<code>$repeatingColumns</code>
<code>$tables</code>
<code>$tablesName</code>
</MixedArgument>
<MixedAssignment occurrences="9">
<MixedAssignment occurrences="2">
<code>$dependencies</code>
<code>$newColumn</code>
<code>$newTable</code>
<code>$newtables</code>
<code>$partialDependencies</code>
<code>$primary_columns</code>
<code>$repeatingColumns</code>
<code>$tables</code>
<code>$tablesName</code>
</MixedAssignment>
</file>
<file src="libraries/classes/Controllers/PhpInfoController.php">

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Normalization;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Normalization\AddNewPrimaryController;
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\AddNewPrimaryController
*/
class AddNewPrimaryControllerTest extends AbstractTestCase
{
public function testDefault(): void
{
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['col_priv'] = false;
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$dbiDummy = $this->createDbiDummy();
$dbi = $this->createDatabaseInterface($dbiDummy);
$GLOBALS['dbi'] = $dbi;
$response = new ResponseRenderer();
$template = new Template();
$controller = new AddNewPrimaryController(
$response,
$template,
new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
);
$controller($this->createStub(ServerRequest::class));
$this->assertStringContainsString('<table id="table_columns"', $response->getHTMLResult());
}
}

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Normalization;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Normalization\CreateNewColumnController;
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\CreateNewColumnController
*/
class CreateNewColumnControllerTest extends AbstractTestCase
{
public function testDefault(): void
{
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['col_priv'] = false;
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$_POST['numFields'] = 1;
$dbiDummy = $this->createDbiDummy();
$dbi = $this->createDatabaseInterface($dbiDummy);
$GLOBALS['dbi'] = $dbi;
$response = new ResponseRenderer();
$template = new Template();
$controller = new CreateNewColumnController(
$response,
$template,
new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
);
$controller($this->createStub(ServerRequest::class));
$this->assertStringContainsString('<table id="table_columns"', $response->getHTMLResult());
}
}

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Normalization;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Normalization\GetColumnsController;
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\GetColumnsController
*/
class GetColumnsControllerTest extends AbstractTestCase
{
public function testDefault(): void
{
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$dbiDummy = $this->createDbiDummy();
$dbiDummy->addSelectDb('test_db');
$dbi = $this->createDatabaseInterface($dbiDummy);
$GLOBALS['dbi'] = $dbi;
$response = new ResponseRenderer();
$template = new Template();
$controller = new GetColumnsController(
$response,
$template,
new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
);
$controller($this->createStub(ServerRequest::class));
// phpcs:disable Generic.Files.LineLength.TooLong
$this->assertSame(
'<option selected disabled>Select one…</option><option value="no_such_col">No such column</option><option value="name">name [ varchar(20) ]</option>',
$response->getHTMLResult()
);
// phpcs:enable
}
}

View File

@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Normalization;
use PhpMyAdmin\Controllers\Normalization\MainController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use function in_array;
/**
* @covers \PhpMyAdmin\Controllers\Normalization\MainController
*/
class MainControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;
/** @var DbiDummy */
protected $dummyDbi;
protected function setUp(): void
{
parent::setUp();
parent::setLanguage();
parent::setTheme();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
parent::loadContainerBuilder();
parent::loadDbiIntoContainerBuilder();
$GLOBALS['server'] = 1;
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
parent::loadResponseIntoContainerBuilder();
$GLOBALS['db'] = 'my_db';
$GLOBALS['table'] = 'test_tbl';
}
public function testNormalization(): void
{
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$response = new ResponseRenderer();
$controller = new MainController($response, new Template());
$controller($this->createStub(ServerRequest::class));
$files = $response->getHeader()->getScripts()->getFiles();
$this->assertTrue(
in_array(['name' => 'normalization.js', 'fire' => 1], $files, true),
'normalization.js script was not included in the response.'
);
$this->assertTrue(
in_array(['name' => 'vendor/jquery/jquery.uitablefilter.js', 'fire' => 0], $files, true),
'vendor/jquery/jquery.uitablefilter.js script was not included in the response.'
);
$output = $response->getHTMLResult();
$this->assertStringContainsString(
'<form method="post" action="index.php?route=/normalization/1nf/step1&lang=en"'
. ' name="normalize" id="normalizeTable"',
$output
);
$this->assertStringContainsString('<input type="hidden" name="db" value="test_db">', $output);
$this->assertStringContainsString('<input type="hidden" name="table" value="test_table">', $output);
$this->assertStringContainsString('type="radio" name="normalizeTo"', $output);
$this->assertStringContainsString('id="normalizeToRadio1" value="1nf" checked>', $output);
$this->assertStringContainsString('id="normalizeToRadio2" value="2nf">', $output);
$this->assertStringContainsString('id="normalizeToRadio3" value="3nf">', $output);
}
}

View File

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Normalization;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Normalization\MoveRepeatingGroup;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\Normalization;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Transformations;
/**
* @covers \PhpMyAdmin\Controllers\Normalization\MoveRepeatingGroup
*/
class MoveRepeatingGroupTest extends AbstractTestCase
{
public function testDefault(): void
{
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$_POST['repeatingColumns'] = 'col1, col2';
$_POST['newTable'] = 'new_table';
$_POST['newColumn'] = 'new_column';
$_POST['primary_columns'] = 'id,col1';
// phpcs:disable Generic.Files.LineLength.TooLong
$dbiDummy = $this->createDbiDummy();
$dbiDummy->addSelectDb('test_db');
$dbiDummy->addResult('CREATE TABLE `new_table` SELECT `id`,`col1`,`col1` as `new_column` FROM `test_table` UNION SELECT `id`,`col1`,`col2` as `new_column` FROM `test_table`', []);
$dbiDummy->addResult('ALTER TABLE `test_table` DROP `col1`, DROP `col2`', []);
// phpcs:enable
$dbi = $this->createDatabaseInterface($dbiDummy);
$GLOBALS['dbi'] = $dbi;
$response = new ResponseRenderer();
$template = new Template();
$controller = new MoveRepeatingGroup(
$response,
$template,
new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
);
$controller($this->createStub(ServerRequest::class));
$message = Message::success('Selected repeating group has been moved to the table \'test_table\'');
$this->assertSame(['queryError' => false, 'message' => $message->getDisplay()], $response->getJSONResult());
}
}

View File

@ -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
}
}

View File

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Normalization\SecondNormalForm;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Normalization\SecondNormalForm\CreateNewTablesController;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Normalization;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Transformations;
use function json_encode;
/**
* @covers \PhpMyAdmin\Controllers\Normalization\SecondNormalForm\CreateNewTablesController
*/
class CreateNewTablesControllerTest extends AbstractTestCase
{
public function testDefault(): void
{
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$_POST['pd'] = json_encode(['ID, task' => [], 'task' => ['timestamp']]);
$_POST['newTablesName'] = json_encode(['ID, task' => 'batch_log2', 'task' => 'table2']);
$dbiDummy = $this->createDbiDummy();
$dbiDummy->addSelectDb('test_db');
$dbiDummy->addResult('CREATE TABLE `batch_log2` SELECT DISTINCT `ID`, `task` FROM `test_table`;', []);
$dbiDummy->addResult('CREATE TABLE `table2` SELECT DISTINCT `task`, `timestamp` FROM `test_table`;', []);
$dbiDummy->addResult('DROP TABLE `test_table`', []);
$dbi = $this->createDatabaseInterface($dbiDummy);
$GLOBALS['dbi'] = $dbi;
$response = new ResponseRenderer();
$template = new Template();
$controller = new CreateNewTablesController(
$response,
$template,
new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
);
$controller($this->createStub(ServerRequest::class));
$this->assertSame([
'legendText' => 'End of step',
'headText' => '<h3>The second step of normalization is complete for table \'test_table\'.</h3>',
'queryError' => false,
'extra' => '',
], $response->getJSONResult());
}
}

View File

@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Normalization\ThirdNormalForm;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Normalization\ThirdNormalForm\CreateNewTablesController;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Normalization;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Transformations;
use function json_encode;
/**
* @covers \PhpMyAdmin\Controllers\Normalization\ThirdNormalForm\CreateNewTablesController
*/
class CreateNewTablesControllerTest extends AbstractTestCase
{
public function testDefault(): void
{
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$_POST['newTables'] = json_encode([
'test_table' => [
'event' => [
'pk' => 'eventID',
'nonpk' => 'Start_time, DateOfEvent, NumberOfGuests, NameOfVenue, LocationOfVenue',
],
'table2' => ['pk' => 'Start_time', 'nonpk' => 'TypeOfEvent, period'],
],
]);
// phpcs:disable Generic.Files.LineLength.TooLong
$dbiDummy = $this->createDbiDummy();
$dbiDummy->addSelectDb('test_db');
$dbiDummy->addResult('CREATE TABLE `event` SELECT DISTINCT `eventID`, `Start_time`, `DateOfEvent`, `NumberOfGuests`, `NameOfVenue`, `LocationOfVenue` FROM `test_table`;', []);
$dbiDummy->addResult('CREATE TABLE `table2` SELECT DISTINCT `Start_time`, `TypeOfEvent`, `period` FROM `test_table`;', []);
$dbiDummy->addResult('DROP TABLE `test_table`', []);
// phpcs:enable
$dbi = $this->createDatabaseInterface($dbiDummy);
$GLOBALS['dbi'] = $dbi;
$response = new ResponseRenderer();
$template = new Template();
$controller = new CreateNewTablesController(
$response,
$template,
new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
);
$controller($this->createStub(ServerRequest::class));
$this->assertSame([
'legendText' => 'End of step',
'headText' => '<h3>The third step of normalization is complete.</h3>',
'queryError' => false,
'extra' => '',
], $response->getJSONResult());
}
}

View File

@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Normalization\ThirdNormalForm;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Normalization\ThirdNormalForm\NewTablesController;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Normalization;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Transformations;
use function json_encode;
/**
* @covers \PhpMyAdmin\Controllers\Normalization\ThirdNormalForm\NewTablesController
*/
class NewTablesControllerTest extends AbstractTestCase
{
public function testDefault(): void
{
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$_POST['tables'] = json_encode([
'test_table' => [
'event',
'event',
'event',
'event',
'NameOfVenue',
'event',
'period',
'event',
'event',
],
]);
$_POST['pd'] = json_encode([
'' => [],
'event' => [
'TypeOfEvent',
'period',
'Start_time',
'NameOfVenue',
'LocationOfVenue',
],
'NameOfVenue' => ['DateOfEvent'],
'period' => ['NumberOfGuests'],
]);
$dbi = $this->createDatabaseInterface();
$GLOBALS['dbi'] = $dbi;
$response = new ResponseRenderer();
$template = new Template();
$controller = new NewTablesController(
$response,
$template,
new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
);
$controller($this->createStub(ServerRequest::class));
// phpcs:disable Generic.Files.LineLength.TooLong
$this->assertSame([
'html' => '<p><b>In order to put the original table \'test_table\' into Third normal form we need to create the following tables:</b></p><p><input type="text" name="test_table" value="test_table">( <u>event</u>, TypeOfEvent, period, Start_time, NameOfVenue, LocationOfVenue )<p><input type="text" name="table2" value="table2">( <u>NameOfVenue</u>, DateOfEvent )<p><input type="text" name="table3" value="table3">( <u>period</u>, NumberOfGuests )',
'newTables' => [
'test_table' => [
'test_table' => [
'pk' => 'event',
'nonpk' => 'TypeOfEvent, period, Start_time, NameOfVenue, LocationOfVenue',
],
'table2' => ['pk' => 'NameOfVenue', 'nonpk' => 'DateOfEvent'],
'table3' => ['pk' => 'period', 'nonpk' => 'NumberOfGuests'],
],
],
'success' => true,
], $response->getJSONResult());
// phpcs:enable
}
}

View File

@ -1,230 +0,0 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\NormalizationController;
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;
use function json_encode;
/**
* @covers \PhpMyAdmin\Controllers\NormalizationController
*/
class NormalizationControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;
/** @var DbiDummy */
protected $dummyDbi;
protected function setUp(): void
{
parent::setUp();
parent::setLanguage();
parent::setTheme();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
parent::loadContainerBuilder();
parent::loadDbiIntoContainerBuilder();
$GLOBALS['server'] = 1;
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
parent::loadResponseIntoContainerBuilder();
$GLOBALS['db'] = 'my_db';
$GLOBALS['table'] = 'test_tbl';
}
public function testGetNewTables3NF(): void
{
$_POST['getNewTables3NF'] = 1;
$_POST['tables'] = json_encode([
'test_tbl' => [
'event',
'event',
'event',
'event',
'NameOfVenue',
'event',
'period',
'event',
'event',
],
]);
$_POST['pd'] = json_encode([
'' => [],
'event' => [
'TypeOfEvent',
'period',
'Start_time',
'NameOfVenue',
'LocationOfVenue',
],
'NameOfVenue' => ['DateOfEvent'],
'period' => ['NumberOfGuests'],
]);
$GLOBALS['goto'] = 'index.php?route=/sql';
$GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']);
$GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']);
/** @var NormalizationController $normalizationController */
$normalizationController = $GLOBALS['containerBuilder']->get(NormalizationController::class);
$normalizationController($this->createStub(ServerRequest::class));
$this->assertResponseWasSuccessfull();
$this->getResponseJsonResult();// Will echo the contents
$data = (string) json_encode(
[
'html' => '<p><b>In order to put the original table \'test_tbl\' into '
. 'Third normal form we need to create the following tables:</b>'
. '</p><p><input type="text" name="test_tbl" value="test_tbl">'
. '( <u>event</u>, TypeOfEvent, period, Start_time, NameOfVenue, LocationOfVenue )'
. '<p><input type="text" name="table2" value="table2">'
. '( <u>NameOfVenue</u>, DateOfEvent )<p><input type="text" name="table3" value="table3">'
. '( <u>period</u>, NumberOfGuests )',
'newTables' => [
'test_tbl' => [
'test_tbl' => [
'pk' => 'event',
'nonpk' => 'TypeOfEvent, period, Start_time, NameOfVenue, LocationOfVenue',
],
'table2' => [
'pk' => 'NameOfVenue',
'nonpk' => 'DateOfEvent',
],
'table3' => [
'pk' => 'period',
'nonpk' => 'NumberOfGuests',
],
],
],
'success' => true,
]
);
$this->expectOutputString($data);
}
public function testCreateNewTables2NF(): void
{
$_POST['createNewTables2NF'] = 1;
$_POST['pd'] = json_encode([
'ID, task' => [],
'task' => ['timestamp'],
]);
$_POST['newTablesName'] = json_encode([
'ID, task' => 'batch_log2',
'task' => 'table2',
]);
$GLOBALS['goto'] = 'index.php?route=/sql';
$GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']);
$GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']);
/** @var NormalizationController $normalizationController */
$normalizationController = $GLOBALS['containerBuilder']->get(NormalizationController::class);
$this->dummyDbi->addSelectDb('my_db');
$normalizationController($this->createStub(ServerRequest::class));
$this->dummyDbi->assertAllSelectsConsumed();
$this->assertResponseWasSuccessfull();
$this->assertSame(
[
'legendText' => 'End of step',
'headText' => '<h3>The second step of normalization is complete for table \'test_tbl\'.</h3>',
'queryError' => false,
'extra' => '',
],
$this->getResponseJsonResult()
);
}
public function testCreateNewTables3NF(): void
{
$_POST['createNewTables3NF'] = 1;
$_POST['newTables'] = json_encode([
'test_tbl' => [
'event' => [
'pk' => 'eventID',
'nonpk' => 'Start_time, DateOfEvent, NumberOfGuests, NameOfVenue, LocationOfVenue',
],
'table2' => [
'pk' => 'Start_time',
'nonpk' => 'TypeOfEvent, period',
],
],
]);
$GLOBALS['goto'] = 'index.php?route=/sql';
$GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']);
$GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']);
/** @var NormalizationController $normalizationController */
$normalizationController = $GLOBALS['containerBuilder']->get(NormalizationController::class);
$this->dummyDbi->addSelectDb('my_db');
$normalizationController($this->createStub(ServerRequest::class));
$this->dummyDbi->assertAllSelectsConsumed();
$this->assertResponseWasSuccessfull();
$this->assertSame(
[
'legendText' => 'End of step',
'headText' => '<h3>The third step of normalization is complete.</h3>',
'queryError' => false,
'extra' => '',
],
$this->getResponseJsonResult()
);
}
public function testNormalization(): void
{
$GLOBALS['db'] = 'test_db';
$GLOBALS['table'] = 'test_table';
$dbi = $this->createDatabaseInterface();
$response = new ResponseRenderer();
$template = new Template();
$controller = new NormalizationController(
$response,
$template,
new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
);
$controller($this->createStub(ServerRequest::class));
$files = $response->getHeader()->getScripts()->getFiles();
$this->assertTrue(
in_array(['name' => 'normalization.js', 'fire' => 1], $files, true),
'normalization.js script was not included in the response.'
);
$this->assertTrue(
in_array(['name' => 'vendor/jquery/jquery.uitablefilter.js', 'fire' => 0], $files, true),
'vendor/jquery/jquery.uitablefilter.js script was not included in the response.'
);
$output = $response->getHTMLResult();
$this->assertStringContainsString(
'<form method="post" action="index.php?route=/normalization/1nf/step1&lang=en"'
. ' name="normalize" id="normalizeTable"',
$output
);
$this->assertStringContainsString('<input type="hidden" name="db" value="test_db">', $output);
$this->assertStringContainsString('<input type="hidden" name="table" value="test_table">', $output);
$this->assertStringContainsString('type="radio" name="normalizeTo"', $output);
$this->assertStringContainsString('id="normalizeToRadio1" value="1nf" checked>', $output);
$this->assertStringContainsString('id="normalizeToRadio2" value="2nf">', $output);
$this->assertStringContainsString('id="normalizeToRadio3" value="3nf">', $output);
}
}