diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php index a30725019..cf701cdd6 100644 --- a/lib/Service/ImportService.php +++ b/lib/Service/ImportService.php @@ -285,8 +285,14 @@ public function import(?int $tableId, ?int $viewId, string $path, bool $createMi * @throws PermissionError */ private function loop(Worksheet $worksheet): void { - $firstRow = $worksheet->getRowIterator()->current(); - $secondRow = $worksheet->getRowIterator()->seek(2)->current(); + $rowIterator = $worksheet->getRowIterator(); + $firstRow = $rowIterator->current(); + $rowIterator->next(); + if (!$rowIterator->valid()) { + return; + } + $secondRow = $rowIterator->current(); + unset($rowIterator); $this->getColumns($firstRow, $secondRow); if (empty(array_filter($this->columns))) { diff --git a/tests/integration/features/APIv1.feature b/tests/integration/features/APIv1.feature index 333d225ee..a88c53d45 100644 --- a/tests/integration/features/APIv1.feature +++ b/tests/integration/features/APIv1.feature @@ -215,6 +215,54 @@ Feature: APIv1 | Val1 | Val2 | Val3 | 1 | 💙 | Ä | 2024-02-24 | false | | great | news | here | 99 | ⚠️ | Ö | 2016-06-01 | true | + @api1 @import + Scenario: Import xlsx table generated by 365 + Given user "participant1" uploads file "import-from-ms365.xlsx" + And table "Import test" with emoji "👨🏻‍💻" exists for user "participant1" as "base1" + When user imports file "/import-from-ms365.xlsx" into last created table + Then import results have the following data + | found_columns_count | 8 | + | created_columns_count | 8 | + | inserted_rows_count | 2 | + | errors_count | 0 | + Then table has at least following typed columns + | Col1 | text | + | Col2 | text | + | Col3 | text | + | num | number | + | emoji | text | + | special | text | + | date | datetime | + | truth | selection | + Then table contains at least following rows + | Col1 | Col2 | Col3 | num | emoji | special | date | truth | + | Val1 | Val2 | Val3 | 1 | 💙 | Ä | 2024-02-24 00:00 | false | + | great | news | here | 99 | ⚠ | Ö | 2016-06-01 00:00 | true | + + @api1 @import + Scenario: Import xlsx table generated by LibreOffice + Given user "participant1" uploads file "import-from-libreoffice.xlsx" + And table "Import test" with emoji "👨🏻‍💻" exists for user "participant1" as "base1" + When user imports file "/import-from-libreoffice.xlsx" into last created table + Then import results have the following data + | found_columns_count | 8 | + | created_columns_count | 8 | + | inserted_rows_count | 2 | + | errors_count | 0 | + Then table has at least following typed columns + | Col1 | text | + | Col2 | text | + | Col3 | text | + | num | number | + | emoji | text | + | special | text | + | date | datetime | + | truth | selection | + Then table contains at least following rows + | Col1 | Col2 | Col3 | num | emoji | special | date | truth | + | Val1 | Val2 | Val3 | 1 | 💙 | Ä | 2024-02-24 00:00 | false | + | great | news | here | 99 | ⚠ | Ö | 2016-06-01 00:00 | true | + @api1 Scenario: Create, edit and delete views Given table "View test" with emoji "👨🏻‍💻" exists for user "participant1" as "view-test" diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 725a93be1..0be0cec0e 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -13,6 +13,7 @@ use GuzzleHttp\Cookie\CookieJar; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Psr7\Utils; use PHPUnit\Framework\Assert; use PHPUnit\Framework\ExpectationFailedException; use Psr\Http\Message\ResponseInterface; @@ -64,6 +65,8 @@ class FeatureContext implements Context { private array $tableData = []; private array $viewData = []; + private $importColumnData = null; + // use CommandLineTrait; private CollectionManager $collectionManager; @@ -89,6 +92,7 @@ public function setUp() { * @AfterScenario */ public function cleanupUsers() { + $this->importColumnData = null; $this->collectionManager->cleanUp(); foreach ($this->createdUsers as $user) { $this->deleteUser($user); @@ -467,8 +471,21 @@ public function columnsForNodeV2(string $nodeType, string $nodeName, ?TableNode // (((((((((((((((((((((((((((( END API v2 ))))))))))))))))))))))))))))))))))) + /** + * @Given user :user uploads file :file + */ + public function uploadFile(string $user, string $file): void { + $this->setCurrentUser($user); + + $localFilePath = __DIR__ . '/../../resources/' . $file; + + $url = sprintf('%sremote.php/dav/files/%s/%s', $this->baseUrl, $user, $file); + $body = Utils::streamFor(fopen($localFilePath, 'rb')); + $this->sendRequestFullUrl('PUT', $url, $body); + Assert::assertEquals(201, $this->response->getStatusCode()); + } // IMPORT -------------------------- @@ -574,7 +591,7 @@ public function checkRowsExists(TableNode $table): void { $allValuesForColumn[] = $row[$indexForCol]; } foreach ($table->getColumn($key) as $item) { - Assert::assertTrue(in_array($item, $allValuesForColumn)); + Assert::assertTrue(in_array($item, $allValuesForColumn), sprintf('%s not in %s', $item, implode(', ', $allValuesForColumn))); } } } diff --git a/tests/integration/resources/import-from-libreoffice.xlsx b/tests/integration/resources/import-from-libreoffice.xlsx new file mode 100644 index 000000000..6cdff60f7 Binary files /dev/null and b/tests/integration/resources/import-from-libreoffice.xlsx differ diff --git a/tests/integration/resources/import-from-ms365.xlsx b/tests/integration/resources/import-from-ms365.xlsx new file mode 100644 index 000000000..896b4276c Binary files /dev/null and b/tests/integration/resources/import-from-ms365.xlsx differ