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:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-07-29 00:33:34 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-07-29 00:33:34 +0300
commit398bdae484ae6fdb63b7ee04db788d31c358ff40 (patch)
tree8c1d956282f124fed70f51cc681a508e50f1973a /test
parent9c9ae5069e8bda601b8fe6eabd1f7b93b2810599 (diff)
Extract normalization 1NF step 1 action
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r--test/classes/Controllers/Normalization/FirstNormalForm/FirstStepControllerTest.php82
-rw-r--r--test/classes/Controllers/NormalizationControllerTest.php4
2 files changed, 84 insertions, 2 deletions
diff --git a/test/classes/Controllers/Normalization/FirstNormalForm/FirstStepControllerTest.php b/test/classes/Controllers/Normalization/FirstNormalForm/FirstStepControllerTest.php
new file mode 100644
index 0000000000..b8869b3251
--- /dev/null
+++ b/test/classes/Controllers/Normalization/FirstNormalForm/FirstStepControllerTest.php
@@ -0,0 +1,82 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Normalization\FirstNormalForm;
+
+use PhpMyAdmin\ConfigStorage\Relation;
+use PhpMyAdmin\Controllers\Normalization\FirstNormalForm\FirstStepController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Normalization;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+use PhpMyAdmin\Transformations;
+
+use function in_array;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Normalization\FirstNormalForm\FirstStepController
+ */
+class FirstStepControllerTest extends AbstractTestCase
+{
+ /**
+ * @psalm-param '1nf'|'2nf'|'3nf' $expectedNormalizeTo
+ *
+ * @dataProvider providerForTestDefault
+ */
+ public function testDefault(?string $normalizeTo, string $expectedNormalizeTo): void
+ {
+ $GLOBALS['db'] = 'test_db';
+ $GLOBALS['table'] = 'test_table';
+ $_POST['normalizeTo'] = $normalizeTo;
+
+ $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));
+
+ $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('First step of normalization (1NF)', $output);
+ $this->assertStringContainsString(
+ '<div id=\'mainContent\' data-normalizeto=\'' . $expectedNormalizeTo . '\'>',
+ $output
+ );
+ $this->assertStringContainsString('<option value=\'no_such_col\'>No such column</option>', $output);
+ }
+
+ /**
+ * @return array<int, array{string|null, '1nf'|'2nf'|'3nf'}>
+ */
+ public function providerForTestDefault(): iterable
+ {
+ return [
+ [null, '1nf'],
+ ['', '1nf'],
+ ['invalid', '1nf'],
+ ['1nf', '1nf'],
+ ['2nf', '2nf'],
+ ['3nf', '3nf'],
+ ];
+ }
+}
diff --git a/test/classes/Controllers/NormalizationControllerTest.php b/test/classes/Controllers/NormalizationControllerTest.php
index 91630a026f..31a87b0676 100644
--- a/test/classes/Controllers/NormalizationControllerTest.php
+++ b/test/classes/Controllers/NormalizationControllerTest.php
@@ -238,12 +238,12 @@ class NormalizationControllerTest extends AbstractTestCase
$output = $response->getHTMLResult();
$this->assertStringContainsString(
- '<form method="post" action="index.php?route=/normalization&lang=en" name="normalize" id="normalizeTable"',
+ '<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('<input type="hidden" name="step1" value="1">', $output);
$this->assertStringContainsString('type="radio" name="normalizeTo"', $output);
$this->assertStringContainsString('id="normalizeToRadio1" value="1nf" checked>', $output);
$this->assertStringContainsString('id="normalizeToRadio2" value="2nf">', $output);