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' => '

In order to put the original table \'test_tbl\' into ' . 'Third normal form we need to create the following tables:' . '

' . '( event, TypeOfEvent, period, Start_time, NameOfVenue, LocationOfVenue )' . '

' . '( NameOfVenue, DateOfEvent )

' . '( period, 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 { $_POST['getNewTables2NF'] = 1; $_POST['pd'] = json_encode([ 'ID, task' => [], 'task' => ['timestamp'], ]); $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->expectOutputString( '

In order to put the original table \'test_tbl\' into Second normal' . ' form we need to create the following tables:

( ID, task )

( task, timestamp )' ); } 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' => '

The second step of normalization is complete for table \'test_tbl\'.

', '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' => '

The third step of normalization is complete.

', '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( '
assertStringContainsString('', $output); $this->assertStringContainsString('', $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); } }