mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 12:42:15 +01:00
Fixed escaping issues in importer
This commit is contained in:
committed by
Constantin Graf
parent
4c27f1a2de
commit
85f4a3049c
@@ -47,6 +47,8 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
|||||||
$reader = Reader::createFromString($data);
|
$reader = Reader::createFromString($data);
|
||||||
$reader->setHeaderOffset(0);
|
$reader->setHeaderOffset(0);
|
||||||
$reader->setDelimiter(',');
|
$reader->setDelimiter(',');
|
||||||
|
$reader->setEnclosure('"');
|
||||||
|
$reader->setEscape('');
|
||||||
$header = $reader->getHeader();
|
$header = $reader->getHeader();
|
||||||
$this->validateHeader($header);
|
$this->validateHeader($header);
|
||||||
$records = $reader->getRecords();
|
$records = $reader->getRecords();
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ class TogglTimeEntriesImporter extends DefaultImporter
|
|||||||
$reader = Reader::createFromString($data);
|
$reader = Reader::createFromString($data);
|
||||||
$reader->setHeaderOffset(0);
|
$reader->setHeaderOffset(0);
|
||||||
$reader->setDelimiter(',');
|
$reader->setDelimiter(',');
|
||||||
|
$reader->setEnclosure('"');
|
||||||
|
$reader->setEscape('');
|
||||||
$header = $reader->getHeader();
|
$header = $reader->getHeader();
|
||||||
$this->validateHeader($header);
|
$this->validateHeader($header);
|
||||||
$records = $reader->getRecords();
|
$records = $reader->getRecords();
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
"Project","Client","Description","Task","User","Group","Email","Tags","Type","Billable","Invoiced","Invoice ID","Start Date","Start Time","End Date","End Time","Duration (h)","Duration (decimal)","Billable Rate (EUR)","Billable Amount (EUR)","Date of creation"
|
||||||
|
"Real World Project","Real World Client","\\ 🔥 Special characters ''''''`!@#$%^&*()_+\-=\[\]{};':''\\|,.''<>\/?~ \\\","A giant task","Peter Tester","Group1, Group2","peter.test@email.test","","Regular","Yes","Yes","Invoice100","10/15/2024","11:00:00 AM","10/15/2024","11:30:00 AM","00:30:00","0.50","1000.00","500.00","10/15/2024"
|
||||||
|
2
resources/testfiles/toggl_time_entries_import_test_2.csv
Normal file
2
resources/testfiles/toggl_time_entries_import_test_2.csv
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
"User","Email","Client","Project","Task","Description","Billable","Start date","Start time","End date","End time","Duration","Tags"
|
||||||
|
"Peter Tester","peter.test@email.test","Real World Client","Real World Project","A giant task","\\ 🔥 Special characters """"""`!@#$%^&*()_+\-=\[\]{};':""\\|,.''<>\/?~ \\\","No","2024-10-15","12:02:17","2024-10-15","12:02:19","00:00:02",""
|
||||||
|
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Tests\Unit\Service\Import\Importers;
|
namespace Tests\Unit\Service\Import\Importers;
|
||||||
|
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
|
use App\Models\TimeEntry;
|
||||||
use App\Service\Import\Importers\ClockifyTimeEntriesImporter;
|
use App\Service\Import\Importers\ClockifyTimeEntriesImporter;
|
||||||
use App\Service\Import\Importers\DefaultImporter;
|
use App\Service\Import\Importers\DefaultImporter;
|
||||||
use App\Service\Import\Importers\ImportException;
|
use App\Service\Import\Importers\ImportException;
|
||||||
@@ -42,6 +43,31 @@ class ClockifyTimeEntriesImporterTest extends ImporterTestAbstract
|
|||||||
$this->assertSame(1, $report->clientsCreated);
|
$this->assertSame(1, $report->clientsCreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_import_of_test_with_special_characters_description_succeeds(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
$timezone = 'Europe/Vienna';
|
||||||
|
$importer = new ClockifyTimeEntriesImporter;
|
||||||
|
$importer->init($organization);
|
||||||
|
// Description: \\ 🔥 Special characters """`!@#$%^&*()_+\-=\[\]{};':"\\|,.''<>\/?~ \\\
|
||||||
|
$data = Storage::disk('testfiles')->get('clockify_time_entries_import_test_2.csv');
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$importer->importData($data, $timezone);
|
||||||
|
$report = $importer->getReport();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$timeEntry = TimeEntry::first();
|
||||||
|
$this->assertSame('\\\\ 🔥 Special characters \'\'\'\'\'\'`!@#$%^&*()_+\-=\[\]{};\':\'\'\\\\|,.\'\'<>\/?~ \\\\\\', $timeEntry->description);
|
||||||
|
$this->assertSame(1, $report->timeEntriesCreated);
|
||||||
|
$this->assertSame(0, $report->tagsCreated);
|
||||||
|
$this->assertSame(1, $report->tasksCreated);
|
||||||
|
$this->assertSame(1, $report->usersCreated);
|
||||||
|
$this->assertSame(1, $report->projectsCreated);
|
||||||
|
$this->assertSame(1, $report->clientsCreated);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_import_of_test_file_twice_succeeds(): void
|
public function test_import_of_test_file_twice_succeeds(): void
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Tests\Unit\Service\Import\Importers;
|
namespace Tests\Unit\Service\Import\Importers;
|
||||||
|
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
|
use App\Models\TimeEntry;
|
||||||
use App\Service\Import\Importers\DefaultImporter;
|
use App\Service\Import\Importers\DefaultImporter;
|
||||||
use App\Service\Import\Importers\ImportException;
|
use App\Service\Import\Importers\ImportException;
|
||||||
use App\Service\Import\Importers\TogglTimeEntriesImporter;
|
use App\Service\Import\Importers\TogglTimeEntriesImporter;
|
||||||
@@ -47,6 +48,31 @@ class TogglTimeEntriesImporterTest extends ImporterTestAbstract
|
|||||||
$this->assertSame(1, $report->clientsCreated);
|
$this->assertSame(1, $report->clientsCreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_import_of_test_with_special_characters_description_succeeds(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
$timezone = 'Europe/Vienna';
|
||||||
|
$importer = new TogglTimeEntriesImporter;
|
||||||
|
$importer->init($organization);
|
||||||
|
// Description: \\ 🔥 Special characters """`!@#$%^&*()_+\-=\[\]{};':"\\|,.''<>\/?~ \\\
|
||||||
|
$data = Storage::disk('testfiles')->get('toggl_time_entries_import_test_2.csv');
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$importer->importData($data, $timezone);
|
||||||
|
$report = $importer->getReport();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$timeEntry = TimeEntry::first();
|
||||||
|
$this->assertSame('\\\\ 🔥 Special characters """`!@#$%^&*()_+\-=\[\]{};\':"\\\\|,.\'\'<>\/?~ \\\\\\', $timeEntry->description);
|
||||||
|
$this->assertSame(1, $report->timeEntriesCreated);
|
||||||
|
$this->assertSame(0, $report->tagsCreated);
|
||||||
|
$this->assertSame(1, $report->tasksCreated);
|
||||||
|
$this->assertSame(1, $report->usersCreated);
|
||||||
|
$this->assertSame(1, $report->projectsCreated);
|
||||||
|
$this->assertSame(1, $report->clientsCreated);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_import_of_test_file_twice_succeeds(): void
|
public function test_import_of_test_file_twice_succeeds(): void
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|||||||
Reference in New Issue
Block a user