Skip to content

Commit c4d5da0

Browse files
committed
Fix saving config options in base test.
Prior to this change we were always resetting missing booleans to false here: https://github.com/DOMjudge/domjudge/blob/98b0b138de4fc7c2330ac957e88d2e9c83792795/webapp/src/Service/ConfigurationService.php#L200 Since in the base test (https://github.com/DOMjudge/domjudge/blob/98b0b138de4fc7c2330ac957e88d2e9c83792795/webapp/tests/Unit/BaseTestCase.php#L325) we change the data source, this also reset all booleans that were true by default in `etc/db-config.yaml`. Once we move to Symfony forms, we can likely remove this special casing alltogether.
1 parent e0c5ed9 commit c4d5da0

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

webapp/src/Controller/Jury/ConfigController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function indexAction(EventLogService $eventLogService, Request $request):
6666
}
6767
}
6868
$before = $this->config->all();
69-
$errors = $this->config->saveChanges($data, $eventLogService, $this->dj, $options);
69+
$errors = $this->config->saveChanges($data, $eventLogService, $this->dj, options: $options);
7070
$after = $this->config->all();
7171

7272
// Compile a list of differences.

webapp/src/Service/ConfigurationService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public function saveChanges(
166166
array $dataToSet,
167167
EventLogService $eventLog,
168168
DOMJudgeService $dj,
169+
bool $treatMissingBooleansAsFalse = true,
169170
?array &$options = null
170171
): array {
171172
$specs = $this->getConfigSpecification();
@@ -196,7 +197,7 @@ public function saveChanges(
196197
$options[$specName] = $optionToSet;
197198
}
198199
if (!array_key_exists($specName, $dataToSet)) {
199-
if ($spec->type == 'bool') {
200+
if ($spec->type == 'bool' && $treatMissingBooleansAsFalse) {
200201
// Special-case bool, since checkboxes don't return a
201202
// value when unset.
202203
$val = false;

webapp/tests/Unit/BaseTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,6 @@ protected function setupDataSource(int $dataSource): void
322322
$config = self::getContainer()->get(ConfigurationService::class);
323323
$eventLog = self::getContainer()->get(EventLogService::class);
324324
$dj = self::getContainer()->get(DOMJudgeService::class);
325-
$config->saveChanges(['data_source'=>$dataSource], $eventLog, $dj);
325+
$config->saveChanges(['data_source'=>$dataSource], $eventLog, $dj, treatMissingBooleansAsFalse: false);
326326
}
327327
}

0 commit comments

Comments
 (0)