phpmyadmin/test/classes/Controllers/Normalization/ThirdNormalForm/NewTablesControllerTest.php
Maurício Meneghini Fauth b92e95d062
Extract normalization 3NF new tables action
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2022-08-02 11:22:56 -03:00

83 lines
2.9 KiB
PHP

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