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
path: root/test
diff options
context:
space:
mode:
authorWilliam Desportes <williamdes@wdes.fr>2021-04-30 01:06:06 +0300
committerWilliam Desportes <williamdes@wdes.fr>2021-04-30 01:09:21 +0300
commit2204ef77a0ad9b42983c7938dd62ed752871f880 (patch)
tree824e7cbd412c04f78e16a894b8eee3733bd2572f /test
parentc49bb8fa27a0cf81972fb26830b2194ebbd9f32c (diff)
parent23366b4684828770951f6087d5793fc470a73f68 (diff)
Merge branch 'QA_5_1'
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test')
-rw-r--r--test/classes/Controllers/NormalizationControllerTest.php188
-rw-r--r--test/classes/NormalizationTest.php16
-rw-r--r--test/classes/Stubs/DbiDummy.php38
-rw-r--r--test/classes/Stubs/Response.php27
4 files changed, 236 insertions, 33 deletions
diff --git a/test/classes/Controllers/NormalizationControllerTest.php b/test/classes/Controllers/NormalizationControllerTest.php
new file mode 100644
index 0000000000..900dc3d149
--- /dev/null
+++ b/test/classes/Controllers/NormalizationControllerTest.php
@@ -0,0 +1,188 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers;
+
+use PhpMyAdmin\Controllers\NormalizationController;
+use PhpMyAdmin\Tests\AbstractTestCase;
+
+use function json_encode;
+
+class NormalizationControllerTest extends AbstractTestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ parent::loadDefaultConfig();
+ parent::setLanguage();
+ parent::setTheme();
+ parent::setGlobalDbi();
+ 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
+ {
+ global $containerBuilder;
+
+ $_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';
+ $containerBuilder->setParameter('db', $GLOBALS['db']);
+ $containerBuilder->setParameter('table', $GLOBALS['table']);
+ /** @var NormalizationController $normalizationController */
+ $normalizationController = $containerBuilder->get(NormalizationController::class);
+ $normalizationController->index();
+ $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 testGetNewTables2NF(): void
+ {
+ global $containerBuilder;
+
+ $_POST['getNewTables2NF'] = 1;
+ $_POST['pd'] = json_encode([
+ 'ID, task' => [],
+ 'task' => ['timestamp'],
+ ]);
+
+ $GLOBALS['goto'] = 'index.php?route=/sql';
+ $containerBuilder->setParameter('db', $GLOBALS['db']);
+ $containerBuilder->setParameter('table', $GLOBALS['table']);
+ /** @var NormalizationController $normalizationController */
+ $normalizationController = $containerBuilder->get(NormalizationController::class);
+ $normalizationController->index();
+ $this->expectOutputString(
+ '<p><b>In order to put the original table \'test_tbl\' into Second normal'
+ . ' form we need to create the following tables:</b></p><p><input type="text" '
+ . 'name="ID, task" value="test_tbl">( <u>ID, task</u> )<p><input type="text" name="task"'
+ . ' value="table2">( <u>task</u>, timestamp )'
+ );
+ }
+
+ public function testCreateNewTables2NF(): void
+ {
+ global $containerBuilder;
+
+ $_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';
+ $containerBuilder->setParameter('db', $GLOBALS['db']);
+ $containerBuilder->setParameter('table', $GLOBALS['table']);
+ /** @var NormalizationController $normalizationController */
+ $normalizationController = $containerBuilder->get(NormalizationController::class);
+ $normalizationController->index();
+ $this->assertSame(
+ $this->getResponseJsonResult(),
+ [
+ 'legendText' => 'End of step',
+ 'headText' => '<h3>The second step of normalization is complete for table \'test_tbl\'.</h3>',
+ 'queryError' => false,
+ 'extra' => '',
+ ]
+ );
+ }
+
+ public function testCreateNewTables3NF(): void
+ {
+ global $containerBuilder;
+
+ $_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';
+ $containerBuilder->setParameter('db', $GLOBALS['db']);
+ $containerBuilder->setParameter('table', $GLOBALS['table']);
+ /** @var NormalizationController $normalizationController */
+ $normalizationController = $containerBuilder->get(NormalizationController::class);
+ $normalizationController->index();
+ $this->assertSame(
+ $this->getResponseJsonResult(),
+ [
+ 'legendText' => 'End of step',
+ 'headText' => '<h3>The third step of normalization is complete.</h3>',
+ 'queryError' => false,
+ 'extra' => '',
+ ]
+ );
+ }
+}
diff --git a/test/classes/NormalizationTest.php b/test/classes/NormalizationTest.php
index 0c0bfb1410..92f68bf40d 100644
--- a/test/classes/NormalizationTest.php
+++ b/test/classes/NormalizationTest.php
@@ -405,16 +405,16 @@ class NormalizationTest extends AbstractTestCase
public function testCreateNewTablesFor3NF(): void
{
$db = 'PMA_db';
- $cols = new stdClass();
- $cols->pk = 'id';
- $cols->nonpk = 'col1, col2';
- $cols1 = new stdClass();
- $cols1->pk = 'col2';
- $cols1->nonpk = 'col3, col4';
$newTables = [
'PMA_table' => [
- 'PMA_table' => $cols,
- 'table1' => $cols1,
+ 'PMA_table' => [
+ 'pk' => 'id',
+ 'nonpk' => 'col1, col2',
+ ],
+ 'table1' => [
+ 'pk' => 'col2',
+ 'nonpk' => 'col3, col4',
+ ],
],
];
$result = $this->normalization->createNewTablesFor3NF(
diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php
index d16350b13f..73f3ccc1d5 100644
--- a/test/classes/Stubs/DbiDummy.php
+++ b/test/classes/Stubs/DbiDummy.php
@@ -2608,6 +2608,44 @@ class DbiDummy implements DbiExtension
[42],
],
],
+ [
+ 'query' => 'CREATE TABLE `event` SELECT DISTINCT `eventID`, `Start_time`,'
+ . ' `DateOfEvent`, `NumberOfGuests`, `NameOfVenue`, `LocationOfVenue` FROM `test_tbl`;',
+ 'result' => [],
+ ],
+ [
+ 'query' => 'ALTER TABLE `event` ADD PRIMARY KEY(`eventID`);',
+ 'result' => [],
+ ],
+ [
+ 'query' => 'CREATE TABLE `table2` SELECT DISTINCT `Start_time`,'
+ . ' `TypeOfEvent`, `period` FROM `test_tbl`;',
+ 'result' => [],
+ ],
+ [
+ 'query' => 'ALTER TABLE `table2` ADD PRIMARY KEY(`Start_time`);',
+ 'result' => [],
+ ],
+ [
+ 'query' => 'DROP TABLE `test_tbl`',
+ 'result' => [],
+ ],
+ [
+ 'query' => 'CREATE TABLE `batch_log2` SELECT DISTINCT `ID`, `task` FROM `test_tbl`;',
+ 'result' => [],
+ ],
+ [
+ 'query' => 'ALTER TABLE `batch_log2` ADD PRIMARY KEY(`ID`, `task`);',
+ 'result' => [],
+ ],
+ [
+ 'query' => 'CREATE TABLE `table2` SELECT DISTINCT `task`, `timestamp` FROM `test_tbl`;',
+ 'result' => [],
+ ],
+ [
+ 'query' => 'ALTER TABLE `table2` ADD PRIMARY KEY(`task`);',
+ 'result' => [],
+ ],
];
/**
* Current database.
diff --git a/test/classes/Stubs/Response.php b/test/classes/Stubs/Response.php
index 71fd24b30e..62051489f8 100644
--- a/test/classes/Stubs/Response.php
+++ b/test/classes/Stubs/Response.php
@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Stubs;
+use PhpMyAdmin\Footer;
use PhpMyAdmin\Header;
use PhpMyAdmin\Message;
@@ -19,14 +20,6 @@ use function is_array;
class Response extends \PhpMyAdmin\Response
{
/**
- * PhpMyAdmin\Header instance
- *
- * @access private
- * @var Header
- */
- protected $header;
-
- /**
* HTML data to be used in the response
*
* @access private
@@ -44,23 +37,6 @@ class Response extends \PhpMyAdmin\Response
protected $json;
/**
- * Whether there were any errors during the processing of the request
- * Only used for ajax responses
- *
- * @access private
- * @var bool
- */
- protected $isSuccess;
-
- /**
- * Whether we are servicing an ajax request.
- *
- * @access private
- * @var bool
- */
- private $isAjax;
-
- /**
* Creates a new class instance
*/
public function __construct()
@@ -72,6 +48,7 @@ class Response extends \PhpMyAdmin\Response
$GLOBALS['lang'] = 'en';
$this->header = new Header();
+ $this->footer = new Footer();
}
/**