diff --git a/webapp/src/Service/ImportExportService.php b/webapp/src/Service/ImportExportService.php index 17ee3a17d6..314f79ef3d 100644 --- a/webapp/src/Service/ImportExportService.php +++ b/webapp/src/Service/ImportExportService.php @@ -984,8 +984,8 @@ public function importTeamsJson(array $data, ?string &$message = null, ?array &$ 'icpcid' => $team['icpc_id'] ?? null, 'label' => $team['label'] ?? null, 'categoryid' => $team['group_ids'][0] ?? null, - 'name' => $team['name'] ?? null, - 'display_name' => $team['display_name'] ?? null, + 'name' => $team['name'] ?? '', + 'display_name' => $team['display_name'] ?? '', 'publicdescription' => $team['public_description'] ?? $team['members'] ?? '', 'location' => $team['location']['description'] ?? null, ], diff --git a/webapp/tests/Unit/Service/ImportExportServiceTest.php b/webapp/tests/Unit/Service/ImportExportServiceTest.php index 24e670c138..658deb52f3 100644 --- a/webapp/tests/Unit/Service/ImportExportServiceTest.php +++ b/webapp/tests/Unit/Service/ImportExportServiceTest.php @@ -858,6 +858,44 @@ public function testImportTeamsJsonError(): void self::assertEquals($preCount, $postCount); } + public function testImportTeamsJsonErrorEmptyString(): void + { + $teamsData = <<get(EntityManagerInterface::class); + $preCount = $em->getRepository(Team::class)->count([]); + + $fileName = tempnam(static::getContainer()->get(DOMJudgeService::class)->getDomjudgeTmpDir(), 'teams-json'); + file_put_contents($fileName, $teamsData); + $file = new UploadedFile($fileName, 'teams.json'); + /** @var ImportExportService $importExportService */ + $importExportService = static::getContainer()->get(ImportExportService::class); + $importCount = $importExportService->importJson('teams', $file, $message); + // Remove the file, we don't need it anymore. + unlink($fileName); + + self::assertMatchesRegularExpression('/name: This value should not be blank./', $message); + self::assertEquals(0, $importCount); + + $postCount = $em->getRepository(Team::class)->count([]); + self::assertEquals($preCount, $postCount); + } + public function testImportGroupsTsv(): void { // Example from the manual