Import of W&K seminar exports with preview, booking form via form generator with event-dependent field rules, notification routing, inbox with folders and CSV export for W&K. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
66 lines
2.2 KiB
PHP
66 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Mummert\ContaoWkSyncBundle\Tests\Import;
|
|
|
|
use Mummert\ContaoWkSyncBundle\Import\CsvReader;
|
|
use Mummert\ContaoWkSyncBundle\Import\ImportException;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class CsvReaderTest extends TestCase
|
|
{
|
|
public function testReadsWindows1252WithMultilineFieldsAndEuroSign(): void
|
|
{
|
|
$csv = "kbnr;kbtitel;kbpmemo;kbkp1\r\n"
|
|
."\"0003355\";\"P\xE4dagogik\";\"Zeile 1\r\nZeile 2\";\"240,00 \xC7\"\r\n"
|
|
."\"0003356\";\"Titel \"\"mit\"\" Anf\xFChrung\";\"\";\"\"\r\n";
|
|
|
|
$table = (new CsvReader())->readString($csv);
|
|
|
|
self::assertSame('Windows-1252', $table->encoding);
|
|
self::assertSame(['kbnr', 'kbtitel', 'kbpmemo', 'kbkp1'], $table->header);
|
|
self::assertCount(2, $table->rows);
|
|
self::assertSame('Pädagogik', $table->rows[0]['kbtitel']);
|
|
self::assertSame("Zeile 1\nZeile 2", $table->rows[0]['kbpmemo']);
|
|
self::assertSame('240,00 €', $table->rows[0]['kbkp1']);
|
|
self::assertSame('Titel "mit" Anführung', $table->rows[1]['kbtitel']);
|
|
self::assertSame('2', $table->rows[0]['__record']);
|
|
}
|
|
|
|
public function testKeepsUtf8AndNamesWithCedilla(): void
|
|
{
|
|
$csv = "\xEF\xBB\xBFkbnr;kbkln1\n\"0000001\";\"Çelik\"\n";
|
|
|
|
$table = (new CsvReader())->readString($csv);
|
|
|
|
self::assertSame('UTF-8', $table->encoding);
|
|
self::assertSame('Çelik', $table->rows[0]['kbkln1']);
|
|
}
|
|
|
|
public function testDoesNotReplaceCedillaInNamesForWindows1252(): void
|
|
{
|
|
$csv = "kbnr;kbkln1;kbkp1\n\"0000001\";\"\xC7elik\";\"12,50 \xC7\"\n";
|
|
|
|
$table = (new CsvReader())->readString($csv);
|
|
|
|
self::assertSame('Çelik', $table->rows[0]['kbkln1']);
|
|
self::assertSame('12,50 €', $table->rows[0]['kbkp1']);
|
|
}
|
|
|
|
public function testPadsShortRowsWithWarning(): void
|
|
{
|
|
$table = (new CsvReader())->readString("a;b;c\n1;2\n");
|
|
|
|
self::assertSame(['a' => '1', 'b' => '2', 'c' => '', '__record' => '2'], $table->rows[0]);
|
|
self::assertCount(1, $table->warnings);
|
|
}
|
|
|
|
public function testRejectsEmptyFile(): void
|
|
{
|
|
$this->expectException(ImportException::class);
|
|
|
|
(new CsvReader())->readString("\n\n");
|
|
}
|
|
}
|