-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCsvValuesViewHelperTest.php
More file actions
122 lines (97 loc) · 3.75 KB
/
CsvValuesViewHelperTest.php
File metadata and controls
122 lines (97 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
declare(strict_types=1);
namespace Extcode\Cart\Tests\Functional\ViewHelpers;
/*
* This file is part of the package extcode/cart.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
use Codappix\Typo3PhpDatasets\TestingFramework;
use Extcode\Cart\Domain\Repository\Order\ItemRepository;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\View\ViewFactoryData;
use TYPO3\CMS\Core\View\ViewFactoryInterface;
use TYPO3\CMS\Core\View\ViewInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
final class CsvValuesViewHelperTest extends FunctionalTestCase
{
use TestingFramework;
private ItemRepository $itemRepository;
public function setUp(): void
{
$this->testExtensionsToLoad = [
'extcode/cart',
];
$this->coreExtensionsToLoad = [
'typo3/cms-beuser',
'typo3/cms-core',
];
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));
}
}