Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/ILIAS/Test/classes/class.ilObjTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
75 changes: 71 additions & 4 deletions components/ILIAS/TestQuestionPool/tests/ilAssQuestionListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mzych@databay.de>
*
* @ingroup components\ILIASTestQuestionPool
*
* This test was automatically generated.
*/
class ilAssQuestionListTest extends assBaseTestCase
{
Expand All @@ -38,15 +40,80 @@ 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
);
}

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);
}
}
47 changes: 45 additions & 2 deletions components/ILIAS/TestQuestionPool/tests/ilAssQuestionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* @author Matheus Zych <mzych@databay.de>
*
* @ingroup components\ILIASTestQuestionPool
*
* This test was automatically generated.
*/
class ilAssQuestionTypeTest extends assBaseTestCase
{
Expand All @@ -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']);
}
}
Loading