Skip to content

Commit e76adf1

Browse files
committed
Merge #20082 - [Toon Export] Fix null separator
Pull-request: #20082 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents cd76c61 + 0817747 commit e76adf1

3 files changed

Lines changed: 36 additions & 16 deletions

File tree

src/Plugins/Export/ExportToon.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,7 @@ public function exportData(
138138
$buffer .= str_repeat(' ', $this->indent);
139139
}
140140

141-
if ($col === null) {
142-
$buffer .= 'null';
143-
continue;
144-
}
145-
146-
$buffer .= $col;
141+
$buffer .= $col ?? 'null';
147142

148143
// phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
149144
if ($index !== $columnsCnt - 1) {

tests/unit/Plugins/Export/ExportToonTest.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,19 @@ public function testExportData(): void
183183
$exportToon->setExportOptions($request, new Export());
184184

185185
ob_start();
186-
$exportToon->exportData('test_db', 'test_table', 'SELECT * FROM `test_db`.`test_table`;');
186+
$exportToon->exportData(
187+
'test_db',
188+
'test_table_export_toon',
189+
'SELECT * FROM `test_db`.`test_table_export_toon`;',
190+
);
187191
$result = ob_get_clean();
188192

189193
self::assertIsString($result);
190194
self::assertSame(
191-
'test_db.test_table[3]{id,name,datetimefield}:' . "\n" .
192-
' 1,abcd,2011-01-20 02:00:02' . "\n" .
193-
' 2,foo,2010-01-20 02:00:02' . "\n" .
194-
' 3,Abcd,2012-01-20 02:00:02' . "\n\n",
195+
'test_db.test_table_export_toon[3]{id,name,datetimefield,textfield,intfield}:' . "\n" .
196+
' 1,abcd,2011-01-20 02:00:02,31,null' . "\n" .
197+
' 2,foo,2010-01-20 02:00:02,null,null' . "\n" .
198+
' 3,Abcd,2012-01-20 02:00:02,null,8' . "\n\n",
195199
$result,
196200
);
197201
}
@@ -205,15 +209,19 @@ public function testExportDataWithCustomConfig(): void
205209
$exportToon->setExportOptions($request, new Export());
206210

207211
ob_start();
208-
$exportToon->exportData('test_db', 'test_table', 'SELECT * FROM `test_db`.`test_table`;');
212+
$exportToon->exportData(
213+
'test_db',
214+
'test_table_export_toon',
215+
'SELECT * FROM `test_db`.`test_table_export_toon`;',
216+
);
209217
$result = ob_get_clean();
210218

211219
self::assertIsString($result);
212220
self::assertSame(
213-
'test_db.test_table[3|]{id|name|datetimefield}:' . "\n" .
214-
' 1|abcd|2011-01-20 02:00:02' . "\n" .
215-
' 2|foo|2010-01-20 02:00:02' . "\n" .
216-
' 3|Abcd|2012-01-20 02:00:02' . "\n\n",
221+
'test_db.test_table_export_toon[3|]{id|name|datetimefield|textfield|intfield}:' . "\n" .
222+
' 1|abcd|2011-01-20 02:00:02|31|null' . "\n" .
223+
' 2|foo|2010-01-20 02:00:02|null|null' . "\n" .
224+
' 3|Abcd|2012-01-20 02:00:02|null|8' . "\n\n",
217225
$result,
218226
);
219227
}

tests/unit/Stubs/DbiDummy.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use const MYSQLI_TYPE_BLOB;
3333
use const MYSQLI_TYPE_DATETIME;
3434
use const MYSQLI_TYPE_DECIMAL;
35+
use const MYSQLI_TYPE_INT24;
3536
use const MYSQLI_TYPE_STRING;
3637

3738
// phpcs:disable Generic.Files.LineLength.TooLong
@@ -1730,6 +1731,22 @@ private function init(): void
17301731
['5', 'Abcd', '2012-01-20 02:00:02', '+30.2103210000'],
17311732
],
17321733
],
1734+
[
1735+
'query' => 'SELECT * FROM `test_db`.`test_table_export_toon`;',
1736+
'columns' => ['id', 'name', 'datetimefield', 'textfield', 'intfield'],
1737+
'metadata' => [
1738+
FieldHelper::fromArray(['type' => MYSQLI_TYPE_DECIMAL]),
1739+
FieldHelper::fromArray(['type' => MYSQLI_TYPE_STRING]),
1740+
FieldHelper::fromArray(['type' => MYSQLI_TYPE_DATETIME]),
1741+
FieldHelper::fromArray(['type' => MYSQLI_TYPE_STRING]),
1742+
FieldHelper::fromArray(['type' => MYSQLI_TYPE_INT24]),
1743+
],
1744+
'result' => [
1745+
['1', 'abcd', '2011-01-20 02:00:02',31,null],
1746+
['2', 'foo', '2010-01-20 02:00:02',null,null],
1747+
['3', 'Abcd', '2012-01-20 02:00:02',null,8],
1748+
],
1749+
],
17331750
[
17341751
'query' => 'SELECT * FROM `test_db`.`test_table`;',
17351752
'columns' => ['id', 'name', 'datetimefield'],

0 commit comments

Comments
 (0)