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:
authorWilliam Desportes <williamdes@wdes.fr>2022-10-26 13:03:45 +0300
committerWilliam Desportes <williamdes@wdes.fr>2022-10-26 13:22:38 +0300
commit25c13d667b215d6660b2f0977a40412e575b6433 (patch)
tree583bd0fb72769241b624378c4dd262c72e13de08 /test
parent35401ad4ef8d3c71fb703cc348670f48c6213d3b (diff)
parentbe57ae7ddf306d627db801f12ca62f71d214390c (diff)
Merge branch 'QA_5_2'
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test')
-rw-r--r--test/classes/Html/GeneratorTest.php82
-rw-r--r--test/classes/InsertEditTest.php183
-rw-r--r--test/classes/TableTest.php48
-rw-r--r--test/classes/UtilTest.php60
4 files changed, 371 insertions, 2 deletions
diff --git a/test/classes/Html/GeneratorTest.php b/test/classes/Html/GeneratorTest.php
index 39f3ee6b8a..255dfc639f 100644
--- a/test/classes/Html/GeneratorTest.php
+++ b/test/classes/Html/GeneratorTest.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Html;
+use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Url;
@@ -450,4 +451,85 @@ class GeneratorTest extends AbstractTestCase
Generator::getServerSSL()
);
}
+
+ /**
+ * Test for Generator::getDefaultFunctionForField
+ *
+ * @param array $field field settings
+ * @param bool $insertMode true if insert mode
+ * @param string $expected expected result
+ * @psalm-param array<string, string|bool|null> $field
+ *
+ * @dataProvider providerForTestGetDefaultFunctionForField
+ */
+ public function testGetDefaultFunctionForField(
+ array $field,
+ bool $insertMode,
+ string $expected
+ ): void {
+ $this->markTestIncomplete('Needs to be fixed');
+ $dbiStub = $this->createStub(DatabaseInterface::class);
+
+ $GLOBALS['dbi'] = $dbiStub;
+
+ $result = Generator::getDefaultFunctionForField($field, $insertMode);
+
+ $this->assertEquals($expected, $result);
+ }
+
+ /**
+ * Data provider for Generator::getDefaultFunctionForField test
+ *
+ * @return array
+ * @psalm-return array<int, array{array<string, string|bool|null>, bool, string}>
+ */
+ public function providerForTestGetDefaultFunctionForField(): array
+ {
+ return [
+ [
+ [
+ 'True_Type' => 'GEOMETRY',
+ 'first_timestamp' => false,
+ 'Extra' => null,
+ 'Key' => '',
+ 'Type' => '',
+ 'Null' => 'NO',
+ ],
+ true,
+ 'ST_GeomFromText',
+ ],
+ [
+ [
+ 'True_Type' => 'timestamp',
+ 'first_timestamp' => true,
+ 'Extra' => null,
+ 'Key' => '',
+ 'Type' => '',
+ 'Null' => 'NO',
+ ],
+ true,
+ 'NOW',
+ ],
+ [
+ [
+ 'True_Type' => 'uuid',
+ 'first_timestamp' => false,
+ 'Key' => '',
+ 'Type' => '',
+ ],
+ true,
+ '',
+ ],
+ [
+ [
+ 'True_Type' => '',
+ 'first_timestamp' => false,
+ 'Key' => 'PRI',
+ 'Type' => 'char(36)',
+ ],
+ true,
+ 'UUID',
+ ],
+ ];
+ }
}
diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php
index 88e5dfa605..0418111807 100644
--- a/test/classes/InsertEditTest.php
+++ b/test/classes/InsertEditTest.php
@@ -23,10 +23,14 @@ use ReflectionProperty;
use stdClass;
use function hash;
+use function is_object;
+use function is_scalar;
+use function is_string;
use function mb_substr;
use function md5;
use function password_verify;
use function sprintf;
+use function strval;
use const MYSQLI_PRI_KEY_FLAG;
use const MYSQLI_TYPE_DECIMAL;
@@ -574,6 +578,8 @@ class InsertEditTest extends AbstractTestCase
]
);
+ $result = $this->parseString($result);
+
$this->assertStringContainsString('title="comment&gt;"', $result);
$this->assertStringContainsString('f1&lt;', $result);
@@ -870,6 +876,8 @@ class InsertEditTest extends AbstractTestCase
]
);
+ $result = $this->parseString($result);
+
$this->assertStringContainsString(
'<textarea name="fieldsb" class="char charField" '
. 'data-maxlength="10" rows="7" cols="1" dir="abc/" '
@@ -1246,6 +1254,8 @@ class InsertEditTest extends AbstractTestCase
]
);
+ $result = $this->parseString($result);
+
$this->assertStringContainsString('<input type="hidden" name="fields_typeb" value="datetime">', $result);
// case 4: (else -> date)
@@ -1272,7 +1282,65 @@ class InsertEditTest extends AbstractTestCase
]
);
+ $result = $this->parseString($result);
+
$this->assertStringContainsString('<input type="hidden" name="fields_typeb" value="date">', $result);
+
+ // case 5: (else -> bit)
+ $column['True_Type'] = 'bit';
+ $result = $this->callFunction(
+ $this->insertEdit,
+ InsertEdit::class,
+ 'getValueColumnForOtherDatatypes',
+ [
+ $column,
+ 'defchar',
+ 'a',
+ 'b',
+ 'c',
+ 22,
+ '&lt;',
+ 12,
+ 1,
+ '/',
+ '&lt;',
+ "foo\nbar",
+ $extracted_columnspec,
+ false,
+ ]
+ );
+
+ $result = $this->parseString($result);
+
+ $this->assertStringContainsString('<input type="hidden" name="fields_typeb" value="bit">', $result);
+
+ // case 6: (else -> uuid)
+ $column['True_Type'] = 'uuid';
+ $result = $this->callFunction(
+ $this->insertEdit,
+ InsertEdit::class,
+ 'getValueColumnForOtherDatatypes',
+ [
+ $column,
+ 'defchar',
+ 'a',
+ 'b',
+ 'c',
+ 22,
+ '&lt;',
+ 12,
+ 1,
+ '/',
+ '&lt;',
+ "foo\nbar",
+ $extracted_columnspec,
+ false,
+ ]
+ );
+
+ $result = $this->parseString($result);
+
+ $this->assertStringContainsString('<input type="hidden" name="fields_typeb" value="uuid">', $result);
}
/**
@@ -1379,6 +1447,8 @@ class InsertEditTest extends AbstractTestCase
[$url_params]
);
+ $result = $this->parseString($result);
+
$this->assertStringContainsString('index.php?route=/table/change', $result);
$this->assertStringContainsString('ShowFunctionFields=1&ShowFieldTypesInDataEditView=0', $result);
@@ -1621,7 +1691,7 @@ class InsertEditTest extends AbstractTestCase
unset($column['Default']);
$column['True_Type'] = 'char';
- $result = $this->callFunction(
+ $result = (array) $this->callFunction(
$this->insertEdit,
InsertEdit::class,
'getSpecialCharsAndBackupFieldForInsertingMode',
@@ -1891,7 +1961,7 @@ class InsertEditTest extends AbstractTestCase
new Template()
);
- $result = $this->callFunction(
+ $result = (array) $this->callFunction(
$this->insertEdit,
InsertEdit::class,
'getWarningMessages',
@@ -2567,6 +2637,90 @@ class InsertEditTest extends AbstractTestCase
'',
$result
);
+
+ $this->assertEquals("'20\\'12'", $result);
+
+ $this->markTestIncomplete('Following cases need to be fixed');
+ // case 8
+ $_POST['fields']['multi_edit'][0][0] = [];
+ $result = $this->insertEdit->getCurrentValueForDifferentTypes(
+ false,
+ '0',
+ ['set'],
+ '',
+ [],
+ 0,
+ [],
+ [1],
+ [],
+ true,
+ true,
+ '',
+ 'test_table',
+ []
+ );
+
+ $this->assertEquals('NULL', $result);
+
+ // case 9
+ $result = $this->insertEdit->getCurrentValueForDifferentTypes(
+ false,
+ '0',
+ ['protected'],
+ '',
+ [],
+ 0,
+ ['a'],
+ [],
+ [1],
+ true,
+ true,
+ '',
+ 'test_table',
+ []
+ );
+
+ $this->assertEquals("''", $result);
+
+ // case 10
+ $result = $this->insertEdit->getCurrentValueForDifferentTypes(
+ false,
+ '0',
+ ['uuid'],
+ '',
+ [],
+ 0,
+ ['a'],
+ [],
+ [1],
+ true,
+ true,
+ '',
+ 'test_table',
+ []
+ );
+
+ $this->assertEquals('uuid()', $result);
+
+ // case 11
+ $result = $this->insertEdit->getCurrentValueForDifferentTypes(
+ false,
+ '0',
+ ['uuid'],
+ 'uuid()',
+ [],
+ 0,
+ ['a'],
+ [],
+ [1],
+ true,
+ true,
+ '',
+ 'test_table',
+ []
+ );
+
+ $this->assertEquals('uuid()', $result);
}
/**
@@ -2887,6 +3041,8 @@ class InsertEditTest extends AbstractTestCase
]
);
+ $actual = $this->parseString($actual);
+
$this->assertStringContainsString('col', $actual);
$this->assertStringContainsString('<option>AES_ENCRYPT</option>', $actual);
$this->assertStringContainsString('<span class="column_type" dir="ltr">varchar(20)</span>', $actual);
@@ -2944,6 +3100,9 @@ class InsertEditTest extends AbstractTestCase
'',
]
);
+
+ $actual = $this->parseString($actual);
+
$this->assertStringContainsString('qwerty', $actual);
$this->assertStringContainsString('<option>UUID</option>', $actual);
$this->assertStringContainsString('<span class="column_type" dir="ltr">datetime</span>', $actual);
@@ -3197,4 +3356,24 @@ class InsertEditTest extends AbstractTestCase
$actual
);
}
+
+ /**
+ * Convert mixed type value to string
+ *
+ * @param mixed $value
+ *
+ * @return string
+ */
+ private function parseString($value)
+ {
+ if (is_string($value)) {
+ return $value;
+ }
+
+ if (is_object($value) || is_scalar($value)) {
+ return strval($value);
+ }
+
+ return '';
+ }
}
diff --git a/test/classes/TableTest.php b/test/classes/TableTest.php
index 041d1be830..bfb642cf57 100644
--- a/test/classes/TableTest.php
+++ b/test/classes/TableTest.php
@@ -752,6 +752,54 @@ class TableTest extends AbstractTestCase
$query
);
+ //$default_type is UUID
+ $type = 'UUID';
+ $default_type = 'UUID';
+ $move_to = '';
+ $query = Table::generateFieldSpec(
+ $name,
+ $type,
+ $length,
+ $attribute,
+ $collation,
+ $null,
+ $default_type,
+ $default_value,
+ $extra,
+ '',
+ $virtuality,
+ $expression,
+ $move_to
+ );
+ $this->assertEquals(
+ '`PMA_name` UUID PMA_attribute NULL DEFAULT uuid()',
+ $query
+ );
+
+ //$default_type is uuid()
+ $type = 'UUID';
+ $default_type = 'uuid()';
+ $move_to = '';
+ $query = Table::generateFieldSpec(
+ $name,
+ $type,
+ $length,
+ $attribute,
+ $collation,
+ $null,
+ $default_type,
+ $default_value,
+ $extra,
+ '',
+ $virtuality,
+ $expression,
+ $move_to
+ );
+ $this->assertEquals(
+ '`PMA_name` UUID PMA_attribute NULL DEFAULT uuid()',
+ $query
+ );
+
//$default_type is NONE
$type = 'BOOLEAN';
$default_type = 'NONE';
diff --git a/test/classes/UtilTest.php b/test/classes/UtilTest.php
index e13d6bf7cb..728e7a682f 100644
--- a/test/classes/UtilTest.php
+++ b/test/classes/UtilTest.php
@@ -2549,4 +2549,64 @@ class UtilTest extends AbstractTestCase
$actual = Util::getDbInfo('test_db', '');
$this->assertSame($expected, $actual);
}
+
+ /**
+ * Tests for Util::testIsUUIDSupported() method.
+ *
+ * @param bool $isMariaDB True if mariadb
+ * @param int $version Database version as integer
+ * @param bool $expected Expected Result
+ *
+ * @dataProvider provideForTestIsUUIDSupported
+ */
+ public function testIsUUIDSupported(bool $isMariaDB, int $version, bool $expected): void
+ {
+ $dbi = $this->getMockBuilder(DatabaseInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dbi->expects($this->any())
+ ->method('isMariaDB')
+ ->will($this->returnValue($isMariaDB));
+
+ $dbi->expects($this->any())
+ ->method('getVersion')
+ ->will($this->returnValue($version));
+
+ $GLOBALS['dbi'] = $dbi;
+ $this->assertEquals(Util::isUUIDSupported(), $expected);
+ unset($GLOBALS['dbi']);
+ }
+
+ /**
+ * Data provider for isUUIDSupported() tests.
+ *
+ * @return array
+ * @psalm-return array<int, array{bool, int, bool}>
+ */
+ public function provideForTestIsUUIDSupported(): array
+ {
+ return [
+ [
+ false,
+ 60100,
+ false,
+ ],
+ [
+ false,
+ 100700,
+ false,
+ ],
+ [
+ true,
+ 60100,
+ false,
+ ],
+ [
+ true,
+ 100700,
+ true,
+ ],
+ ];
+ }
}