Skip to content

Commit

Permalink
test(Integration): extend import test with xlsx data sets
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Nov 14, 2024
1 parent 0a6b3c7 commit a3e0833
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
48 changes: 48 additions & 0 deletions tests/integration/features/APIv1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 | false |
| great | news | here | 99 | ⚠ | Ö | 2016-06-01 | 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 | false |
| great | news | here | 99 | ⚠ | Ö | 2016-06-01 | true |

@api1
Scenario: Create, edit and delete views
Given table "View test" with emoji "👨🏻‍💻" exists for user "participant1" as "view-test"
Expand Down
19 changes: 18 additions & 1 deletion tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,6 +65,8 @@ class FeatureContext implements Context {
private array $tableData = [];
private array $viewData = [];

private $importColumnData = null;

// use CommandLineTrait;
private CollectionManager $collectionManager;

Expand All @@ -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);
Expand Down Expand Up @@ -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 --------------------------

Expand Down Expand Up @@ -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)));
}
}
}
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit a3e0833

Please sign in to comment.