Skip to content

Commit d599204

Browse files
committed
test(Integration): extend import test with xlsx data sets
Signed-off-by: Arthur Schiwon <[email protected]>
1 parent 0a6b3c7 commit d599204

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

lib/Service/ImportService.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,14 @@ public function import(?int $tableId, ?int $viewId, string $path, bool $createMi
285285
* @throws PermissionError
286286
*/
287287
private function loop(Worksheet $worksheet): void {
288-
$firstRow = $worksheet->getRowIterator()->current();
289-
$secondRow = $worksheet->getRowIterator()->seek(2)->current();
288+
$rowIterator = $worksheet->getRowIterator();
289+
$firstRow = $rowIterator->current();
290+
$rowIterator->next();
291+
if (!$rowIterator->valid()) {
292+
return;
293+
}
294+
$secondRow = $rowIterator->current();
295+
unset($rowIterator);
290296
$this->getColumns($firstRow, $secondRow);
291297

292298
if (empty(array_filter($this->columns))) {

tests/integration/features/APIv1.feature

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,54 @@ Feature: APIv1
215215
| Val1 | Val2 | Val3 | 1 | 💙 | Ä | 2024-02-24 | false |
216216
| great | news | here | 99 | ⚠️ | Ö | 2016-06-01 | true |
217217

218+
@api1 @import
219+
Scenario: Import xlsx table generated by 365
220+
Given user "participant1" uploads file "import-from-ms365.xlsx"
221+
And table "Import test" with emoji "👨🏻‍💻" exists for user "participant1" as "base1"
222+
When user imports file "/import-from-ms365.xlsx" into last created table
223+
Then import results have the following data
224+
| found_columns_count | 8 |
225+
| created_columns_count | 8 |
226+
| inserted_rows_count | 2 |
227+
| errors_count | 0 |
228+
Then table has at least following typed columns
229+
| Col1 | text |
230+
| Col2 | text |
231+
| Col3 | text |
232+
| num | number |
233+
| emoji | text |
234+
| special | text |
235+
| date | datetime |
236+
| truth | selection |
237+
Then table contains at least following rows
238+
| Col1 | Col2 | Col3 | num | emoji | special | date | truth |
239+
| Val1 | Val2 | Val3 | 1 | 💙 | Ä | 2024-02-24 00:00 | false |
240+
| great | news | here | 99 | ⚠ | Ö | 2016-06-01 00:00 | true |
241+
242+
@api1 @import
243+
Scenario: Import xlsx table generated by LibreOffice
244+
Given user "participant1" uploads file "import-from-libreoffice.xlsx"
245+
And table "Import test" with emoji "👨🏻‍💻" exists for user "participant1" as "base1"
246+
When user imports file "/import-from-libreoffice.xlsx" into last created table
247+
Then import results have the following data
248+
| found_columns_count | 8 |
249+
| created_columns_count | 8 |
250+
| inserted_rows_count | 2 |
251+
| errors_count | 0 |
252+
Then table has at least following typed columns
253+
| Col1 | text |
254+
| Col2 | text |
255+
| Col3 | text |
256+
| num | number |
257+
| emoji | text |
258+
| special | text |
259+
| date | datetime |
260+
| truth | selection |
261+
Then table contains at least following rows
262+
| Col1 | Col2 | Col3 | num | emoji | special | date | truth |
263+
| Val1 | Val2 | Val3 | 1 | 💙 | Ä | 2024-02-24 00:00 | false |
264+
| great | news | here | 99 | ⚠ | Ö | 2016-06-01 00:00 | true |
265+
218266
@api1
219267
Scenario: Create, edit and delete views
220268
Given table "View test" with emoji "👨🏻‍💻" exists for user "participant1" as "view-test"

tests/integration/features/bootstrap/FeatureContext.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use GuzzleHttp\Cookie\CookieJar;
1414
use GuzzleHttp\Exception\ClientException;
1515
use GuzzleHttp\Exception\GuzzleException;
16+
use GuzzleHttp\Psr7\Utils;
1617
use PHPUnit\Framework\Assert;
1718
use PHPUnit\Framework\ExpectationFailedException;
1819
use Psr\Http\Message\ResponseInterface;
@@ -64,6 +65,8 @@ class FeatureContext implements Context {
6465
private array $tableData = [];
6566
private array $viewData = [];
6667

68+
private $importColumnData = null;
69+
6770
// use CommandLineTrait;
6871
private CollectionManager $collectionManager;
6972

@@ -89,6 +92,7 @@ public function setUp() {
8992
* @AfterScenario
9093
*/
9194
public function cleanupUsers() {
95+
$this->importColumnData = null;
9296
$this->collectionManager->cleanUp();
9397
foreach ($this->createdUsers as $user) {
9498
$this->deleteUser($user);
@@ -467,8 +471,21 @@ public function columnsForNodeV2(string $nodeType, string $nodeName, ?TableNode
467471
// (((((((((((((((((((((((((((( END API v2 )))))))))))))))))))))))))))))))))))
468472

469473

474+
/**
475+
* @Given user :user uploads file :file
476+
*/
477+
public function uploadFile(string $user, string $file): void {
478+
$this->setCurrentUser($user);
479+
480+
$localFilePath = __DIR__ . '/../../resources/' . $file;
481+
482+
$url = sprintf('%sremote.php/dav/files/%s/%s', $this->baseUrl, $user, $file);
483+
$body = Utils::streamFor(fopen($localFilePath, 'rb'));
470484

485+
$this->sendRequestFullUrl('PUT', $url, $body);
471486

487+
Assert::assertEquals(201, $this->response->getStatusCode());
488+
}
472489

473490
// IMPORT --------------------------
474491

@@ -574,7 +591,7 @@ public function checkRowsExists(TableNode $table): void {
574591
$allValuesForColumn[] = $row[$indexForCol];
575592
}
576593
foreach ($table->getColumn($key) as $item) {
577-
Assert::assertTrue(in_array($item, $allValuesForColumn));
594+
Assert::assertTrue(in_array($item, $allValuesForColumn), sprintf('%s not in %s', $item, implode(', ', $allValuesForColumn)));
578595
}
579596
}
580597
}
6.35 KB
Binary file not shown.
13.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)