Unwind getSpecialCharsAndBackupFieldForInsertingMode()

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2023-04-20 14:24:56 +01:00
parent 9640a76556
commit 15f1fc44e7
3 changed files with 32 additions and 44 deletions

View File

@ -894,17 +894,12 @@ class InsertEdit
/**
* display default values
*
* @return mixed[] $real_null_value, $data, $special_chars
* @psalm-return array{bool, string, string}
*/
private function getSpecialCharsAndBackupFieldForInsertingMode(
private function getSpecialCharsForInsertingMode(
string|null $defaultValue,
string $trueType,
): array {
$realNullValue = false;
): string {
if ($defaultValue === null) {
$realNullValue = true;
$defaultValue = '';
}
@ -921,7 +916,7 @@ class InsertEdit
$specialChars = htmlspecialchars($defaultValue);
}
return [$realNullValue, $defaultValue, $specialChars];
return $specialChars;
}
/**
@ -1844,19 +1839,16 @@ class InsertEdit
} else {
// (we are inserting)
// display default values
$tmp = $column;
$defaultValue = $column['Default'] ?? null;
if (isset($repopulate[$fieldHashMd5])) {
$tmp['Default'] = $repopulate[$fieldHashMd5];
$defaultValue = $repopulate[$fieldHashMd5];
}
[
$realNullValue,
$data,
$specialChars,
] = $this->getSpecialCharsAndBackupFieldForInsertingMode($tmp['Default'] ?? null, $tmp['True_Type']);
$realNullValue = $defaultValue === null;
$data = (string) $defaultValue;
$specialChars = $this->getSpecialCharsForInsertingMode($defaultValue, $column['True_Type']);
$specialCharsEncoded = Util::duplicateFirstNewline($specialChars);
$backupField = '';
unset($tmp);
}
$idindex = ($oRows * $columnsCnt) + $columnNumber + 1;

View File

@ -7927,6 +7927,7 @@
<code><![CDATA[$column['True_Type']]]></code>
<code><![CDATA[$column['True_Type']]]></code>
<code><![CDATA[$column['True_Type']]]></code>
<code><![CDATA[$column['True_Type']]]></code>
<code><![CDATA[$column['Type']]]></code>
<code><![CDATA[$column['Type']]]></code>
<code><![CDATA[$column['Type']]]></code>
@ -7948,6 +7949,7 @@
<code><![CDATA[$currentRow[$column['Field']]]]></code>
<code><![CDATA[$currentRow[$column['Field']]]]></code>
<code><![CDATA[$currentRow[$column['Field']]]]></code>
<code>$defaultValue</code>
<code><![CDATA[$extractedColumnspec['enum_set_values']]]></code>
<code><![CDATA[$extractedColumnspec['spec_in_brackets']]]></code>
<code><![CDATA[$foreignData['foreign_field']]]></code>
@ -7962,8 +7964,6 @@
<code>$rows[$keyId]</code>
<code>$singleQuery</code>
<code>$singleQuery</code>
<code><![CDATA[$tmp['Default'] ?? null]]></code>
<code><![CDATA[$tmp['True_Type']]]></code>
<code><![CDATA[$transformationPlugin->getScripts()]]></code>
<code><![CDATA[$transformation[$type . '_options'] ?? '']]></code>
<code>$whereClause</code>
@ -8026,6 +8026,8 @@
<code><![CDATA[$currentRow[$column['Field']]]]></code>
<code>$currentValue</code>
<code>$data</code>
<code>$defaultValue</code>
<code>$defaultValue</code>
<code>$enumSelectedValue</code>
<code>$enumValue</code>
<code>$fieldsize</code>
@ -8036,7 +8038,6 @@
<code>$setSelectSize</code>
<code>$singleQuery</code>
<code>$specialChars</code>
<code><![CDATA[$tmp['Default']]]></code>
<code>$transformedHtml</code>
<code>$whereClause</code>
<code>$whereClause</code>

View File

@ -1162,26 +1162,26 @@ class InsertEditTest extends AbstractTestCase
}
/**
* Test for getSpecialCharsAndBackupFieldForInsertingMode
* Test for getSpecialCharsForInsertingMode
*
* @param array $column Column parameters
* @param array $expected Expected result
* @param array $column Column parameters
* @param string $expected Expected result
* @psalm-param array<string, string|bool|null> $column
* @psalm-param array<bool|string> $expected
*
* @dataProvider providerForTestGetSpecialCharsAndBackupFieldForInsertingMode
* @dataProvider providerForTestGetSpecialCharsForInsertingMode
*/
public function testGetSpecialCharsAndBackupFieldForInsertingMode(
public function testGetSpecialCharsForInsertingMode(
array $column,
array $expected,
string $expected,
): void {
$GLOBALS['cfg']['ProtectBinary'] = false;
$GLOBALS['cfg']['ShowFunctionFields'] = true;
$result = (array) $this->callFunction(
/** @var string $result */
$result = $this->callFunction(
$this->insertEdit,
InsertEdit::class,
'getSpecialCharsAndBackupFieldForInsertingMode',
'getSpecialCharsForInsertingMode',
[$column['Default'] ?? null, $column['True_Type']],
);
@ -1189,46 +1189,41 @@ class InsertEditTest extends AbstractTestCase
}
/**
* Data provider for test getSpecialCharsAndBackupFieldForInsertingMode()
* Data provider for test getSpecialCharsForInsertingMode()
*
* @return array<string, array{array<string, string|bool|null>, array<bool|string>}>
* @return array<string, array{array<string, string|bool|null>, string}>
*/
public static function providerForTestGetSpecialCharsAndBackupFieldForInsertingMode(): array
public static function providerForTestGetSpecialCharsForInsertingMode(): array
{
return [
'bit' => [
['True_Type' => 'bit', 'Default' => 'b\'101\'', 'is_binary' => true],
[false, 'b\'101\'', '101', '101'],
'101',
],
'char' => [['True_Type' => 'char', 'is_binary' => true], [true, '', '', '']],
'char' => [['True_Type' => 'char', 'is_binary' => true], ''],
'time with CURRENT_TIMESTAMP value' => [
['True_Type' => 'time', 'Default' => 'CURRENT_TIMESTAMP'],
[false, 'CURRENT_TIMESTAMP', 'CURRENT_TIMESTAMP', 'CURRENT_TIMESTAMP'],
'CURRENT_TIMESTAMP',
],
'time with current_timestamp() value' => [
['True_Type' => 'time', 'Default' => 'current_timestamp()'],
[false, 'current_timestamp()', 'current_timestamp()', 'current_timestamp()'],
'current_timestamp()',
],
'time with no dot value' => [
['True_Type' => 'time', 'Default' => '10'],
[false, '10', '10.000000', '10.000000'],
'10.000000',
],
'time with dot value' => [
['True_Type' => 'time', 'Default' => '10.08'],
[false, '10.08', '10.080000', '10.080000'],
'10.080000',
],
'any text with escape text default' => [
['True_Type' => 'text', 'Default' => '"lorem\"ipsem"'],
[false, '"lorem\"ipsem"', 'lorem"ipsem', 'lorem"ipsem'],
'lorem"ipsem',
],
'varchar with html special chars' => [
['True_Type' => 'varchar', 'Default' => 'hello world<br><b>lorem</b> ipsem'],
[
false,
'hello world<br><b>lorem</b> ipsem',
'hello world&lt;br&gt;&lt;b&gt;lorem&lt;/b&gt; ipsem',
'hello world&lt;br&gt;&lt;b&gt;lorem&lt;/b&gt; ipsem',
],
'hello world&lt;br&gt;&lt;b&gt;lorem&lt;/b&gt; ipsem',
],
];
}