Skip to content

Commit

Permalink
TA: Ordering Table for Questionlist, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen authored and kergomard committed Jul 1, 2024
1 parent f511be1 commit 8817428
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 44 deletions.
32 changes: 18 additions & 14 deletions components/ILIAS/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ilObjTestGUI extends ilObjectGUI implements ilCtrlBaseClassInterface, ilDe
protected SkillService $skills_service;
private Archives $archives;
protected InternalRequestService $testrequest;
protected QuestionsTableQuery $table_query;
protected ?QuestionsTableQuery $table_query = null;

protected bool $create_question_mode;

Expand Down Expand Up @@ -195,8 +195,6 @@ public function __construct($refId = null)
$tabs_manager->setTestQuestionSetConfig($this->test_question_set_config_factory->getQuestionSetConfig());
$this->setTabsManager($tabs_manager);
}

$this->table_query = $this->getQuestionsTableQuery();
}

/**
Expand All @@ -206,8 +204,9 @@ public function executeCommand(): void
{
$cmd = $this->ctrl->getCmd('testScreen');

if ($table_cmd = $this->table_query->getQueryCommand()) {
$row_ids = $this->table_query->getRowIds($this->object);
$table_query = $this->getQuestionsTableQuery();
if ($table_cmd = $table_query->getQueryCommand()) {
$row_ids = $table_query->getRowIds($this->object);
$this->getTable()->handleCommand(
$table_cmd,
$row_ids,
Expand Down Expand Up @@ -3123,8 +3122,9 @@ protected function getTargetQuestionpoolForm($questionpools, string $cmd): ilPro
$form->addItem($select);
}

if ($this->table_query->getQueryCommand()) {
$question_ids = $this->table_query->getRowIds($this->object);
$table_query = $this->getQuestionsTableQuery();
if ($table_query->getQueryCommand()) {
$question_ids = $table_query->getRowIds($this->object);
} elseif ($this->testrequest->isset('q_id') && is_array($this->testrequest->raw('q_id'))) {
$question_ids = $this->testrequest->raw('q_id');
}
Expand Down Expand Up @@ -3353,12 +3353,16 @@ private function getTestScreenGUIInstance(): ilTestScreenGUI

protected function getQuestionsTableQuery(): QuestionsTableQuery
{
return new QuestionsTableQuery(
$this->http,
$this->refinery,
new \ILIAS\Data\Factory(),
['qlist', $this->object->getId()]
);
if ($this->table_query === null) {
$id = $this->object ? $this->object->getId() : '';
$this->table_query = new QuestionsTableQuery(
$this->http,
$this->refinery,
new \ILIAS\Data\Factory(),
['qlist', $id]
);
}
return $this->table_query;
}

protected function getTable(): QuestionsTable
Expand All @@ -3367,7 +3371,7 @@ protected function getTable(): QuestionsTable
$this->ui_factory,
$this->ui_renderer,
$this->http->request(),
$this->table_query,
$this->getQuestionsTableQuery(),
$this->lng,
$this->ctrl,
$this->object,
Expand Down
44 changes: 27 additions & 17 deletions components/ILIAS/Test/tests/ilObjTestGUITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@

use ILIAS\DI\Container;

class QuestionsTableQueryMock extends QuestionsTableQuery
{
public function __construct()
{
}
private function getHereURL(): string
{
return 'http://www.ilias.de';
}
}

/**
* Class ilObjTestGUITest
* @author Marvin Beym <[email protected]>
Expand All @@ -33,6 +44,9 @@ protected function setUp(): void
if (!defined('ANONYMOUS_USER_ID')) {
define('ANONYMOUS_USER_ID', 13);
}
if (!defined('CLIENT_DATA_DIR')) {
define('CLIENT_DATA_DIR', 'data/');
}

global $DIC;

Expand Down Expand Up @@ -74,18 +88,13 @@ protected function setUp(): void
$this->addGlobal_objectService();
$this->addGlobal_GlobalScreenService();

$table_query_mock = new class () extends QuestionsTableQuery {
private function getHereURL(): string
{
return 'http://www.ilias.de';
}
};

$table_query = $this->getMockBuilder($table_query_mock)
->disableOriginalConstructor()
->getMock();
$this->testObj = $this->getNewTestGUI();
}

$this->testObj = new class ($table_query) extends ilObjTestGUI {
protected function getNewTestGUI(): ilObjTestGUI
{
$table_query = $this->getMockBuilder(QuestionsTableQueryMock::class)->getMock();
return new class ($table_query) extends ilObjTestGUI {
public function __construct(
protected QuestionsTableQuery $mock_table_query
) {
Expand All @@ -98,6 +107,7 @@ protected function getQuestionsTableQuery(): QuestionsTableQuery
};
}


protected function tearDown(): void
{
global $DIC;
Expand Down Expand Up @@ -132,7 +142,7 @@ public function testRunObject(): void
{
$ctrl_mock = $this->createMock(ilCtrl::class);
$this->setGlobalVariable('ilCtrl', $ctrl_mock);
$testObj = new ilObjTestGUI();
$testObj = $this->getNewTestGUI();
$ctrl_mock
->expects($this->once())
->method('redirect')
Expand All @@ -151,7 +161,7 @@ public function testOutEvaluationObject(): void
;
$this->setGlobalVariable('ilCtrl', $ctrl_mock);

$testObj = new ilObjTestGUI();
$testObj = $this->getNewTestGUI();

$testObj->outEvaluationObject();
}
Expand All @@ -160,7 +170,7 @@ public function testBackObject(): void
{
$ctrl_mock = $this->createMock(ilCtrl::class);
$this->setGlobalVariable('ilCtrl', $ctrl_mock);
$testObj = new ilObjTestGUI();
$testObj = $this->getNewTestGUI();
$ctrl_mock
->expects($this->once())
->method('redirect')
Expand All @@ -173,7 +183,7 @@ public function testCancelCreateQuestionObject(): void
{
$ctrl_mock = $this->createMock(ilCtrl::class);
$this->setGlobalVariable('ilCtrl', $ctrl_mock);
$testObj = new ilObjTestGUI();
$testObj = $this->getNewTestGUI();
$ctrl_mock
->expects($this->once())
->method('redirect')
Expand All @@ -186,7 +196,7 @@ public function testCancelRemoveQuestionsObject(): void
{
$ctrl_mock = $this->createMock(ilCtrl::class);
$this->setGlobalVariable('ilCtrl', $ctrl_mock);
$testObj = new ilObjTestGUI();
$testObj = $this->getNewTestGUI();
$ctrl_mock
->expects($this->once())
->method('redirect')
Expand All @@ -199,7 +209,7 @@ public function testMoveQuestionsObject(): void
{
$ctrl_mock = $this->createMock(ilCtrl::class);
$this->setGlobalVariable('ilCtrl', $ctrl_mock);
$testObj = new ilObjTestGUI();
$testObj = $this->getNewTestGUI();
$ctrl_mock
->expects($this->once())
->method('redirect')
Expand Down
3 changes: 2 additions & 1 deletion components/ILIAS/Test/tests/ilTestBaseTestCaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use ILIAS\UI\Implementation\Factory;
use ILIAS\Refinery\Factory as RefineryFactory;
use ILIAS\Refinery\Random\Group as RandomGroup;
use GuzzleHttp\Psr7\Uri as GuzzleURI;

trait ilTestBaseTestCaseTrait
{
Expand Down Expand Up @@ -218,7 +219,7 @@ protected function addGlobal_http(): void
->disableOriginalConstructor()
->getMock();
$request_mock->method('getUri')
->willReturn(new ILIAS\Data\URI('http://wwww.ilias.de'));
->willReturn(new GuzzleURI('http://wwww.ilias.de'));
$http_mock = $this->getMockBuilder(Services::class)->disableOriginalConstructor()
->getMock();
$http_mock->method('request')
Expand Down
56 changes: 48 additions & 8 deletions ...ts/tables/ilTestQuestionsTableGUITest.php → .../Test/tests/tables/QuestionsTableTest.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use ILIAS\UI\Component\Table;
use ILIAS\UI\Component\Modal;
use ILIAS\UI\Implementation\Component as C;
use ILIAS\TestQuestionPool\QuestionInfoService;

/**
* Class QuestionsTableTest
Expand All @@ -37,21 +38,61 @@ protected function setUp(): void
$this->addGlobal_refinery();
$this->addGlobal_http();
$this->addGlobal_lng();
$this->addGlobal_ilCtrl();


$records = $this->getSomeRecords();
$this->table_gui = new class ($records, $DIC) extends QuestionsTable {
$obj_test = $this->getMockBuilder(ilObjTest::class)
->disableOriginalConstructor()
->getMock();
$obj_test->method('getId')->willReturn(666);


$commands = $this->getMockBuilder(QuestionsTableQuery::class)
->disableOriginalConstructor()
->getMock();
$commands->method('getRowBoundURLBuilder')
->willReturn(
[
$this->getMockBuilder(ILIAS\UI\URLBuilder::class)
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder(ILIAS\UI\URLBuilderToken::class)
->disableOriginalConstructor()
->getMock(),

]
);

$questioninfo = new class () extends QuestionInfoService {
public function __construct()
{
}
};

$this->table_gui = new class (
$records,
$DIC,
$obj_test,
$commands,
$questioninfo
) extends QuestionsTable {
public function __construct(
protected $data,
$DIC
$DIC,
$obj_test,
$commands,
$questioninfo
) {
parent::__construct(
$DIC['ui.factory'],
new ILIAS\Data\Factory(),
$DIC['refinery'],
$DIC['http'],
$DIC['ui.renderer'],
$DIC['http']->request(),
$commands,
$DIC['lng'],
'some_table_id',
$DIC['ilCtrl'],
$obj_test,
$questioninfo,
fn() => ''
);
}
Expand Down Expand Up @@ -86,9 +127,8 @@ public function test_instantiateObject_shouldReturnInstance(): void

public function testQuestionsTableGUIwillReturnProperTypes(): void
{
$this->assertInstanceOf(Table\Ordering::class, $this->table_gui->getTable([]));
$this->assertInstanceOf(Table\Ordering::class, $this->table_gui->getTableComponent([]));
$this->assertInstanceOf(Modal\Interruptive::class, $this->table_gui->getDeleteConfirmation([]));
$this->assertIsArray($this->table_gui->getOrderData());
}

public function testQuestionsTableDefinesActions(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ public function calculateReachedPoints($active_id, $pass = null, $authorizedSolu
$solutionValuePairs = $this->getSolutionValues($active_id, $pass, $authorizedSolution);

if (!count($solutionValuePairs)) {
return (float)0;
return (float) 0;
}

$indexedSolutionValues = $this->fetchIndexedValuesFromValuePairs($solutionValuePairs);
Expand Down Expand Up @@ -845,7 +845,7 @@ public function storeImageFile(string $upload_file, string $upload_name): ?strin
$target_filepath = $this->getImagePath() . $target_filename;
if (ilFileUtils::moveUploadedFile($upload_file, $target_filename, $target_filepath)) {
$thumb_path = $this->getImagePath() . $this->getThumbPrefix() . $target_filename;
ilShellUtil::convertImage($target_filepath, $thumb_path, "JPEG", (string)$this->getThumbSize());
ilShellUtil::convertImage($target_filepath, $thumb_path, "JPEG", (string) $this->getThumbSize());

return $target_filename;
}
Expand All @@ -861,7 +861,7 @@ public function updateImageFile(string $existing_image_name): ?string
if (ilFileUtils::rename($existing_image_path, $target_filepath)) {
unlink($this->getImagePath() . $this->getThumbPrefix() . $existing_image_name);
$thumb_path = $this->getImagePath() . $this->getThumbPrefix() . $target_filename;
ilShellUtil::convertImage($target_filepath, $thumb_path, "JPEG", (string)$this->getThumbSize());
ilShellUtil::convertImage($target_filepath, $thumb_path, "JPEG", (string) $this->getThumbSize());

return $target_filename;
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ protected function generateThumbForFile($path, $file): void
$ext = 'JPEG';
break;
}
ilShellUtil::convertImage($filename, $thumbpath, $ext, (string)$this->getThumbSize());
ilShellUtil::convertImage($filename, $thumbpath, $ext, (string) $this->getThumbSize());
}
}

Expand Down

0 comments on commit 8817428

Please sign in to comment.