diff --git a/Tests/Fixtures/Orders.php b/Tests/Fixtures/Orders.php new file mode 100644 index 00000000..4840da26 --- /dev/null +++ b/Tests/Fixtures/Orders.php @@ -0,0 +1,51 @@ + [ + 0 => [ + 'uid' => 10, + 'pid' => 105, + 'billing_address' => 1, + ], + 1 => [ + 'uid' => 11, + 'pid' => 105, + 'billing_address' => 1, + 'order_number' => 'O-20260121-7', + 'order_date' => 1769034161, + 'invoice_number' => 'I-20260122-3', + 'invoice_date' => 1769120561, + ], + 2 => [ + 'uid' => 12, + 'pid' => 105, + 'billing_address' => 0, + 'order_number' => 'O-20260121-7', + 'order_date' => 1769034161, + 'invoice_number' => 'I-20260122-3', + 'invoice_date' => 1769120561, + ], + ], + 'tx_cart_domain_model_order_address' => [ + 0 => [ + 'uid' => 20, + 'pid' => 105, + 'item' => 10, + 'record_type' => '\\' . BillingAddress::class, + ], + 1 => [ + 'uid' => 21, + 'pid' => 105, + 'item' => 11, + 'record_type' => '\\' . BillingAddress::class, + 'salutation' => 'Mr', + 'title' => '', + 'first_name' => 'Arthur', + 'last_name' => 'Dent', + ], + ], +]; diff --git a/Tests/Functional/ViewHelpers/CsvValuesViewHelperTest.php b/Tests/Functional/ViewHelpers/CsvValuesViewHelperTest.php new file mode 100644 index 00000000..9ccb78f9 --- /dev/null +++ b/Tests/Functional/ViewHelpers/CsvValuesViewHelperTest.php @@ -0,0 +1,115 @@ +testExtensionsToLoad[] = 'extcode/cart'; + + parent::setUp(); + + $this->itemRepository = GeneralUtility::makeInstance(ItemRepository::class); + + $querySettings = GeneralUtility::makeInstance(QuerySettingsInterface::class); + $querySettings->setStoragePageIds([105]); + $this->itemRepository->setDefaultQuerySettings($querySettings); + + $this->importPHPDataSet(__DIR__ . '/../../Fixtures/BaseDatabase.php'); + $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Orders.php'); + } + + #[Test] + public function orderWithEmptyOrderDataWithEmptyAddressDataExportsToCsvLine(): void + { + $orderItem = $this->itemRepository->findByUid(10); + + $template = __DIR__ . '/Fixtures/CsvValues.html'; + $view = $this->getView($template); + $view->assign('orderItem', $orderItem); + $content = $view->render(); + + self::assertSame( + ',,,,,,,' . "\n", + $content + ); + } + + #[Test] + public function orderWithOrderDataAndWithAddressExportsToCsvLine(): void + { + $orderItem = $this->itemRepository->findByUid(11); + + $template = __DIR__ . '/Fixtures/CsvValues.html'; + $view = $this->getView($template); + $view->assign('orderItem', $orderItem); + $content = $view->render(); + + self::assertSame( + '"O-20260121-7","21.01.2026","I-20260122-3","22.01.2026","Mr",,"Arthur","Dent"' . "\n", + $content + ); + } + + #[Test] + public function orderWithOrderDataAndWithAddressExportsToCsvLineWithDifferentDelimAndQuote(): void + { + $orderItem = $this->itemRepository->findByUid(11); + + $template = __DIR__ . '/Fixtures/CsvValuesWithDifferentDelimAndQuote.html'; + $view = $this->getView($template); + $view->assign('orderItem', $orderItem); + $content = $view->render(); + + self::assertSame( + '\'O-20260121-7\'|\'21.01.2026\'|\'I-20260122-3\'|\'22.01.2026\'|\'Mr\'||\'Arthur\'|\'Dent\'' . "\n", + $content + ); + } + + #[Test] + public function orderWithOrderDataAndWithoutAddressExportsToCsvLine(): void + { + $orderItem = $this->itemRepository->findByUid(12); + + $template = __DIR__ . '/Fixtures/CsvValues.html'; + $view = $this->getView($template); + $view->assign('orderItem', $orderItem); + $content = $view->render(); + + self::assertSame( + '"O-20260121-7","21.01.2026","I-20260122-3","22.01.2026","","","",""' . "\n", + $content + ); + } + + private function getView(string $template): ViewInterface + { + $viewFactory = GeneralUtility::makeInstance(ViewFactoryInterface::class); + return $viewFactory->create(new ViewFactoryData(null, null, null, $template)); + } +} diff --git a/Tests/Functional/ViewHelpers/Fixtures/CsvValues.html b/Tests/Functional/ViewHelpers/Fixtures/CsvValues.html new file mode 100644 index 00000000..06723d28 --- /dev/null +++ b/Tests/Functional/ViewHelpers/Fixtures/CsvValues.html @@ -0,0 +1 @@ + diff --git a/Tests/Functional/ViewHelpers/Fixtures/CsvValuesWithDifferentDelimAndQuote.html b/Tests/Functional/ViewHelpers/Fixtures/CsvValuesWithDifferentDelimAndQuote.html new file mode 100644 index 00000000..e78d9818 --- /dev/null +++ b/Tests/Functional/ViewHelpers/Fixtures/CsvValuesWithDifferentDelimAndQuote.html @@ -0,0 +1 @@ +