Skip to content

Commit e1f78ca

Browse files
committed
Revert "Don't set the empty string as we display it on the scoreboard"
This reverts commit 9974cec. A better fix was applied in: #2567, the values is now properly validated and we fail if the property is not set. Added another case for this specific case of an empty name.
1 parent c5988a0 commit e1f78ca

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

webapp/src/Service/ImportExportService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,8 @@ public function importTeamsJson(array $data, ?string &$message = null, ?array &$
984984
'icpcid' => $team['icpc_id'] ?? null,
985985
'label' => $team['label'] ?? null,
986986
'categoryid' => $team['group_ids'][0] ?? null,
987-
'name' => $team['name'] ?? null,
988-
'display_name' => $team['display_name'] ?? null,
987+
'name' => $team['name'] ?? '',
988+
'display_name' => $team['display_name'] ?? '',
989989
'publicdescription' => $team['public_description'] ?? $team['members'] ?? '',
990990
'location' => $team['location']['description'] ?? null,
991991
],

webapp/tests/Unit/Service/ImportExportServiceTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,44 @@ public function testImportTeamsJsonError(): void
858858
self::assertEquals($preCount, $postCount);
859859
}
860860

861+
public function testImportTeamsJsonErrorEmptyString(): void
862+
{
863+
$teamsData = <<<EOF
864+
[{
865+
"id": "11",
866+
"icpc_id": "447047",
867+
"label": "team1",
868+
"name": "",
869+
"group_ids": ["24"],
870+
"organization_id": "INST-42",
871+
"location": {"description": "AUD 10"}
872+
}, {
873+
"id": "12",
874+
"icpc_id": "447837",
875+
"group_ids": ["25"],
876+
"name": "Pleading not FAUlty",
877+
"organization_id": "INST-43"
878+
}]
879+
EOF;
880+
$em = static::getContainer()->get(EntityManagerInterface::class);
881+
$preCount = $em->getRepository(Team::class)->count([]);
882+
883+
$fileName = tempnam(static::getContainer()->get(DOMJudgeService::class)->getDomjudgeTmpDir(), 'teams-json');
884+
file_put_contents($fileName, $teamsData);
885+
$file = new UploadedFile($fileName, 'teams.json');
886+
/** @var ImportExportService $importExportService */
887+
$importExportService = static::getContainer()->get(ImportExportService::class);
888+
$importCount = $importExportService->importJson('teams', $file, $message);
889+
// Remove the file, we don't need it anymore.
890+
unlink($fileName);
891+
892+
self::assertMatchesRegularExpression('/name: This value should not be blank./', $message);
893+
self::assertEquals(0, $importCount);
894+
895+
$postCount = $em->getRepository(Team::class)->count([]);
896+
self::assertEquals($preCount, $postCount);
897+
}
898+
861899
public function testImportGroupsTsv(): void
862900
{
863901
// Example from the manual

0 commit comments

Comments
 (0)