mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Fixed error handling of structural data import
This was the reason for the exception in #632
This commit is contained in:
parent
64414fe105
commit
b7b941e3a1
4 changed files with 98 additions and 10 deletions
|
@ -27,11 +27,13 @@ use App\Entity\Attachments\AttachmentType;
|
|||
use App\Entity\LabelSystem\LabelProfile;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Services\ImportExportSystem\EntityImporter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\Validator\ConstraintViolation;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
|
@ -190,6 +192,63 @@ EOT;
|
|||
$this->assertSame($expected, $this->service->determineFormat($extension));
|
||||
}
|
||||
|
||||
public function testImportStringProjects(): void
|
||||
{
|
||||
$input = <<<EOT
|
||||
name;comment
|
||||
Test 1;Test 1 notes
|
||||
Test 2;Test 2 notes
|
||||
EOT;
|
||||
|
||||
$errors = [];
|
||||
|
||||
$results = $this->service->importString($input, [
|
||||
'class' => Project::class,
|
||||
'format' => 'csv',
|
||||
'csv_delimiter' => ';',
|
||||
], $errors);
|
||||
|
||||
$this->assertCount(2, $results);
|
||||
|
||||
//No errors must be present
|
||||
$this->assertEmpty($errors);
|
||||
|
||||
|
||||
$this->assertContainsOnlyInstancesOf(Project::class, $results);
|
||||
|
||||
$this->assertSame('Test 1', $results[0]->getName());
|
||||
$this->assertSame('Test 1 notes', $results[0]->getComment());
|
||||
}
|
||||
|
||||
public function testImportStringProjectWithErrors(): void
|
||||
{
|
||||
$input = <<<EOT
|
||||
name;comment
|
||||
;Test 1 notes
|
||||
Test 2;Test 2 notes
|
||||
EOT;
|
||||
|
||||
$errors = [];
|
||||
|
||||
$results = $this->service->importString($input, [
|
||||
'class' => Project::class,
|
||||
'format' => 'csv',
|
||||
'csv_delimiter' => ';',
|
||||
], $errors);
|
||||
|
||||
$this->assertCount(1, $results);
|
||||
$this->assertCount(1, $errors);
|
||||
|
||||
//Validate shape of error output
|
||||
|
||||
$this->assertArrayHasKey('Row 0', $errors);
|
||||
$this->assertArrayHasKey('entity', $errors['Row 0']);
|
||||
$this->assertArrayHasKey('violations', $errors['Row 0']);
|
||||
|
||||
$this->assertInstanceOf(ConstraintViolationListInterface::class, $errors['Row 0']['violations']);
|
||||
$this->assertInstanceOf(Project::class, $errors['Row 0']['entity']);
|
||||
}
|
||||
|
||||
public function testImportStringParts(): void
|
||||
{
|
||||
$input = <<<EOT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue