Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Tests/Functional/ViewHelpers/CsvHeaderViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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 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\TestingFramework\Core\Functional\FunctionalTestCase;

final class CsvHeaderViewHelperTest extends FunctionalTestCase
{
use TestingFramework;

public function setUp(): void
{
$this->testExtensionsToLoad[] = 'extcode/cart';

parent::setUp();
}

#[Test]
public function headerExportsToCsvLine(): void
{
$template = __DIR__ . '/Fixtures/CsvHeader.html';
$view = $this->getView($template);
$content = $view->render();

self::assertSame(
'"Order Number","Order Date","Invoice Number","Invoice Date","Salutation","Title","FirstName","LastName"' . "\n",
$content
);
}

#[Test]
public function headerExportsToCsvLineWithDifferentDelimAndQuote(): void
{
$template = __DIR__ . '/Fixtures/CsvHeaderWithDifferentDelimAndQuote.html';
$view = $this->getView($template);
$content = $view->render();

self::assertSame(
'\'Order Number\'|\'Order Date\'|\'Invoice Number\'|\'Invoice Date\'|\'Salutation\'|\'Title\'|\'FirstName\'|\'LastName\'' . "\n",
$content
);
}

private function getView(string $template): ViewInterface
{
$viewFactory = GeneralUtility::makeInstance(ViewFactoryInterface::class);
return $viewFactory->create(new ViewFactoryData(null, null, null, $template));
}
}
1 change: 1 addition & 0 deletions Tests/Functional/ViewHelpers/Fixtures/CsvHeader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<cart:csvHeader />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<cart:csvHeader delim="|" quote="'"/>