Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract normalization 1NF step 3 action
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
- Loading branch information
1 parent
6e8600f
commit 08297d9
Showing
6 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
libraries/classes/Controllers/Normalization/FirstNormalForm/ThirdStepController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Normalization\FirstNormalForm; | ||
|
||
use PhpMyAdmin\Controllers\AbstractController; | ||
use PhpMyAdmin\Http\ServerRequest; | ||
use PhpMyAdmin\Normalization; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Template; | ||
|
||
final class ThirdStepController 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 | ||
{ | ||
$res = $this->normalization->getHtmlContentsFor1NFStep3($GLOBALS['db'], $GLOBALS['table']); | ||
$this->response->addJSON($res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/classes/Controllers/Normalization/FirstNormalForm/ThirdStepControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Tests\Controllers\Normalization\FirstNormalForm; | ||
|
||
use PhpMyAdmin\ConfigStorage\Relation; | ||
use PhpMyAdmin\Controllers\Normalization\FirstNormalForm\ThirdStepController; | ||
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\FirstNormalForm\ThirdStepController | ||
*/ | ||
class ThirdStepControllerTest 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 ThirdStepController( | ||
$response, | ||
$template, | ||
new Normalization($dbi, new Relation($dbi), new Transformations(), $template) | ||
); | ||
$controller($this->createStub(ServerRequest::class)); | ||
|
||
// phpcs:disable Generic.Files.LineLength.TooLong | ||
$this->assertSame([ | ||
'legendText' => 'Step 1.3 Move repeating groups', | ||
'headText' => 'Do you have a group of two or more columns that are closely related and are all repeating the same attribute? For example, a table that holds data on books might have columns such as book_id, author1, author2, author3 and so on which form a repeating group. In this case a new table (book_id, author) should be created.', | ||
'subText' => 'Check the columns which form a repeating group. If no such group, click on \'No repeating group\'', | ||
'extra' => '<input type="checkbox" value="id">id [ int(11) ]<br><input type="checkbox" value="name">name [ varchar(20) ]<br><input type="checkbox" value="datetimefield">datetimefield [ datetime ]<br><br><input class="btn btn-secondary" type="submit" id="moveRepeatingGroup" value="Done"><input class="btn btn-secondary" type="submit" value="No repeating group" onclick="goToStep4();">', | ||
'primary_key' => '["id"]', | ||
], $response->getJSONResult()); | ||
// phpcs:enable | ||
} | ||
} |