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>2021-09-09 19:48:07 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2021-09-09 19:48:07 +0300
commitfb257e5922169484487b69e002816aa2b75ac71c (patch)
tree58e6d5207e45e8e3d301f357d0713f4c51bea841 /test
parente3554879ef7a4879446db25669563df004f832a2 (diff)
Extract actions from Table\StructureController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r--test/classes/Controllers/Table/Structure/ChangeControllerTest.php60
-rw-r--r--test/classes/Controllers/Table/Structure/SaveControllerTest.php49
-rw-r--r--test/classes/Controllers/Table/StructureControllerTest.php240
3 files changed, 109 insertions, 240 deletions
diff --git a/test/classes/Controllers/Table/Structure/ChangeControllerTest.php b/test/classes/Controllers/Table/Structure/ChangeControllerTest.php
new file mode 100644
index 0000000000..0f9bb7c29c
--- /dev/null
+++ b/test/classes/Controllers/Table/Structure/ChangeControllerTest.php
@@ -0,0 +1,60 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Table\Structure;
+
+use PhpMyAdmin\Controllers\Table\Structure\ChangeController;
+use PhpMyAdmin\Relation;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseStub;
+use PhpMyAdmin\Transformations;
+use ReflectionClass;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Table\Structure\ChangeController
+ */
+class ChangeControllerTest extends AbstractTestCase
+{
+ public function testChangeController(): void
+ {
+ $GLOBALS['server'] = 1;
+ $GLOBALS['text_dir'] = 'ltr';
+ $GLOBALS['PMA_PHP_SELF'] = 'index.php';
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['db'] = 'testdb';
+ $GLOBALS['table'] = 'mytable';
+ $_REQUEST['field'] = '_id';
+
+ $response = new ResponseStub();
+ $template = new Template();
+
+ $class = new ReflectionClass(ChangeController::class);
+ $method = $class->getMethod('displayHtmlForColumnChange');
+ $method->setAccessible(true);
+
+ $ctrl = new ChangeController(
+ $response,
+ $template,
+ $GLOBALS['db'],
+ $GLOBALS['table'],
+ new Relation($this->dbi, $template),
+ new Transformations(),
+ $this->dbi
+ );
+
+ $method->invokeArgs($ctrl, [null]);
+ $this->assertStringContainsString(
+ '<input id="field_0_1"' . "\n"
+ . ' type="text"' . "\n"
+ . ' name="field_name[0]"' . "\n"
+ . ' maxlength="64"' . "\n"
+ . ' class="textfield"' . "\n"
+ . ' title="Column"' . "\n"
+ . ' size="10"' . "\n"
+ . ' value="_id">' . "\n",
+ $response->getHTMLResult()
+ );
+ }
+}
diff --git a/test/classes/Controllers/Table/Structure/SaveControllerTest.php b/test/classes/Controllers/Table/Structure/SaveControllerTest.php
new file mode 100644
index 0000000000..53fe39b3fe
--- /dev/null
+++ b/test/classes/Controllers/Table/Structure/SaveControllerTest.php
@@ -0,0 +1,49 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Table\Structure;
+
+use PhpMyAdmin\Controllers\Table\Structure\SaveController;
+use PhpMyAdmin\Controllers\Table\StructureController;
+use PhpMyAdmin\Relation;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseStub;
+use PhpMyAdmin\Transformations;
+use ReflectionClass;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Table\Structure\SaveController
+ */
+class SaveControllerTest extends AbstractTestCase
+{
+ public function testSaveController(): void
+ {
+ $GLOBALS['server'] = 1;
+ $GLOBALS['text_dir'] = 'ltr';
+ $GLOBALS['PMA_PHP_SELF'] = 'index.php';
+ $GLOBALS['db'] = 'db';
+ $GLOBALS['table'] = 'table';
+
+ $class = new ReflectionClass(SaveController::class);
+ $method = $class->getMethod('adjustColumnPrivileges');
+ $method->setAccessible(true);
+
+ $template = new Template();
+ $ctrl = new SaveController(
+ new ResponseStub(),
+ $template,
+ $GLOBALS['db'],
+ $GLOBALS['table'],
+ new Relation($this->dbi, $template),
+ new Transformations(),
+ $this->dbi,
+ $this->createStub(StructureController::class)
+ );
+
+ $this->assertFalse(
+ $method->invokeArgs($ctrl, [[]])
+ );
+ }
+}
diff --git a/test/classes/Controllers/Table/StructureControllerTest.php b/test/classes/Controllers/Table/StructureControllerTest.php
deleted file mode 100644
index 13c033a67a..0000000000
--- a/test/classes/Controllers/Table/StructureControllerTest.php
+++ /dev/null
@@ -1,240 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace PhpMyAdmin\Tests\Controllers\Table;
-
-use PhpMyAdmin\Controllers\Table\StructureController;
-use PhpMyAdmin\CreateAddField;
-use PhpMyAdmin\DatabaseInterface;
-use PhpMyAdmin\FlashMessages;
-use PhpMyAdmin\Relation;
-use PhpMyAdmin\RelationCleanup;
-use PhpMyAdmin\Table;
-use PhpMyAdmin\Template;
-use PhpMyAdmin\Tests\AbstractTestCase;
-use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseStub;
-use PhpMyAdmin\Transformations;
-use ReflectionClass;
-
-/**
- * @covers \PhpMyAdmin\Controllers\Table\StructureController
- */
-class StructureControllerTest extends AbstractTestCase
-{
- /** @var ResponseStub */
- private $response;
-
- /** @var Template */
- private $template;
-
- /**
- * Prepares environment for the test.
- */
- protected function setUp(): void
- {
- parent::setUp();
- parent::loadDefaultConfig();
- parent::setTheme();
- $GLOBALS['text_dir'] = 'ltr';
- $GLOBALS['server'] = 1;
- $GLOBALS['db'] = 'db';
- $GLOBALS['table'] = 'table';
- $GLOBALS['cfg']['Server']['DisableIS'] = false;
- $GLOBALS['cfg']['Server']['user'] = 'pma_user';
- $GLOBALS['PMA_PHP_SELF'] = 'index.php';
-
- $indexes = [
- [
- 'Schema' => 'Schema1',
- 'Key_name' => 'Key_name1',
- 'Column_name' => 'Column_name1',
- ],
- [
- 'Schema' => 'Schema2',
- 'Key_name' => 'Key_name2',
- 'Column_name' => 'Column_name2',
- ],
- [
- 'Schema' => 'Schema3',
- 'Key_name' => 'Key_name3',
- 'Column_name' => 'Column_name3',
- ],
- ];
-
- $table = $this->getMockBuilder(Table::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $dbi = $this->getMockBuilder(DatabaseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $dbi->expects($this->any())->method('getTable')
- ->will($this->returnValue($table));
- $dbi->expects($this->any())->method('getTableIndexes')
- ->will($this->returnValue($indexes));
-
- $GLOBALS['dbi'] = $dbi;
-
- $this->response = new ResponseStub();
- $this->template = new Template();
- }
-
- /**
- * Tests for getKeyForTablePrimary()
- *
- * Case one: there are no primary key in the table
- */
- public function testGetKeyForTablePrimaryOne(): void
- {
- $GLOBALS['dbi']->expects($this->any())->method('fetchAssoc')
- ->will($this->returnValue(null));
-
- $class = new ReflectionClass(StructureController::class);
- $method = $class->getMethod('getKeyForTablePrimary');
- $method->setAccessible(true);
-
- $relation = new Relation($GLOBALS['dbi'], $this->template);
- $ctrl = new StructureController(
- $this->response,
- $this->template,
- $GLOBALS['db'],
- $GLOBALS['table'],
- $relation,
- new Transformations(),
- new CreateAddField($GLOBALS['dbi']),
- new RelationCleanup($GLOBALS['dbi'], $relation),
- $GLOBALS['dbi'],
- new FlashMessages()
- );
-
- // No primary key in db.table2
- $this->assertEquals(
- '',
- $method->invoke($ctrl)
- );
- }
-
- /**
- * Tests for getKeyForTablePrimary()
- *
- * Case two: there are a primary key in the table
- */
- public function testGetKeyForTablePrimaryTwo(): void
- {
- $GLOBALS['dbi']->expects($this->any())
- ->method('fetchAssoc')
- ->will(
- $this->returnCallback(
- static function () {
- static $callCount = 0;
- if ($callCount == 0) {
- $callCount++;
-
- return [
- 'Key_name' => 'PRIMARY',
- 'Column_name' => 'column',
- ];
- }
-
- return null;
- }
- )
- );
-
- $class = new ReflectionClass(StructureController::class);
- $method = $class->getMethod('getKeyForTablePrimary');
- $method->setAccessible(true);
-
- $relation = new Relation($GLOBALS['dbi'], $this->template);
- $ctrl = new StructureController(
- $this->response,
- $this->template,
- $GLOBALS['db'],
- $GLOBALS['table'],
- $relation,
- new Transformations(),
- new CreateAddField($GLOBALS['dbi']),
- new RelationCleanup($GLOBALS['dbi'], $relation),
- $GLOBALS['dbi'],
- new FlashMessages()
- );
-
- // With db.table, it has a primary key `column`
- $this->assertEquals(
- 'column, ',
- $method->invoke($ctrl)
- );
- }
-
- /**
- * Tests for adjustColumnPrivileges()
- */
- public function testAdjustColumnPrivileges(): void
- {
- $class = new ReflectionClass(StructureController::class);
- $method = $class->getMethod('adjustColumnPrivileges');
- $method->setAccessible(true);
-
- $relation = new Relation($GLOBALS['dbi'], $this->template);
- $ctrl = new StructureController(
- $this->response,
- $this->template,
- $GLOBALS['db'],
- $GLOBALS['table'],
- $relation,
- new Transformations(),
- new CreateAddField($GLOBALS['dbi']),
- new RelationCleanup($GLOBALS['dbi'], $relation),
- $GLOBALS['dbi'],
- new FlashMessages()
- );
-
- $this->assertFalse(
- $method->invokeArgs($ctrl, [[]])
- );
- }
-
- /**
- * Tests for displayHtmlForColumnChange()
- */
- public function testDisplayHtmlForColumnChange(): void
- {
- $_REQUEST['field'] = '_id';
- $GLOBALS['db'] = 'testdb';
- $GLOBALS['table'] = 'mytable';
-
- $this->setGlobalDbi();
-
- $class = new ReflectionClass(StructureController::class);
- $method = $class->getMethod('displayHtmlForColumnChange');
- $method->setAccessible(true);
-
- $relation = new Relation($GLOBALS['dbi'], $this->template);
- $ctrl = new StructureController(
- $this->response,
- $this->template,
- $GLOBALS['db'],
- $GLOBALS['table'],
- $relation,
- new Transformations(),
- new CreateAddField($GLOBALS['dbi']),
- new RelationCleanup($GLOBALS['dbi'], $relation),
- $GLOBALS['dbi'],
- new FlashMessages()
- );
-
- $method->invokeArgs($ctrl, [null]);
- $this->assertStringContainsString(
- '<input id="field_0_1"' . "\n"
- . ' type="text"' . "\n"
- . ' name="field_name[0]"' . "\n"
- . ' maxlength="64"' . "\n"
- . ' class="textfield"' . "\n"
- . ' title="Column"' . "\n"
- . ' size="10"' . "\n"
- . ' value="_id">' . "\n",
- $this->response->getHTMLResult()
- );
- }
-}