diff --git a/src/Import/Import.php b/src/Import/Import.php index fc2172c58b..70d583a7de 100644 --- a/src/Import/Import.php +++ b/src/Import/Import.php @@ -1011,6 +1011,10 @@ class Import $numCols = count($table->columns); $lastColumnKey = array_key_last($table->columns); + if ($table->rows === []) { + break; + } + $tempSQLStr = 'INSERT INTO ' . Util::backquote($dbName) . '.' . Util::backquote($table->tableName) . ' ('; diff --git a/tests/classes/Plugins/Import/ImportMediawikiTest.php b/tests/classes/Plugins/Import/ImportMediawikiTest.php index 60bcf12b74..aec4952443 100644 --- a/tests/classes/Plugins/Import/ImportMediawikiTest.php +++ b/tests/classes/Plugins/Import/ImportMediawikiTest.php @@ -138,4 +138,48 @@ class ImportMediawikiTest extends AbstractTestCase self::assertStringContainsString('Edit settings for `pma_bookmarktest`', ImportSettings::$importNotice); self::assertTrue(ImportSettings::$finished); } + + /** + * Test for doImport + * + * @group medium + */ + public function testDoImportWithEmptyTable(): void + { + //Mock DBI + $dbi = $this->getMockBuilder(DatabaseInterface::class) + ->disableOriginalConstructor() + ->getMock(); + DatabaseInterface::$instance = $dbi; + + $importHandle = new File('tests/test_data/__slashes.mediawiki'); + $importHandle->open(); + + //Test function called + $this->object->doImport($importHandle); + + // If import successfully, PMA will show all databases and + // tables imported as following HTML Page + /* + The following structures have either been created or altered. Here you + can: + View a structure's contents by clicking on its name + Change any of its settings by clicking the corresponding "Options" link + Edit structure by following the "Structure" link + + mediawiki_DB (Options) + pma_bookmarktest (Structure) (Options) + */ + + //asset that all databases and tables are imported + self::assertStringContainsString( + 'The following structures have either been created or altered.', + ImportSettings::$importNotice, + ); + self::assertStringContainsString('Go to database: `mediawiki_DB`', ImportSettings::$importNotice); + self::assertStringContainsString('Edit settings for `mediawiki_DB`', ImportSettings::$importNotice); + self::assertStringContainsString('Go to table: `empty`', ImportSettings::$importNotice); + self::assertStringContainsString('Edit settings for `empty`', ImportSettings::$importNotice); + self::assertTrue(ImportSettings::$finished); + } } diff --git a/tests/test_data/__slashes.mediawiki b/tests/test_data/__slashes.mediawiki new file mode 100644 index 0000000000..6d2b6bc381 --- /dev/null +++ b/tests/test_data/__slashes.mediawiki @@ -0,0 +1,12 @@ + + + +{| class="wikitable sortable" style="text-align:center;" +|+'''empty''' +|- + ! \'table + ! \\column +|} +