1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\Tests\Plugins\Import; |
6
|
|
|
|
7
|
|
|
use PhpMyAdmin\File; |
8
|
|
|
use PhpMyAdmin\Plugins\Import\ImportOds; |
9
|
|
|
use PhpMyAdmin\Tests\AbstractTestCase; |
10
|
|
|
use function str_repeat; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @requires extension zip |
14
|
|
|
*/ |
15
|
|
|
class ImportOdsTest extends AbstractTestCase |
16
|
|
|
{ |
17
|
|
|
/** @var ImportOds */ |
18
|
|
|
protected $object; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Sets up the fixture, for example, opens a network connection. |
22
|
|
|
* This method is called before a test is executed. |
23
|
|
|
* |
24
|
|
|
* @access protected |
25
|
|
|
*/ |
26
|
|
|
protected function setUp(): void |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
parent::loadDefaultConfig(); |
30
|
|
|
$GLOBALS['server'] = 0; |
31
|
|
|
$GLOBALS['plugin_param'] = 'csv'; |
32
|
|
|
$this->object = new ImportOds(); |
33
|
|
|
|
34
|
|
|
//setting |
35
|
|
|
$GLOBALS['finished'] = false; |
36
|
|
|
$GLOBALS['read_limit'] = 100000000; |
37
|
|
|
$GLOBALS['offset'] = 0; |
38
|
|
|
$GLOBALS['cfg']['Server']['DisableIS'] = false; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Load interface for zip extension. |
42
|
|
|
*/ |
43
|
|
|
$GLOBALS['read_multiply'] = 10; |
44
|
|
|
$GLOBALS['import_type'] = 'ods'; |
45
|
|
|
|
46
|
|
|
//variable for Ods |
47
|
|
|
$_REQUEST['ods_recognize_percentages'] = true; |
48
|
|
|
$_REQUEST['ods_recognize_currency'] = true; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Tears down the fixture, for example, closes a network connection. |
53
|
|
|
* This method is called after a test is executed. |
54
|
|
|
* |
55
|
|
|
* @access protected |
56
|
|
|
*/ |
57
|
|
|
protected function tearDown(): void |
58
|
|
|
{ |
59
|
|
|
parent::tearDown(); |
60
|
|
|
unset($this->object); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Test for getProperties |
65
|
|
|
* |
66
|
|
|
* @group medium |
67
|
|
|
*/ |
68
|
|
|
public function testGetProperties(): void |
69
|
|
|
{ |
70
|
|
|
$properties = $this->object->getProperties(); |
71
|
|
|
$this->assertEquals( |
72
|
|
|
__('OpenDocument Spreadsheet'), |
73
|
|
|
$properties->getText() |
74
|
|
|
); |
75
|
|
|
$this->assertEquals( |
76
|
|
|
'ods', |
77
|
|
|
$properties->getExtension() |
78
|
|
|
); |
79
|
|
|
$this->assertEquals( |
80
|
|
|
__('Options'), |
81
|
|
|
$properties->getOptionsText() |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Test for doImport |
87
|
|
|
* |
88
|
|
|
* @group medium |
89
|
|
|
*/ |
90
|
|
|
public function testDoImport(): void |
91
|
|
|
{ |
92
|
|
|
//$sql_query_disabled will show the import SQL detail |
93
|
|
|
//$import_notice will show the import detail result |
94
|
|
|
global $import_notice, $sql_query, $sql_query_disabled; |
95
|
|
|
$sql_query_disabled = false; |
96
|
|
|
|
97
|
|
|
$GLOBALS['import_file'] = 'test/test_data/db_test.ods'; |
98
|
|
|
$_REQUEST['ods_empty_rows'] = true; |
99
|
|
|
|
100
|
|
|
parent::setGlobalDbi(); |
101
|
|
|
|
102
|
|
|
$importHandle = new File($GLOBALS['import_file']); |
103
|
|
|
$importHandle->setDecompressContent(true); |
104
|
|
|
$importHandle->open(); |
105
|
|
|
|
106
|
|
|
//Test function called |
107
|
|
|
$this->object->doImport($importHandle); |
108
|
|
|
|
109
|
|
|
$this->assertStringContainsString( |
110
|
|
|
'CREATE DATABASE IF NOT EXISTS `ODS_DB` DEFAULT CHARACTER SET ' |
111
|
|
|
. 'utf8 COLLATE utf8_general_ci', |
112
|
|
|
$sql_query |
113
|
|
|
); |
114
|
|
|
$this->assertStringContainsString( |
115
|
|
|
'CREATE TABLE IF NOT EXISTS `ODS_DB`.`pma_bookmark`', |
116
|
|
|
$sql_query |
117
|
|
|
); |
118
|
|
|
$this->assertStringContainsString( |
119
|
|
|
'INSERT INTO `ODS_DB`.`pma_bookmark` (`A`, `B`, `C`, `D`) VALUES ' |
120
|
|
|
. "(1, 'dbbase', NULL, 'ddd');", |
121
|
|
|
$sql_query |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
//asset that all databases and tables are imported |
125
|
|
|
$this->assertStringContainsString( |
126
|
|
|
'The following structures have either been created or altered.', |
127
|
|
|
$import_notice |
128
|
|
|
); |
129
|
|
|
$this->assertStringContainsString( |
130
|
|
|
'Go to database: `ODS_DB`', |
131
|
|
|
$import_notice |
132
|
|
|
); |
133
|
|
|
$this->assertStringContainsString( |
134
|
|
|
'Edit settings for `ODS_DB`', |
135
|
|
|
$import_notice |
136
|
|
|
); |
137
|
|
|
$this->assertStringContainsString( |
138
|
|
|
'Go to table: `pma_bookmark`', |
139
|
|
|
$import_notice |
140
|
|
|
); |
141
|
|
|
$this->assertStringContainsString( |
142
|
|
|
'Edit settings for `pma_bookmark`', |
143
|
|
|
$import_notice |
144
|
|
|
); |
145
|
|
|
|
146
|
|
|
//asset that the import process is finished |
147
|
|
|
$this->assertTrue( |
148
|
|
|
$GLOBALS['finished'] |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function dataProviderOdsEmptyRows(): array |
153
|
|
|
{ |
154
|
|
|
return [ |
155
|
|
|
'remove empty columns' => [true], |
156
|
|
|
'keep empty columns' => [false], |
157
|
|
|
]; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Test for doImport using second dataset |
162
|
|
|
* |
163
|
|
|
* @group medium |
164
|
|
|
* @dataProvider dataProviderOdsEmptyRows |
165
|
|
|
*/ |
166
|
|
|
public function testDoImportDataset2(bool $odsEmptyRowsMode): void |
167
|
|
|
{ |
168
|
|
|
//$sql_query_disabled will show the import SQL detail |
169
|
|
|
//$import_notice will show the import detail result |
170
|
|
|
global $import_notice, $sql_query, $sql_query_disabled; |
171
|
|
|
$sql_query_disabled = false; |
172
|
|
|
|
173
|
|
|
$GLOBALS['import_file'] = 'test/test_data/import-slim.ods.xml'; |
174
|
|
|
$_REQUEST['ods_col_names'] = true; |
175
|
|
|
$_REQUEST['ods_empty_rows'] = $odsEmptyRowsMode; |
176
|
|
|
|
177
|
|
|
parent::setGlobalDbi(); |
178
|
|
|
|
179
|
|
|
$importHandle = new File($GLOBALS['import_file']); |
180
|
|
|
$importHandle->setDecompressContent(false);// Not compressed |
181
|
|
|
$importHandle->open(); |
182
|
|
|
|
183
|
|
|
// The process could probably detect that all the values for columns V to BL are empty |
184
|
|
|
// That would make the empty columns not needed and would create a cleaner structure |
185
|
|
|
$nulls = ''; |
|
|
|
|
186
|
|
|
$nullCells = ''; |
|
|
|
|
187
|
|
|
$nullCellNames = ''; |
|
|
|
|
188
|
|
|
|
189
|
|
|
$nulls = ', NULL' . str_repeat(', NULL', 44);// 45 empty cells |
190
|
|
|
|
191
|
|
|
$nullCells = ', `T` varchar(10), `U` varchar(10),' |
192
|
|
|
. ' `V` varchar(10), `W` varchar(10), `X` varchar(10), `Y` varchar(10), `Z` varchar(10),' |
193
|
|
|
. ' `AA` varchar(10), `AB` varchar(10), `AC` varchar(10), `AD` varchar(10), `AE` varchar(10),' |
194
|
|
|
. ' `AF` varchar(10), `AG` varchar(10), `AH` varchar(10), `AI` varchar(10), `AJ` varchar(10),' |
195
|
|
|
. ' `AK` varchar(10), `AL` varchar(10), `AM` varchar(10), `AN` varchar(10), `AO` varchar(10),' |
196
|
|
|
. ' `AP` varchar(10), `AQ` varchar(10), `AR` varchar(10), `AS` varchar(10), `AT` varchar(10),' |
197
|
|
|
. ' `AU` varchar(10), `AV` varchar(10), `AW` varchar(10), `AX` varchar(10), `AY` varchar(10),' |
198
|
|
|
. ' `AZ` varchar(10), `BA` varchar(10), `BB` varchar(10), `BC` varchar(10), `BD` varchar(10),' |
199
|
|
|
. ' `BE` varchar(10), `BF` varchar(10), `BG` varchar(10), `BH` varchar(10), `BI` varchar(10),' |
200
|
|
|
. ' `BJ` varchar(10), `BK` varchar(10), `BL` varchar(10)'; |
201
|
|
|
|
202
|
|
|
$nullCellNames = ', `T`, `U`, `V`, `W`, `X`, `Y`, `Z`, `AA`, `AB`, `AC`,' |
203
|
|
|
. ' `AD`, `AE`, `AF`, `AG`, `AH`, `AI`, `AJ`, `AK`, `AL`, `AM`, `AN`, `AO`, `AP`, `AQ`,' |
204
|
|
|
. ' `AR`, `AS`, `AT`, `AU`, `AV`, `AW`, `AX`, `AY`, `AZ`, `BA`, `BB`, `BC`, `BD`, `BE`,' |
205
|
|
|
. ' `BF`, `BG`, `BH`, `BI`, `BJ`, `BK`, `BL`'; |
206
|
|
|
|
207
|
|
|
$endOfSql = ');;'; |
208
|
|
|
|
209
|
|
|
if (! $odsEmptyRowsMode) { |
210
|
|
|
$fullCols = 'NULL' . str_repeat(', NULL', 44 + 19); |
211
|
|
|
$endOfSql = '),' . "\n"// three more empty lines |
212
|
|
|
. ' (' . $fullCols . '),' . "\n" |
213
|
|
|
. ' (' . $fullCols . '),' . "\n" |
214
|
|
|
. ' (' . $fullCols . ');;'; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
//Test function called |
218
|
|
|
$this->object->doImport($importHandle); |
219
|
|
|
|
220
|
|
|
$this->assertSame( |
221
|
|
|
'CREATE DATABASE IF NOT EXISTS `ODS_DB` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;;' |
222
|
|
|
. 'CREATE TABLE IF NOT EXISTS `ODS_DB`.`Shop` (' |
223
|
|
|
. '`Artikelnummer` varchar(7), `Name` varchar(41), `keywords` varchar(15), `EK_Preis` varchar(21),' |
224
|
|
|
. ' `Preis` varchar(23), `Details` varchar(10), `addInfo` varchar(22), `Einheit` varchar(3),' |
225
|
|
|
. ' `Wirkstoff` varchar(10), `verkuerztHaltbar` varchar(21), `kuehlkette` varchar(7),' |
226
|
|
|
. ' `Gebinde` varchar(71), `Verbrauchsnachweis` varchar(7), `Genehmigungspflichtig` varchar(7),' |
227
|
|
|
. ' `Gefahrstoff` varchar(11), `GefahrArbeitsbereich` varchar(14), `Verwendungszweck` varchar(10),' |
228
|
|
|
. ' `Verbrauch` varchar(10), `showLagerbestand` varchar(7)' . $nullCells . ') ' |
229
|
|
|
. 'DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;;' |
230
|
|
|
. 'INSERT INTO `ODS_DB`.`Shop` (' |
231
|
|
|
. '`Artikelnummer`, `Name`, `keywords`, `EK_Preis`, `Preis`, `Details`, `addInfo`, `Einheit`,' |
232
|
|
|
. ' `Wirkstoff`, `verkuerztHaltbar`, `kuehlkette`, `Gebinde`, `Verbrauchsnachweis`,' |
233
|
|
|
. ' `Genehmigungspflichtig`, `Gefahrstoff`, `GefahrArbeitsbereich`, `Verwendungszweck`,' |
234
|
|
|
. ' `Verbrauch`, `showLagerbestand`' . $nullCellNames . ') VALUES (' |
235
|
|
|
. 'NULL, NULL, \'Schlüsselwörter\', \'Einkaufspreis (Netto)\', \'VK-Preis (Orientierung)\', NULL,' |
236
|
|
|
. ' \'Hintergrundinformation\', \'VPE\', NULL, \'verkürzte Haltbarkeit\', \'ja/nein\',' |
237
|
|
|
. ' \'Stück,Rolle,Pack,Flasche,Sack,Eimer,Karton,Palette,Beutel,Kanister,Paar\', \'ja/nein\',' |
238
|
|
|
. ' \'ja/nein\', \'GHS01-GHS09\', \'Arbeitsbereich\', NULL, NULL, \'ja/nein\'' |
239
|
|
|
. $nulls . '),' . "\n" |
240
|
|
|
. ' (\'1005\', \'Beatmungsfilter\', NULL, \'0,85\', \'1,2\', NULL, NULL, \'5\', NULL, NULL, \'nein\',' |
241
|
|
|
. ' \'Stück\', \'nein\', \'nein\', NULL, NULL, NULL, NULL, \'ja\'' . $nulls . '),' . "\n" |
242
|
|
|
. ' (\'04-3-06\', \'Absaugkatheter, CH06 grün\', NULL, \'0.13\', \'0.13\', NULL, NULL, \'1\',' |
243
|
|
|
. ' NULL, NULL,' |
244
|
|
|
. ' NULL, \'Stück\', \'nein\', \'nein\', NULL, NULL, NULL, NULL, \'ja\'' |
245
|
|
|
. $nulls . '),' . "\n" |
246
|
|
|
. ' (\'04-3-10\', \'Absaugkatheter, CH10 schwarz\', NULL, \'0.13\', \'0.13\', NULL, NULL, \'1\',' |
247
|
|
|
. ' NULL, NULL, NULL, \'Stück\', \'nein\', \'nein\', NULL, NULL, NULL, NULL, \'ja\'' |
248
|
|
|
. $nulls . '),' . "\n" |
249
|
|
|
. ' (\'04-3-18\', \'Absaugkatheter, CH18 rot\', NULL, \'0.13\', \'0.13\', NULL, NULL, \'1\',' |
250
|
|
|
. ' NULL, NULL, NULL, \'Stück\', \'nein\', \'nein\', NULL, NULL, NULL, NULL, \'ja\'' |
251
|
|
|
. $nulls . '),' . "\n" |
252
|
|
|
. ' (\'06-38\', \'Bakterienfilter\', NULL, \'1.25\', \'1.25\', NULL, NULL, \'1\', NULL, NULL, NULL,' |
253
|
|
|
. ' \'Stück\', \'nein\', \'nein\', NULL, NULL, NULL, NULL, \'ja\'' |
254
|
|
|
. $nulls . '),' . "\n" |
255
|
|
|
. ' (\'05-453\', \'Blockerspritze für Larynxtubus, Erwachsen\', NULL, \'2.6\', \'2.6\', NULL, NULL,' |
256
|
|
|
. ' \'1\', NULL, NULL, NULL, \'Stück\', \'nein\', \'nein\', NULL, NULL, NULL, NULL, \'ja\'' |
257
|
|
|
. $nulls . '),' . "\n" |
258
|
|
|
. ' (\'04-402\', \'Absaugschlauch mit Fingertip für Accuvac\', NULL, \'1.7\', \'1.7\', NULL, NULL,' |
259
|
|
|
. ' \'1\', NULL, NULL, NULL, \'Stück\', \'nein\', \'nein\', NULL, NULL, NULL, NULL, \'ja\'' |
260
|
|
|
. $nulls . '),' . "\n" |
261
|
|
|
. ' (\'02-580\', \'Einmalbeatmungsbeutel, Erwachsen\', NULL, \'8.9\', \'8.9\', NULL, NULL,' |
262
|
|
|
. ' \'1\', NULL, NULL, NULL, \'Stück\', \'nein\', \'nein\', NULL, NULL, NULL, NULL, \'ja\'' |
263
|
|
|
. $nulls |
264
|
|
|
. $endOfSql, |
265
|
|
|
$sql_query |
266
|
|
|
); |
267
|
|
|
|
268
|
|
|
//asset that all databases and tables are imported |
269
|
|
|
$this->assertStringContainsString( |
270
|
|
|
'The following structures have either been created or altered.', |
271
|
|
|
$import_notice |
272
|
|
|
); |
273
|
|
|
$this->assertStringContainsString( |
274
|
|
|
'Go to database: `ODS_DB`', |
275
|
|
|
$import_notice |
276
|
|
|
); |
277
|
|
|
$this->assertStringContainsString( |
278
|
|
|
'Edit settings for `ODS_DB`', |
279
|
|
|
$import_notice |
280
|
|
|
); |
281
|
|
|
$this->assertStringContainsString( |
282
|
|
|
'Go to table: `Shop`', |
283
|
|
|
$import_notice |
284
|
|
|
); |
285
|
|
|
$this->assertStringContainsString( |
286
|
|
|
'Edit settings for `Shop`', |
287
|
|
|
$import_notice |
288
|
|
|
); |
289
|
|
|
|
290
|
|
|
//asset that the import process is finished |
291
|
|
|
$this->assertTrue( |
292
|
|
|
$GLOBALS['finished'] |
293
|
|
|
); |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|