Skip to content

Commit

Permalink
Test: Fix Inconsistent Behavior in ChoiceQuestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Nov 5, 2024
1 parent 2272870 commit 9147c5c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,13 @@ public function loadFromDb($questionId): void
$this->setOptionLabel($data['opt_label']);
}

$this->setCustomTrueOptionLabel($data['custom_true']);
$this->setCustomFalseOptionLabel($data['custom_false']);
if ($data['custom_true'] !== null) {
$this->setCustomTrueOptionLabel($data['custom_true']);
}

if ($data['custom_false'] !== null) {
$this->setCustomFalseOptionLabel($data['custom_false']);
}

if ($data['score_partsol'] !== null) {
$this->setScorePartialSolutionEnabled((bool) $data['score_partsol']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,16 @@ public function writeQuestionSpecificPostData(ilPropertyFormGUI $form): void
*/
public function populateAnswerSpecificFormPart(ilPropertyFormGUI $form): ilPropertyFormGUI
{
$kprimAnswers = new ilKprimChoiceWizardInputGUI($this->lng->txt('answers'), 'kprimanswers');
$kprimAnswers->setInfo($this->lng->txt('kprim_answers_info'));
$kprimAnswers->setSize(64);
$kprimAnswers->setMaxLength(1000);
$kprimAnswers->setRequired(true);
$kprimAnswers->setAllowMove(true);
$kprimAnswers->setQuestionObject($this->object);
if (!$this->object->getSelfAssessmentEditingMode()) {
$kprimAnswers->setSingleline($this->object->isSingleLineAnswerType($this->object->getAnswerType()));
} else {
$kprimAnswers->setSingleline(false);
}
$kprimAnswers->setValues($this->object->getAnswers());
$form->addItem($kprimAnswers);
$answers = new ilKprimChoiceWizardInputGUI($this->lng->txt('answers'), 'kprimanswers');
$answers->setInfo($this->lng->txt('kprim_answers_info'));
$answers->setSize(64);
$answers->setMaxLength(1000);
$answers->setRequired(true);
$answers->setAllowMove(true);
$answers->setQuestionObject($this->object);
$answers->setSingleline($this->object->isSingleLineAnswerType($this->object->getAnswerType()));
$answers->setValues($this->object->getAnswers());
$form->addItem($answers);

return $form;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public function setIsSingleline(bool $is_singleline): void
$this->is_singleline = $is_singleline;
}

public function getIsSingleline(): bool
{
return $this->is_singleline;
}

/**
* assMultipleChoice constructor
*
Expand Down Expand Up @@ -138,7 +133,7 @@ public function loadFromDb(int $question_id): void
if ($data['thumb_size'] !== null && $data['thumb_size'] >= self::MINIMUM_THUMB_SIZE) {
$this->setThumbSize($data['thumb_size']);
}
$this->is_singleline = $data['allow_images'] === '0';
$this->is_singleline = $data['allow_images'] === null || $data['allow_images'] === '0';
$this->lastChange = $data['tstamp'];
$this->setSelectionLimit((int) $data['selection_limit'] > 0 ? (int) $data['selection_limit'] : null);
if (isset($data['feedback_setting'])) {
Expand Down Expand Up @@ -884,9 +879,9 @@ protected function buildTestPresentationConfig(): ilTestQuestionConfig
return $config;
}

public function isSingleline()
public function isSingleline(): bool
{
return (bool) $this->is_singleline;
return $this->is_singleline;
}

public function toLog(AdditionalInformationGenerator $additional_info): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ protected function writePostData(bool $always = false): int
*/
protected function getEditAnswersSingleLine($checkonly = false): bool
{
if ($this->object->getSelfAssessmentEditingMode()) {
return $this->object->isSingleline();
}

if ($checkonly) {
return $this->request->int('types') === 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use ILIAS\TestQuestionPool\Questions\QuestionLMExportable;
use ILIAS\TestQuestionPool\Questions\QuestionAutosaveable;
use ILIAS\TestQuestionPool\ManipulateImagesInChoiceQuestionsTrait;

use ILIAS\Test\Logging\AdditionalInformationGenerator;

/**
Expand Down Expand Up @@ -120,7 +119,7 @@ public function loadFromDb(int $question_id): void
if ($data['thumb_size'] !== null && $data['thumb_size'] >= self::MINIMUM_THUMB_SIZE) {
$this->setThumbSize($data['thumb_size']);
}
$this->is_singleline = $data['allow_images'] === '0';
$this->is_singleline = $data['allow_images'] === null || $data['allow_images'] === '0';
$this->lastChange = $data['tstamp'];
$this->feedback_setting = $data['feedback_setting'] ?? self::FEEDBACK_MODE_SELECTED_ANSWERS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ protected function writePostData(bool $always = false): int
*/
protected function getEditAnswersSingleLine($checkonly = false): bool
{
if ($this->object->getSelfAssessmentEditingMode()) {
return $this->object->isSingleline();
}

if ($checkonly) {
return $this->request->int('types') === 0;
}
Expand Down

0 comments on commit 9147c5c

Please sign in to comment.