diff --git a/components/ILIAS/Test/classes/class.ilObjTest.php b/components/ILIAS/Test/classes/class.ilObjTest.php index e324175b584e..0c8330403f88 100755 --- a/components/ILIAS/Test/classes/class.ilObjTest.php +++ b/components/ILIAS/Test/classes/class.ilObjTest.php @@ -2761,7 +2761,7 @@ public function getAvailableQuestions($arr_filter, $completeonly = 0): array $query_result = $this->db->query(" SELECT qpl_questions.*, qpl_questions.tstamp, - qpl_qst_type.type_tag, qpl_qst_type.plugin, qpl_qst_type.plugin_name, + qpl_qst_type.type_tag AS question_type, qpl_qst_type.plugin, qpl_qst_type.plugin_name, object_data.title parent_title FROM qpl_questions, qpl_qst_type, object_data WHERE $original_clause $available @@ -2777,7 +2777,7 @@ public function getAvailableQuestions($arr_filter, $completeonly = 0): array $row = ilAssQuestionType::completeMissingPluginName($row); if (!$row['plugin']) { - $row[ 'ttype' ] = $this->lng->txt($row[ "type_tag" ]); + $row[ 'ttype' ] = $this->lng->txt($row[ "question_type" ]); $rows[] = $row; continue; diff --git a/components/ILIAS/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php b/components/ILIAS/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php index 121a6c61a7a4..5fdb0442143d 100755 --- a/components/ILIAS/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php +++ b/components/ILIAS/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php @@ -148,7 +148,7 @@ public function loadQuestions() { $query = " SELECT qpl_questions.question_id, - qpl_qst_type.type_tag, + qpl_qst_type.type_tag AS question_type, qpl_qst_type.plugin, qpl_qst_type.plugin_name diff --git a/components/ILIAS/TestQuestionPool/classes/questions/class.ilAssQuestionType.php b/components/ILIAS/TestQuestionPool/classes/questions/class.ilAssQuestionType.php index 652e930eafd5..480e7e980a02 100755 --- a/components/ILIAS/TestQuestionPool/classes/questions/class.ilAssQuestionType.php +++ b/components/ILIAS/TestQuestionPool/classes/questions/class.ilAssQuestionType.php @@ -104,9 +104,9 @@ public function isImportable(): bool public static function completeMissingPluginName(array $question_type_data): array { if ($question_type_data['plugin'] - && $question_type_data['plugin_name'] !== null - && $question_type_data['plugin_name'] !== '') { - $question_type_data['plugin_name'] = $question_type_data['type_tag']; + && ($question_type_data['plugin_name'] === null + || $question_type_data['plugin_name'] === '')) { + $question_type_data['plugin_name'] = $question_type_data['question_type']; } return $question_type_data; diff --git a/components/ILIAS/TestQuestionPool/classes/questions/class.ilAssQuestionTypeList.php b/components/ILIAS/TestQuestionPool/classes/questions/class.ilAssQuestionTypeList.php index ce69e3749565..c98c3cad7e35 100755 --- a/components/ILIAS/TestQuestionPool/classes/questions/class.ilAssQuestionTypeList.php +++ b/components/ILIAS/TestQuestionPool/classes/questions/class.ilAssQuestionTypeList.php @@ -50,14 +50,16 @@ public function __construct() public function load(): void { - $res = $this->db->query("SELECT * FROM qpl_qst_type"); + $res = $this->db->query( + 'SELECT question_type_id, type_tag AS question_type, plugin, plugin_name FROM qpl_qst_type' + ); while ($row = $this->db->fetchAssoc($res)) { $row = ilAssQuestionType::completeMissingPluginName($row); $qstType = new ilAssQuestionType(); $qstType->setId($row['question_type_id']); - $qstType->setTag($row['type_tag']); + $qstType->setTag($row['question_type']); $qstType->setPlugin($row['plugin']); $qstType->setPluginName($row['plugin_name']); $this->types[] = $qstType; diff --git a/components/ILIAS/TestQuestionPool/tests/ilAssQuestionListTest.php b/components/ILIAS/TestQuestionPool/tests/ilAssQuestionListTest.php index da6606fa12b6..ce6a1dd702c0 100644 --- a/components/ILIAS/TestQuestionPool/tests/ilAssQuestionListTest.php +++ b/components/ILIAS/TestQuestionPool/tests/ilAssQuestionListTest.php @@ -16,14 +16,16 @@ * *********************************************************************/ +use ILIAS\Refinery\Encode\Group as EncodeGroup; +use ILIAS\Refinery\Factory as Refinery; +use ILIAS\Refinery\Transformation; + /** * Unit tests * * @author Matheus Zych * * @ingroup components\ILIASTestQuestionPool -* -* This test was automatically generated. */ class ilAssQuestionListTest extends assBaseTestCase { @@ -38,10 +40,10 @@ protected function setUp(): void $this->object = new ilAssQuestionList( $this->createMock(ilDBInterface::class), $this->createMock(ilLanguage::class), - $this->createMock(ILIAS\Refinery\Factory::class), + $this->createMock(Refinery::class), $this->createMock(ilComponentRepository::class), $this->createMock(ilComponentFactory::class), - $this->createMock(ILIAS\Notes\Service::class) + null ); } @@ -49,4 +51,69 @@ public function testConstruct(): void { $this->assertInstanceOf(ilAssQuestionList::class, $this->object); } + + public function testLoadUsesQuestionTypeAliasAndWritesTranslatedLabel(): void + { + $db = $this->createMock(ilDBInterface::class); + $lng = $this->createMock(ilLanguage::class); + $refinery = $this->createMock(Refinery::class); + $component_repository = $this->createMock(ilComponentRepository::class); + $component_factory = $this->createMock(ilComponentFactory::class); + + $encode_group = $this->createMock(EncodeGroup::class); + $transformation = $this->createMock(Transformation::class); + $transformation->method('transform')->willReturnArgument(0); + $encode_group->method('htmlSpecialCharsAsEntities')->willReturn($transformation); + $refinery->method('encode')->willReturn($encode_group); + + $lng->method('txt')->with('assSingleChoice')->willReturn('Single Choice'); + + $statement = $this->createMock(ilDBStatement::class); + $captured_query = ''; + $db->expects($this->once()) + ->method('query') + ->willReturnCallback(static function (string $query) use (&$captured_query, $statement) { + $captured_query = $query; + return $statement; + }); + $db->expects($this->exactly(2)) + ->method('fetchAssoc') + ->with($statement) + ->willReturnOnConsecutiveCalls( + [ + 'question_id' => 42, + 'obj_fi' => 7, + 'title' => 'Question title', + 'description' => 'Question description', + 'author' => 'Author', + 'lifecycle' => 'draft', + 'points' => 1.0, + 'complete' => 1, + 'tstamp' => 1, + 'created' => 1, + 'question_type' => 'assSingleChoice', + 'plugin' => false, + 'plugin_name' => null, + 'feedback' => 0, + ], + null + ); + + $list = new ilAssQuestionList( + $db, + $lng, + $refinery, + $component_repository, + $component_factory, + null + ); + $list->setJoinObjectData(false); + $list->load(); + + $this->assertStringContainsString('qpl_qst_type.type_tag AS question_type', $captured_query); + + $row = $list->getDataArrayForQuestionId(42); + $this->assertSame('Single Choice', $row['question_type']); + $this->assertArrayNotHasKey('type_tag', $row); + } } diff --git a/components/ILIAS/TestQuestionPool/tests/ilAssQuestionTypeTest.php b/components/ILIAS/TestQuestionPool/tests/ilAssQuestionTypeTest.php index 90a71f8e83c7..6d2ea05c8b1f 100644 --- a/components/ILIAS/TestQuestionPool/tests/ilAssQuestionTypeTest.php +++ b/components/ILIAS/TestQuestionPool/tests/ilAssQuestionTypeTest.php @@ -22,8 +22,6 @@ * @author Matheus Zych * * @ingroup components\ILIASTestQuestionPool -* -* This test was automatically generated. */ class ilAssQuestionTypeTest extends assBaseTestCase { @@ -42,4 +40,49 @@ public function testConstruct(): void { $this->assertInstanceOf(ilAssQuestionType::class, $this->object); } + + public function testCompleteMissingPluginNameFillsEmptyPluginNameFromQuestionType(): void + { + $result = ilAssQuestionType::completeMissingPluginName([ + 'plugin' => true, + 'plugin_name' => '', + 'question_type' => 'assExamplePluginQuestion', + ]); + + $this->assertSame('assExamplePluginQuestion', $result['plugin_name']); + } + + public function testCompleteMissingPluginNameFillsNullPluginNameFromQuestionType(): void + { + $result = ilAssQuestionType::completeMissingPluginName([ + 'plugin' => true, + 'plugin_name' => null, + 'question_type' => 'assExamplePluginQuestion', + ]); + + $this->assertSame('assExamplePluginQuestion', $result['plugin_name']); + } + + public function testCompleteMissingPluginNameKeepsExistingPluginName(): void + { + $result = ilAssQuestionType::completeMissingPluginName([ + 'plugin' => true, + 'plugin_name' => 'ExampleQuestionPlugin', + 'question_type' => 'assExamplePluginQuestion', + ]); + + $this->assertSame('ExampleQuestionPlugin', $result['plugin_name']); + } + + public function testCompleteMissingPluginNameDoesNotTouchNonPluginData(): void + { + $result = ilAssQuestionType::completeMissingPluginName([ + 'plugin' => false, + 'plugin_name' => null, + 'question_type' => 'assSingleChoice', + ]); + + $this->assertNull($result['plugin_name']); + $this->assertSame('assSingleChoice', $result['question_type']); + } }