Skip to content

Commit d0c818c

Browse files
committed
Component/Test: contribute cron jobs
1 parent 14c5b0e commit d0c818c

4 files changed

Lines changed: 41 additions & 15 deletions

File tree

components/ILIAS/Test/Test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@ public function init(
4848
new Component\Resource\ComponentCSS($this, "test_print.css");
4949
$contribute[Component\Resource\PublicAsset::class] = fn() =>
5050
new Component\Resource\ComponentCSS($this, "test_print_hide_content.css");
51+
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
52+
new \ilCronFinishUnfinishedTestPasses(
53+
self::class,
54+
$use[\ILIAS\Language\Language::class],
55+
$use[\ILIAS\Logging\LoggerFactory::class]
56+
);
5157
}
5258
}

components/ILIAS/Test/classes/class.ilCronFinishUnfinishedTestPasses.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,26 @@
3030
*/
3131
class ilCronFinishUnfinishedTestPasses extends ilCronJob
3232
{
33-
protected readonly TestLogger $logger;
34-
35-
protected readonly ilLanguage $lng;
36-
protected readonly ilDBInterface $db;
37-
protected readonly ilObjUser $user;
38-
protected readonly ilObjectDataCache $obj_data_cache;
33+
protected TestLogger $logger;
34+
protected ilDBInterface $db;
35+
protected ilObjUser $user;
36+
protected ilObjectDataCache $obj_data_cache;
3937
protected int $now;
4038
protected array $unfinished_passes;
4139
protected array $test_ids;
4240
protected array $test_ending_times;
4341
protected ilTestProcessLockerFactory $processLockerFactory;
4442
protected TestResultRepository $test_pass_result_repository;
4543

46-
public function __construct()
44+
public function init(): void
4745
{
46+
$this->lng->loadLanguageModule('assessment');
47+
4848
/** @var ILIAS\DI\Container $DIC */
4949
global $DIC;
5050

5151
$this->logger = TestDIC::dic()['logging.logger'];
52-
$this->lng = $DIC['lng'];
5352
$this->user = $DIC['ilUser'];
54-
$this->lng->loadLanguageModule('assessment');
5553
$this->db = $DIC->database();
5654
$this->obj_data_cache = $DIC['ilObjDataCache'];
5755
$this->now = time();

components/ILIAS/Test/module.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
<parent id="wfld">wfld</parent>
3131
</object>
3232
</objects>
33-
<crons>
34-
<cron id="finish_unfinished_passes" class="ilCronFinishUnfinishedTestPasses" />
35-
</crons>
3633
<pluginslots>
3734
<pluginslot id="texp" name="Export" />
3835
</pluginslots>

components/ILIAS/Test/tests/ilCronFinishUnfinishedTestPassesTest.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
declare(strict_types=1);
2020

2121
use ILIAS\Cron\Schedule\CronJobScheduleType;
22+
use ILIAS\Logging\LoggerFactory;
2223

2324
/**
2425
* Class ilCronFinishUnfinishedTestPassesTest
@@ -40,7 +41,15 @@ protected function setUp(): void
4041
define("ILIAS_LOG_ENABLED", false);
4142
}
4243

43-
$this->test_obj = new ilCronFinishUnfinishedTestPasses();
44+
$logger_factory = $this->getMockBuilder(LoggerFactory::class)
45+
->disableOriginalConstructor()
46+
->getMock();
47+
48+
$this->test_obj = new ilCronFinishUnfinishedTestPasses(
49+
'components\ILIAS\Test',
50+
$GLOBALS['lng'],
51+
$logger_factory
52+
);
4453
}
4554

4655
public function test_instantiateObject_shouldReturnInstance(): void
@@ -63,8 +72,16 @@ public function testGetTitle(): void
6372
->willReturn('testString')
6473
;
6574

75+
$logger_factory = $this->getMockBuilder(LoggerFactory::class)
76+
->disableOriginalConstructor()
77+
->getMock();
78+
6679
$this->setGlobalVariable('lng', $lng_mock);
67-
$test_obj = new ilCronFinishUnfinishedTestPasses();
80+
$test_obj = new ilCronFinishUnfinishedTestPasses(
81+
'components\ILIAS\Test',
82+
$GLOBALS['lng'],
83+
$logger_factory
84+
);
6885

6986
$this->assertEquals('testString', $test_obj->getTitle());
7087
}
@@ -79,8 +96,16 @@ public function testGetDescription(): void
7996
->willReturn('testString')
8097
;
8198

99+
$logger_factory = $this->getMockBuilder(LoggerFactory::class)
100+
->disableOriginalConstructor()
101+
->getMock();
102+
82103
$this->setGlobalVariable('lng', $lng_mock);
83-
$test_obj = new ilCronFinishUnfinishedTestPasses();
104+
$test_obj = new ilCronFinishUnfinishedTestPasses(
105+
'components\ILIAS\Test',
106+
$GLOBALS['lng'],
107+
$logger_factory
108+
);
84109

85110
$this->assertEquals('testString', $test_obj->getDescription());
86111
}

0 commit comments

Comments
 (0)