Skip to content

Commit

Permalink
Test: Fix scoring datetime handling (#6278)
Browse files Browse the repository at this point in the history
* Test: Fix scoring datetime handling
* Test: Save Reporting Date as UTC

---------

Co-authored-by: Stephan Kergomard <[email protected]>
  • Loading branch information
mjansenDatabay and kergomard committed Aug 31, 2023
1 parent 9668ff1 commit a54812f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ protected function doSelect(string $where_part): ilObjTestScoreSettings
if ($reporting_date) {
$reporting_date = \DateTimeImmutable::createFromFormat(
self::STORAGE_DATE_FORMAT,
$reporting_date
$reporting_date,
new DateTimeZone('UTC')
);
} else {
$reporting_date = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ function ($v) {
self::SCORE_REPORTING_DATE => $f->group(
[
$f->dateTime($lng->txt('tst_reporting_date'), "")
->withTimezone($environment['user_time_zone'])
->withUseTime(true)
->withValue($this->getReportingDate())
->withValue(
$this->getReportingDate()?->setTimezone(
new DateTimeZone($environment['user_time_zone'])
)->format($environment['user_date_format'])
)
->withRequired(true)
],
$lng->txt('tst_results_access_date'),
Expand Down Expand Up @@ -156,7 +161,8 @@ public function toStorage(): array
{
$dat = $this->getReportingDate();
if ($dat) {
$dat = $dat->format(ilObjTestScoreSettingsDatabaseRepository::STORAGE_DATE_FORMAT);
$dat = $dat->setTimezone(new DateTimeZone('UTC'))
->format(ilObjTestScoreSettingsDatabaseRepository::STORAGE_DATE_FORMAT);
}
return [
'pass_deletion_allowed' => ['integer', (int) $this->getPassDeletionAllowed()],
Expand Down
6 changes: 5 additions & 1 deletion Modules/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@ public function executeCommand(): void
$ilTabs,
$this->getTestObject()->getScoreSettingsRepository(),
$this->getTestObject()->getTestId(),
...$this->ui
$this->ui[0],
$this->ui[1],
$this->ui[2],
$this->ui[3],
$this->user
);

$this->ctrl->forwardCommand($gui);
Expand Down
26 changes: 22 additions & 4 deletions Modules/Test/classes/class.ilObjTestSettingsScoringResultsGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer as UIRenderer;
use ILIAS\Refinery\Factory as Refinery;
use ILIAS\UI\Component\Input\Field;
use ILIAS\UI\Component\Input\Container\Form\Form;
use Psr\Http\Message\ServerRequestInterface as Request;

Expand Down Expand Up @@ -63,6 +62,7 @@ class ilObjTestSettingsScoringResultsGUI extends ilTestSettingsGUI
protected UIRenderer $ui_renderer;
protected Refinery $refinery;
protected ilTabsGUI $tabs;
protected ilObjUser $active_user;


public function __construct(
Expand All @@ -80,7 +80,8 @@ public function __construct(
UIFactory $ui_factory,
UIRenderer $ui_renderer,
Refinery $refinery,
Request $request
Request $request,
ilObjUser $active_user
) {
$this->ctrl = $ctrl;
$this->access = $access;
Expand All @@ -92,6 +93,7 @@ public function __construct(
$this->testOBJ = $testGUI->getObject();
$this->tpl = $main_template;
$this->tabs = $tabs;
$this->active_user = $active_user;

$this->testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory(
$this->tree,
Expand Down Expand Up @@ -223,14 +225,30 @@ private function buildForm(): Form
$this->refinery
];

$anonymity_flag = (bool) $this->testOBJ->getAnonymity();
$environment = [];
$df = (new \ILIAS\Data\Factory())->dateFormat();
switch ($this->active_user->getDateFormat()) {
case ilCalendarSettings::DATE_FORMAT_DMY:
$date_format = $df->germanShort();
break;
case ilCalendarSettings::DATE_FORMAT_MDY:
//americanShort
$date_format = $df->custom()->month()->slash()->day()->slash()->year()->get();
break;
case ilCalendarSettings::DATE_FORMAT_YMD:
default:
$date_format = $df->standard();
}
$environment['user_date_format'] = $date_format->toString() . 'H:i';
$environment['user_time_zone'] = $this->active_user->getTimeZone();

$disabled_flag = ($this->areScoringSettingsWritable() === false);

$settings = $this->loadScoreSettings();
$sections = [
'scoring' => $settings->getScoringSettings()->toForm(...$ui_pack)
->withDisabled($disabled_flag),
'summary' => $settings->getResultSummarySettings()->toForm(...$ui_pack),
'summary' => $settings->getResultSummarySettings()->toForm(...array_merge($ui_pack, [$environment])),
'details' => $settings->getResultDetailsSettings()->toForm(
...array_merge($ui_pack, [['taxonomy_options' => $this->getTaxonomyOptions()]])
),
Expand Down
21 changes: 13 additions & 8 deletions Modules/Test/test/ScoreSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function testScoreSettingsSectionScoring(): void
$expected = <<<EOT
<div class="il-section-input">
<div class="il-section-input-header"><h2>test_scoring</h2></div>
<div class="form-group row">
<label class="control-label col-sm-4 col-md-3 col-lg-2">tst_text_count_system</label>
<div class="col-sm-8 col-md-9 col-lg-10">
Expand All @@ -185,7 +185,7 @@ public function testScoreSettingsSectionScoring(): void
<label class="control-label col-sm-4 col-md-3 col-lg-2">tst_score_cutting</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<div id="id_2" class="il-input-radio">
<div class="form-control form-control-sm il-input-radiooption">
<input type="radio" id="id_2_0_opt" name="" value="0" checked="checked" />
<label for="id_2_0_opt">tst_score_cut_question</label>
Expand Down Expand Up @@ -259,7 +259,12 @@ public function testScoreSettingsSectionSummary(): void

$s = new ilObjTestSettingsResultSummary(666);
$actual = $this->getDefaultRenderer()->render(
$s->toForm(...$ui)
$s->toForm(...array_merge($ui, [[
'user_time_zone' => 'Europe/Berlin',
'user_date_format' => $data_factory->dateFormat()->withTime24(
$data_factory->dateFormat()->standard()
)
]]))
);

$expected = <<<EOT
Expand Down Expand Up @@ -307,7 +312,7 @@ public function testScoreSettingsSectionSummary(): void
</div>
</div>
</div>
<div class="form-group row">
<label for="id_4" class="control-label col-sm-4 col-md-3 col-lg-2">tst_results_grading_opt_show_status</label>
<div class="col-sm-8 col-md-9 col-lg-10">
Expand Down Expand Up @@ -474,13 +479,13 @@ public function testScoreSettingsSectionGamification(): void
<div class="il-section-input">
<div class="il-section-input-header"><h2>tst_results_gamification</h2></div>
<div class="form-group row">
<label for="id_10" class="control-label col-sm-4 col-md-3 col-lg-2">tst_highscore_enabled</label>
<div class="col-sm-8 col-md-9 col-lg-10">
<input type="checkbox" id="id_10" value="checked" name="" class="form-control form-control-sm" />
<div class="help-block">tst_highscore_description</div>
<div class="form-group row">
<label class="control-label col-sm-4 col-md-3 col-lg-2">tst_highscore_mode<span class="asterisk">*</span></label>
<div class="col-sm-8 col-md-9 col-lg-10">
Expand Down Expand Up @@ -513,7 +518,7 @@ public function testScoreSettingsSectionGamification(): void
<div class="help-block">tst_highscore_top_num_description</div>
</div>
</div>
<div class="form-group row">
<label for="id_4" class="control-label col-sm-4 col-md-3 col-lg-2">tst_highscore_anon</label>
<div class="col-sm-8 col-md-9 col-lg-10">
Expand Down Expand Up @@ -556,7 +561,7 @@ public function testScoreSettingsSectionGamification(): void
<div class="help-block">tst_highscore_wtime_description</div>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion Modules/Test/test/ilObjTestSettingsScoringResultsGUITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function testScoringResultsGUIConstruct(): void
$ui_factory,
$ui_renderer,
$refinery,
$request
$request,
$this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock(),
);

$this->assertInstanceOf(ilObjTestSettingsScoringResultsGUI::class, $this->testObj);
Expand Down

0 comments on commit a54812f

Please sign in to comment.