ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ScoreSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../UI/tests/Base.php");
22 require_once(__DIR__ . "/../../../../UI/tests/Component/Input/Field/CommonFieldRendering.php");
23 
25 use ILIAS\Test\Scoring\Settings\Settings as SettingsScoring;
30 use ILIAS\UI\Component as C;
32 
34 {
35  use BaseUITestTrait;
37 
38  public function testScoreSettingsBuild(): void
39  {
40  $id = -666;
41  $s = new ScoreSettings(
42  $id,
43  new SettingsScoring($id),
47  );
48  $this->assertInstanceOf(ScoreSettings::class, $s);
49  $this->assertEquals($id, $s->getTestId());
50  $this->assertInstanceOf(SettingsScoring::class, $s->getScoringSettings());
51  $this->assertInstanceOf(SettingsResultSummary::class, $s->getResultSummarySettings());
52  $this->assertInstanceOf(SettingsResultDetails::class, $s->getResultDetailsSettings());
53  $this->assertInstanceOf(SettingsGamification::class, $s->getGamificationSettings());
54  }
55 
56  public function testScoreSettingsScoring(): void
57  {
58  $s = new SettingsScoring(-666);
59  $this->assertEquals(-667, $s->withTestId(-667)->getTestId());
60  $this->assertEquals(2, $s->withCountSystem(2)->getCountSystem());
61  $this->assertEquals(4, $s->withScoreCutting(4)->getScoreCutting());
62  $this->assertEquals(5, $s->withPassScoring(5)->getPassScoring());
63  }
64 
65  public function testScoreSettingsSummary(): void
66  {
67  $dat = new \DateTimeImmutable();
68  $s = new SettingsResultSummary(-666);
69  $this->assertEquals(
70  ScoreReportingTypes::SCORE_REPORTING_AFTER_PASSED,
71  $s->withScoreReporting(ScoreReportingTypes::SCORE_REPORTING_AFTER_PASSED)->getScoreReporting()
72  );
73  $this->assertTrue($s->withShowGradingStatusEnabled(true)->getShowGradingStatusEnabled());
74  $this->assertFalse($s->withShowGradingStatusEnabled(false)->getShowGradingStatusEnabled());
75  $this->assertTrue($s->withShowGradingMarkEnabled(true)->getShowGradingMarkEnabled());
76  $this->assertFalse($s->withShowGradingMarkEnabled(false)->getShowGradingMarkEnabled());
77  $this->assertTrue($s->withPassDeletionAllowed(true)->getPassDeletionAllowed());
78  $this->assertFalse($s->withPassDeletionAllowed(false)->getPassDeletionAllowed());
79  $this->assertTrue($s->withShowPassDetails(true)->getShowPassDetails());
80  $this->assertFalse($s->withShowPassDetails(false)->getShowPassDetails());
81  }
82 
83  public function testScoreSettingsDetails(): void
84  {
85  $s = new SettingsResultDetails(-666);
86  $this->assertEquals(192, $s->withResultsPresentation(192)->getResultsPresentation(192));
87  $this->assertTrue($s->withShowExamIdInTestResults(true)->getShowExamIdInTestResults());
88  $this->assertTrue($s->withShowPassDetails(true)->getShowPassDetails());
89  $this->assertFalse($s->withShowPassDetails(false)->getShowPassDetails());
90  $this->assertTrue($s->withShowSolutionPrintview(true)->getShowSolutionPrintview());
91  $this->assertFalse($s->withShowSolutionPrintview(false)->getShowSolutionPrintview());
92  $this->assertTrue($s->withShowSolutionFeedback(true)->getShowSolutionFeedback());
93  $this->assertFalse($s->withShowSolutionFeedback(false)->getShowSolutionFeedback());
94  $this->assertTrue($s->withShowSolutionAnswersOnly(true)->getShowSolutionAnswersOnly());
95  $this->assertFalse($s->withShowSolutionAnswersOnly(false)->getShowSolutionAnswersOnly());
96  $this->assertTrue($s->withShowSolutionSignature(true)->getShowSolutionSignature());
97  $this->assertFalse($s->withShowSolutionSignature(false)->getShowSolutionSignature());
98  $this->assertTrue($s->withShowSolutionSuggested(true)->getShowSolutionSuggested());
99  $this->assertFalse($s->withShowSolutionSuggested(false)->getShowSolutionSuggested());
100  $this->assertTrue($s->withShowSolutionListComparison(true)->getShowSolutionListComparison());
101  $this->assertFalse($s->withShowSolutionListComparison(false)->getShowSolutionListComparison());
102  $this->assertTrue($s->withShowPassDetails(true)->getShowPassDetails());
103  }
104 
105  public function testScoreSettingsGamification(): void
106  {
107  $s = new SettingsGamification(-666);
108  $this->assertTrue($s->withHighscoreEnabled(true)->getHighscoreEnabled());
109  $this->assertFalse($s->withHighscoreEnabled(false)->getHighscoreEnabled());
110  $this->assertTrue($s->withHighscoreAnon(true)->getHighscoreAnon());
111  $this->assertFalse($s->withHighscoreAnon(false)->getHighscoreAnon());
112  $this->assertTrue($s->withHighscoreAchievedTS(true)->getHighscoreAchievedTS());
113  $this->assertFalse($s->withHighscoreAchievedTS(false)->getHighscoreAchievedTS());
114  $this->assertTrue($s->withHighscoreScore(true)->getHighscoreScore());
115  $this->assertFalse($s->withHighscoreScore(false)->getHighscoreScore());
116  $this->assertTrue($s->withHighscorePercentage(true)->getHighscorePercentage());
117  $this->assertFalse($s->withHighscorePercentage(false)->getHighscorePercentage());
118  $this->assertTrue($s->withHighscoreWTime(true)->getHighscoreWTime());
119  $this->assertFalse($s->withHighscoreWTime(false)->getHighscoreWTime());
120  $this->assertTrue($s->withHighscoreOwnTable(true)->getHighscoreOwnTable());
121  $this->assertFalse($s->withHighscoreOwnTable(false)->getHighscoreOwnTable());
122  $this->assertTrue($s->withHighscoreTopTable(true)->getHighscoreTopTable());
123  $this->assertFalse($s->withHighscoreTopTable(false)->getHighscoreTopTable());
124  $this->assertEquals(15, $s->withHighscoreTopNum(15)->getHighscoreTopNum());
125  }
126 
127  protected function getUIPack()
128  {
129  return [
130  $this->getLanguage(),
131  $this->getFieldFactory(),
132  $this->getRefinery()
133  ];
134  }
135 
136  public function testScoreSettingsSectionScoring(): void
137  {
138  $s = new SettingsScoring(666);
139  $actual = $this->render(
140  $s->toForm(...$this->getUIPack())
141  );
142 
143  $i1 = $this->getFormWrappedHtml(
144  'radio-field-input',
145  'tst_text_count_system',
146  '
147  <div class="c-field-radio">
148  <div class="c-field-radio__item">
149  <input type="radio" id="id_1_0_opt" value="0" checked="checked" />
150  <label for="id_1_0_opt">tst_count_partial_solutions</label>
151  <div class="c-input__help-byline">tst_count_partial_solutions_desc</div>
152  </div>
153 
154  <div class="c-field-radio__item">
155  <input type="radio" id="id_1_1_opt" value="1" />
156  <label for="id_1_1_opt">tst_count_correct_solutions</label>
157  <div class="c-input__help-byline">tst_count_correct_solutions_desc</div>
158  </div>
159  </div>
160  ',
161  null,
162  null,
163  null,
164  ''
165  );
166  $i2 = $this->getFormWrappedHtml(
167  'radio-field-input',
168  'tst_score_cutting',
169  '
170  <div class="c-field-radio">
171  <div class="c-field-radio__item">
172  <input type="radio" id="id_2_0_opt" value="0" checked="checked" />
173  <label for="id_2_0_opt">tst_score_cut_question</label>
174  <div class="c-input__help-byline">tst_score_cut_question_desc</div>
175  </div>
176 
177  <div class="c-field-radio__item">
178  <input type="radio" id="id_2_1_opt" value="1" />
179  <label for="id_2_1_opt">tst_score_cut_test</label>
180  <div class="c-input__help-byline">tst_score_cut_test_desc</div>
181  </div>
182  </div>
183  ',
184  null,
185  null,
186  null,
187  ''
188  );
189  $i3 = $this->getFormWrappedHtml(
190  'radio-field-input',
191  'tst_pass_scoring',
192  '
193  <div class="c-field-radio">
194  <div class="c-field-radio__item">
195  <input type="radio" id="id_3_0_opt" value="0" checked="checked" />
196  <label for="id_3_0_opt">tst_pass_last_pass</label>
197  <div class="c-input__help-byline">tst_pass_last_pass_desc</div>
198  </div>
199 
200  <div class="c-field-radio__item">
201  <input type="radio" id="id_3_1_opt" value="1" />
202  <label for="id_3_1_opt">tst_pass_best_pass</label>
203  <div class="c-input__help-byline">tst_pass_best_pass_desc</div>
204  </div>
205  </div>
206  ',
207  null,
208  null,
209  null,
210  ''
211  );
212 
213  $expected = $this->getFormWrappedHtml(
214  'section-field-input',
215  'test_scoring',
216  $i1 . $i2 . $i3,
217  null,
218  null,
219  null,
220  ''
221  );
222  $this->assertHTMLEquals($expected, $this->brutallyTrimSignals($actual));
223  }
224 
225 
226  public function getUIFactory(): NoUIFactory
227  {
228  return new class () extends NoUIFactory {
229  public function symbol(): S\Factory
230  {
231  return new S\Factory(
232  new S\Icon\Factory(),
233  new S\Glyph\Factory(),
234  new S\Avatar\Factory()
235  );
236  }
237  };
238  }
239 
240  public function testScoreSettingsSectionSummary(): void
241  {
242  $data_factory = new \ILIAS\Data\Factory();
243  $language = $this->getLanguage();
244  $refinery = new \ILIAS\Refinery\Factory($data_factory, $language);
245 
247  $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class),
248  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
249  new \ILIAS\UI\Implementation\Component\SignalGenerator(),
250  $data_factory,
251  $refinery,
252  $language
253  );
254  $ui = [$language, $field_factory, $refinery];
255 
256  $s = new SettingsResultSummary(666);
257  $actual = $this->render(
258  $s->toForm(...array_merge($ui, [[
259  'user_time_zone' => 'Europe/Berlin',
260  'user_date_format' => $data_factory->dateFormat()->withTime24(
261  $data_factory->dateFormat()->standard()
262  )
263  ]]))
264  );
265 
266  $i1_1_1 = $this->getFormWrappedHtml(
267  'group-field-input',
268  '<input type="radio" id="id_2" value="2" /><span>tst_results_access_always</span>',
269  '',
270  'tst_results_access_always_desc',
271  'id_2',
272  null,
273  ''
274  );
275  $i1_1_2 = $this->getFormWrappedHtml(
276  'group-field-input',
277  '<input type="radio" id="id_3" value="1" /><span>tst_results_access_finished</span>',
278  '',
279  'tst_results_access_finished_desc',
280  'id_3',
281  null,
282  ''
283  );
284  $i1_1_3 = $this->getFormWrappedHtml(
285  'group-field-input',
286  '<input type="radio" id="id_4" value="4" /><span>tst_results_access_passed</span>',
287  '',
288  'tst_results_access_passed_desc',
289  'id_4',
290  null,
291  ''
292  );
293 
294  $i1_1_4_1 = $this->getFormWrappedHtml(
295  'date-time-field-input',
296  'tst_reporting_date<span class="asterisk" aria-label="required_field">*</span>',
297  '<div class="c-input-group">
298  <input id="id_6" type="datetime-local" class="c-field-datetime" />
299  </div>',
300  null,
301  'id_6',
302  null,
303  ''
304  );
305 
306  $i1_1_4 = $this->getFormWrappedHtml(
307  'group-field-input',
308  '<input type="radio" id="id_5" value="3" /><span>tst_results_access_date</span><span class="asterisk" aria-label="required_field">*</span>',
309  $i1_1_4_1,
310  'tst_results_access_date_desc',
311  'id_5',
312  null,
313  ''
314  );
315 
316  $i1_1 = $this->getFormWrappedHtml(
317  'switchable-group-field-input',
318  'tst_results_access_setting<span class="asterisk" aria-label="required_field">*</span>',
319  $i1_1_1 . $i1_1_2 . $i1_1_3 . $i1_1_4,
320  null,
321  null,
322  null,
323  ''
324  );
325 
326  $i1_2 = $this->getFormWrappedHtml(
327  'checkbox-field-input',
328  'tst_results_grading_opt_show_status',
329  '<input type="checkbox" id="id_7" value="checked" class="c-field-checkbox" />',
330  'tst_results_grading_opt_show_status_desc',
331  'id_7',
332  null,
333  ''
334  );
335  $i1_3 = $this->getFormWrappedHtml(
336  'checkbox-field-input',
337  'tst_results_grading_opt_show_mark',
338  '<input type="checkbox" id="id_8" value="checked" class="c-field-checkbox" />',
339  'tst_results_grading_opt_show_mark_desc',
340  'id_8',
341  null,
342  ''
343  );
344  $i1_4 = $this->getFormWrappedHtml(
345  'checkbox-field-input',
346  'tst_results_grading_opt_show_details',
347  '<input type="checkbox" id="id_9" value="checked" class="c-field-checkbox" />',
348  'tst_results_grading_opt_show_details_desc',
349  'id_9',
350  null,
351  ''
352  );
353  $i1_5 = $this->getFormWrappedHtml(
354  'checkbox-field-input',
355  'tst_pass_deletion',
356  '<input type="checkbox" id="id_10" value="checked" class="c-field-checkbox" />',
357  'tst_pass_deletion_allowed',
358  'id_10',
359  null,
360  ''
361  );
362 
363  $i1 = $this->getFormWrappedHtml(
364  'optional-group-field-input',
365  '<span>tst_results_access_enabled</span><input type="checkbox" id="id_1" value="checked" />',
366  $i1_1 . $i1_2 . $i1_3 . $i1_4 . $i1_5,
367  'tst_results_access_enabled_desc',
368  'id_1',
369  null,
370  ''
371  );
372 
373  $expected = $this->getFormWrappedHtml(
374  'section-field-input',
375  'test_results',
376  $i1,
377  null,
378  null,
379  null,
380  ''
381  );
382  $this->assertEquals($expected, $this->brutallyTrimSignals($actual));
383  }
384 
385 
386  public function testScoreSettingsSectionDetails(): void
387  {
388  $s = new SettingsResultDetails(666);
389  $tax_ids = [1,2];
390  $actual = $this->render(
391  $s->toForm(
392  ...array_merge(
393  $this->getUIPack(),
394  [['taxonomy_options' => $tax_ids]]
395  )
396  )
397  );
398  $opts = [
399  ['tst_results_print_best_solution', 'tst_results_print_best_solution_info'],
400  ['tst_show_solution_feedback', 'tst_show_solution_feedback_desc'],
401  ['tst_show_solution_suggested', 'tst_show_solution_suggested_desc'],
402  ['tst_show_solution_printview', 'tst_show_solution_printview_desc'],
403  ['tst_hide_pagecontents', 'tst_hide_pagecontents_desc'],
404  ['tst_show_solution_signature', 'tst_show_solution_signature_desc'],
405  ['examid_in_test_res', 'examid_in_test_res_desc'],
406  ];
407  $options = '';
408  foreach ($opts as $index => $entry) {
409  list($label, $byline) = $entry;
410  $nr = (string) ($index + 1);
411  $checked = $index === 6 ? ' checked="checked"' : '';
412  $field_html = '<input type="checkbox" id="id_' . $nr . '" value="checked"' . $checked . ' class="c-field-checkbox" />';
413  $options .= $this->getFormWrappedHtml(
414  'checkbox-field-input',
415  $label,
416  $field_html,
417  $byline,
418  'id_' . $nr,
419  null,
420  ''
421  );
422  }
423 
424  $expected = $this->getFormWrappedHtml(
425  'section-field-input',
426  'tst_results_details_options',
427  $options,
428  null,
429  null,
430  null,
431  ''
432  );
433  $this->assertEquals($expected, $this->brutallyTrimSignals($actual));
434  }
435 
436 
437  public function testScoreSettingsSectionGamification(): void
438  {
439  $s = new SettingsGamification(666);
440  $actual = $this->render(
441  $s->toForm(...$this->getUIPack())
442  );
443 
444  $fields = $this->getFormWrappedHtml(
445  'radio-field-input',
446  'tst_highscore_mode<span class="asterisk" aria-label="required_field">*</span>',
447  '<div class="c-field-radio">
448  <div class="c-field-radio__item">
449  <input type="radio" id="id_2_1_opt" value="1" /><label for="id_2_1_opt">tst_highscore_own_table</label><div class="c-input__help-byline">tst_highscore_own_table_description</div>
450  </div>
451  <div class="c-field-radio__item">
452  <input type="radio" id="id_2_2_opt" value="2" /><label for="id_2_2_opt">tst_highscore_top_table</label><div class="c-input__help-byline">tst_highscore_top_table_description</div>
453  </div>
454  <div class="c-field-radio__item">
455  <input type="radio" id="id_2_3_opt" value="3" checked="checked" /><label for="id_2_3_opt">tst_highscore_all_tables</label><div class="c-input__help-byline">tst_highscore_all_tables_description</div>
456  </div>
457  </div>',
458  null,
459  null,
460  null,
461  ''
462  );
463  $fields .= $this->getFormWrappedHtml(
464  'numeric-field-input',
465  'tst_highscore_top_num<span class="asterisk" aria-label="required_field">*</span>',
466  '<input id="id_3" type="number" step="1" value="10" class="c-field-number" />',
467  'tst_highscore_top_num_description',
468  'id_3',
469  null,
470  ''
471  );
472 
473 
474  $opts = [
475  ['tst_highscore_anon', 'tst_highscore_anon_description'],
476  ['tst_highscore_achieved_ts', 'tst_highscore_achieved_ts_description'],
477  ['tst_highscore_score', 'tst_highscore_score_description'],
478  ['tst_highscore_percentage', 'tst_highscore_percentage_description'],
479  ['tst_highscore_wtime', 'tst_highscore_wtime_description']
480  ];
481  foreach ($opts as $index => $entry) {
482  list($label, $byline) = $entry;
483  $nr = (string) ($index + 4);
484  $field_html = '<input type="checkbox" id="id_' . $nr . '" value="checked" checked="checked" class="c-field-checkbox" />';
485  $fields .= $this->getFormWrappedHtml(
486  'checkbox-field-input',
487  $label,
488  $field_html,
489  $byline,
490  'id_' . $nr,
491  null,
492  ''
493  );
494  }
495 
496  $group = $this->getFormWrappedHtml(
497  'optional-group-field-input',
498  '<span>tst_highscore_enabled</span><input type="checkbox" id="id_1" value="checked" />',
499  $fields,
500  'tst_highscore_description',
501  'id_1',
502  null,
503  ''
504  );
505 
506  $expected = $this->getFormWrappedHtml(
507  'section-field-input',
508  'tst_results_gamification',
509  $group,
510  null,
511  null,
512  null,
513  ''
514  );
515  $this->assertHTMLEquals($expected, $this->brutallyTrimSignals($actual));
516  }
517 
519  {
520  $id = -666;
521  $s = new ScoreSettings(
522  $id,
523  new SettingsScoring($id),
527  );
528 
529  $t = new class ($s) extends ilObjTest {
530  public function __construct($s)
531  {
532  $this->score_settings = $s;
533  }
534  };
535 
536  $this->assertIsInt($t->getCountSystem());
537  $this->assertIsInt($t->getScoreCutting());
538  $this->assertIsInt($t->getPassScoring());
539  $this->assertIsBool($t->getShowPassDetails());
540  $this->assertIsBool($t->getShowSolutionAnswersOnly());
541  $this->assertIsBool($t->getShowSolutionSignature());
542  $this->assertIsBool($t->getShowSolutionSuggested());
543  $this->assertIsBool($t->getShowSolutionListComparison());
544  $this->assertIsBool($t->isPassDeletionAllowed());
545  $this->assertIsInt($t->getExportSettings());
546  $this->assertIsBool($t->getHighscoreEnabled());
547  $this->assertIsBool($t->getHighscoreAnon());
548  $this->assertIsBool($t->getHighscoreAchievedTS());
549  $this->assertIsBool($t->getHighscoreScore());
550  $this->assertIsBool($t->getHighscorePercentage());
551  $this->assertIsBool($t->getHighscoreWTime());
552  $this->assertIsBool($t->getHighscoreOwnTable());
553  $this->assertIsBool($t->getHighscoreTopTable());
554  $this->assertIsInt($t->getHighscoreTopNum());
555  $this->assertIsInt($t->getHighscoreMode());
556  }
557 
558  public function testScoreSettingsRelayingTestId(): void
559  {
560  $id = -666;
561  $s = new ScoreSettings(
562  $id,
563  new SettingsScoring($id),
567  );
568 
569  $nu_id = 1234;
570  $s = $s->withTestId($nu_id);
571  $this->assertEquals($nu_id, $s->getTestId());
572  $this->assertEquals($nu_id, $s->getScoringSettings()->getTestId());
573  $this->assertEquals($nu_id, $s->getResultSummarySettings()->getTestId());
574  $this->assertEquals($nu_id, $s->getResultDetailsSettings()->getTestId());
575  $this->assertEquals($nu_id, $s->getGamificationSettings()->getTestId());
576  }
577 }
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getLanguage()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)