88use PhpMyAdmin \Current ;
99use PhpMyAdmin \DatabaseInterface ;
1010use PhpMyAdmin \File ;
11+ use PhpMyAdmin \Http \Factory \ServerRequestFactory ;
1112use PhpMyAdmin \Import \ImportSettings ;
1213use PhpMyAdmin \Plugins \Import \ImportOds ;
1314use PhpMyAdmin \Tests \AbstractTestCase ;
14- use PhpMyAdmin \Tests \Stubs \DbiDummy ;
1515use PHPUnit \Framework \Attributes \CoversClass ;
1616use PHPUnit \Framework \Attributes \DataProvider ;
1717use PHPUnit \Framework \Attributes \Medium ;
2525#[Medium]
2626class ImportOdsTest extends AbstractTestCase
2727{
28- protected DatabaseInterface $ dbi ;
29-
30- protected DbiDummy $ dummyDbi ;
31-
3228 protected ImportOds $ object ;
3329
3430 /**
@@ -39,7 +35,6 @@ protected function setUp(): void
3935 {
4036 parent ::setUp ();
4137
42- DatabaseInterface::$ instance = $ this ->createDatabaseInterface ();
4338 $ GLOBALS ['error ' ] = null ;
4439 ImportSettings::$ timeoutPassed = false ;
4540 ImportSettings::$ maximumTime = 0 ;
@@ -51,22 +46,21 @@ protected function setUp(): void
5146 ImportSettings::$ runQuery = false ;
5247 $ GLOBALS ['sql_query ' ] = '' ;
5348 ImportSettings::$ goSql = false ;
54- $ this ->object = new ImportOds ();
55-
56- //setting
5749 ImportSettings::$ finished = false ;
5850 ImportSettings::$ readLimit = 100000000 ;
5951 ImportSettings::$ offset = 0 ;
6052 Config::getInstance ()->selectedServer ['DisableIS ' ] = false ;
61-
62- /**
63- * Load interface for zip extension.
64- */
6553 ImportSettings::$ readMultiply = 10 ;
6654
55+ $ this ->object = new ImportOds ();
56+
6757 //variable for Ods
68- $ _REQUEST ['ods_recognize_percentages ' ] = true ;
69- $ _REQUEST ['ods_recognize_currency ' ] = true ;
58+ $ request = ServerRequestFactory::create ()->createServerRequest ('POST ' , 'http://example.com/ ' )
59+ ->withParsedBody ([
60+ 'ods_recognize_percentages ' => 'yes ' ,
61+ 'ods_recognize_currency ' => 'yes ' ,
62+ ]);
63+ $ this ->object ->setImportOptions ($ request );
7064 }
7165
7266 /**
@@ -105,23 +99,24 @@ public function testGetProperties(): void
10599 */
106100 public function testDoImport (): void
107101 {
108- //$sql_query_disabled will show the import SQL detail
109- //$import_notice will show the import detail result
110-
111- ImportSettings::$ sqlQueryDisabled = false ;
102+ ImportSettings::$ sqlQueryDisabled = false ; //will show the import SQL detail
112103
113104 ImportSettings::$ importFile = 'tests/test_data/db_test.ods ' ;
114- $ _REQUEST ['ods_empty_rows ' ] = true ;
115105
116- $ this ->dummyDbi = $ this ->createDbiDummy ();
117- $ this ->dbi = $ this ->createDatabaseInterface ($ this ->dummyDbi );
118- DatabaseInterface::$ instance = $ this ->dbi ;
106+ $ request = ServerRequestFactory::create ()->createServerRequest ('POST ' , 'http://example.com/ ' )
107+ ->withParsedBody ([
108+ 'ods_recognize_percentages ' => 'yes ' ,
109+ 'ods_recognize_currency ' => 'yes ' ,
110+ 'ods_empty_rows ' => 'yes ' ,
111+ ]);
112+ $ this ->object ->setImportOptions ($ request );
113+
114+ DatabaseInterface::$ instance = $ this ->createDatabaseInterface ();
119115
120116 $ importHandle = new File (ImportSettings::$ importFile );
121117 $ importHandle ->setDecompressContent (true );
122118 $ importHandle ->open ();
123119
124- //Test function called
125120 $ this ->object ->doImport ($ importHandle );
126121
127122 self ::assertStringContainsString (
@@ -134,7 +129,7 @@ public function testDoImport(): void
134129 $ GLOBALS ['sql_query ' ],
135130 );
136131
137- //asset that all databases and tables are imported
132+ //assert that all databases and tables are imported
138133 self ::assertStringContainsString (
139134 'The following structures have either been created or altered. ' ,
140135 ImportSettings::$ importNotice ,
@@ -144,35 +139,39 @@ public function testDoImport(): void
144139 self ::assertStringContainsString ('Go to table: `pma_bookmark` ' , ImportSettings::$ importNotice );
145140 self ::assertStringContainsString ('Edit settings for `pma_bookmark` ' , ImportSettings::$ importNotice );
146141
147- //asset that the import process is finished
142+ //assert that the import process is finished
148143 self ::assertTrue (ImportSettings::$ finished );
149144 }
150145
151- /** @return mixed[] */
146+ /** @return array<string, array<string|null>> */
152147 public static function dataProviderOdsEmptyRows (): array
153148 {
154- return ['remove empty columns ' => [true ], 'keep empty columns ' => [false ]];
149+ return [
150+ 'remove empty columns ' => ['yes ' ],
151+ 'keep empty columns ' => [null ],
152+ ];
155153 }
156154
157155 /**
158156 * Test for doImport using second dataset
159157 */
160158 #[DataProvider('dataProviderOdsEmptyRows ' )]
161159 #[RequiresPhpExtension('simplexml ' )]
162- public function testDoImportDataset2 (bool $ odsEmptyRowsMode ): void
160+ public function testDoImportDataset2 (string | null $ odsEmptyRowsMode ): void
163161 {
164- //$sql_query_disabled will show the import SQL detail
165- //$import_notice will show the import detail result
166-
167- ImportSettings::$ sqlQueryDisabled = false ;
162+ ImportSettings::$ sqlQueryDisabled = false ; //will show the import SQL detail
168163
169164 ImportSettings::$ importFile = 'tests/test_data/import-slim.ods.xml ' ;
170- $ _REQUEST ['ods_col_names ' ] = true ;
171- $ _REQUEST ['ods_empty_rows ' ] = $ odsEmptyRowsMode ;
165+ $ request = ServerRequestFactory::create ()->createServerRequest ('POST ' , 'http://example.com/ ' )
166+ ->withParsedBody ([
167+ 'ods_recognize_percentages ' => 'yes ' ,
168+ 'ods_recognize_currency ' => 'yes ' ,
169+ 'ods_col_names ' => 'yes ' ,
170+ 'ods_empty_rows ' => $ odsEmptyRowsMode ,
171+ ]);
172+ $ this ->object ->setImportOptions ($ request );
172173
173- $ this ->dummyDbi = $ this ->createDbiDummy ();
174- $ this ->dbi = $ this ->createDatabaseInterface ($ this ->dummyDbi );
175- DatabaseInterface::$ instance = $ this ->dbi ;
174+ DatabaseInterface::$ instance = $ this ->createDatabaseInterface ();
176175
177176 $ importHandle = new File (ImportSettings::$ importFile );
178177 $ importHandle ->setDecompressContent (false );// Not compressed
@@ -183,12 +182,11 @@ public function testDoImportDataset2(bool $odsEmptyRowsMode): void
183182
184183 $ endOfSql = '); ' ;
185184
186- if (! $ odsEmptyRowsMode ) {
185+ if ($ odsEmptyRowsMode === null ) {
187186 $ fullCols = 'NULL ' . str_repeat (', NULL ' , 18 );// 19 empty cells
188187 $ endOfSql = '), ' . "\n" . ' ( ' . $ fullCols . '), ' . "\n" . ' ( ' . $ fullCols . '); ' ;
189188 }
190189
191- //Test function called
192190 $ this ->object ->doImport ($ importHandle );
193191
194192 self ::assertSame (
@@ -240,12 +238,12 @@ public function testDoImportDataset2(bool $odsEmptyRowsMode): void
240238 . ' ( \'0.05 \'), ' . "\n"
241239 . ' ( \'true \'), ' . "\n"
242240 . ' ( \'12 \') '
243- . ($ odsEmptyRowsMode ? '' : ', ' . "\n" . ' (NULL) ' )
244- . ($ odsEmptyRowsMode ? '; ' : ', ' . "\n" . ' (NULL); ' ),
241+ . ($ odsEmptyRowsMode !== null ? '' : ', ' . "\n" . ' (NULL) ' )
242+ . ($ odsEmptyRowsMode !== null ? '; ' : ', ' . "\n" . ' (NULL); ' ),
245243 $ GLOBALS ['sql_query ' ],
246244 );
247245
248- //asset that all databases and tables are imported
246+ //assert that all databases and tables are imported
249247 self ::assertStringContainsString (
250248 'The following structures have either been created or altered. ' ,
251249 ImportSettings::$ importNotice ,
@@ -255,7 +253,7 @@ public function testDoImportDataset2(bool $odsEmptyRowsMode): void
255253 self ::assertStringContainsString ('Go to table: `Shop` ' , ImportSettings::$ importNotice );
256254 self ::assertStringContainsString ('Edit settings for `Shop` ' , ImportSettings::$ importNotice );
257255
258- //asset that the import process is finished
256+ //assert that the import process is finished
259257 self ::assertTrue (ImportSettings::$ finished );
260258 }
261259}
0 commit comments