ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilStudyProgrammeSettingsRepositoryTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21class ilStudyProgrammeSettingsRepositoryTest extends \PHPUnit\Framework\TestCase
22{
23 protected static $created;
24 protected ilDBInterface $db;
26
27 protected function setUp(): void
28 {
29 $this->db = $this->createMock(ilDBInterface::class);
30 $this->tps = $this->createMock(ilOrgUnitObjectTypePositionSetting::class);
31 $this->tps->method('getActivationDefault')
32 ->willReturn(1);
33 }
34
36 {
38 $this->db,
39 $this->tps
40 );
41 $this->assertInstanceOf(ilStudyProgrammeSettingsRepository::class, $repo);
42 return $repo;
43 }
44
45 #[\PHPUnit\Framework\Attributes\Depends('test_init')]
47 {
48 $this->markTestSkipped('Failed for some unknown reason.');
49
51 $this->db,
52 $this->tps
53 );
54 $set = $repo->createFor(-1);
55 $this->assertEquals($set->getTypeSettings()->getTypeId(), ilStudyProgrammeSettings::DEFAULT_SUBTYPE);
56 $this->assertEquals($set->getAssessmentSettings()->getStatus(), ilStudyProgrammeSettings::STATUS_DRAFT);
57 $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_UNDEFINED);
58 $this->assertEquals($set->getAssessmentSettings()->getPoints(), ilStudyProgrammeSettings::DEFAULT_POINTS);
59 $this->assertEquals($set->getDeadlineSettings()->getDeadlinePeriod(), 0);
60 $this->assertNull($set->getDeadlineSettings()->getDeadlineDate());
61 $this->assertEquals($set->getValidityOfQualificationSettings()->getQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
62 $this->assertNull($set->getValidityOfQualificationSettings()->getQualificationDate());
63 $this->assertEquals($set->getValidityOfQualificationSettings()->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
64
66 $this->db,
67 $this->tps
68 );
70 $set = $repo->get(-1);
71 $this->assertEquals($set->getSubtypeId(), ilStudyProgrammeSettings::DEFAULT_SUBTYPE);
72 $this->assertEquals($set->getAssessmentSettings()->getStatus(), ilStudyProgrammeSettings::STATUS_DRAFT);
73 $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_UNDEFINED);
74 $this->assertEquals($set->getPoints(), ilStudyProgrammeSettings::DEFAULT_POINTS);
75 $this->assertEquals($set->getDeadlinePeriod(), 0);
76 $this->assertNull($set->getDeadlineDate());
77 $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
78 $this->assertNull($set->getValidityOfQualificationDate());
79 $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
80
81 $set->setSubtypeId(123)
84 ->setPoints(10)
85 ->setDeadlinePeriod(10)
86 ->setValidityOfQualificationPeriod(20)
87 ->setRestartPeriod(30);
88 $repo->update($set);
90 $set = $repo->get(-1);
91 $this->assertEquals($set->getSubtypeId(), 123);
92 $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
93 $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
94 $this->assertEquals($set->getPoints(), 10);
95 $this->assertEquals($set->getDeadlinePeriod(), 10);
96 $this->assertNull($set->getDeadlineDate());
97 $this->assertEquals($set->getValidityOfQualificationPeriod(), 20);
98 $this->assertNull($set->getValidityOfQualificationDate());
99 $this->assertEquals($set->getRestartPeriod(), 30);
100
101 $set->setSubtypeId(123)
102 ->setDeadlineDate(new DateTime())
103 ->setValidityOfQualificationDate(DateTime::createFromFormat('Ymd', '20200101'))
104 ->setRestartPeriod(ilStudyProgrammeSettings::NO_RESTART);
105 $repo->update($set);
107 $set = $repo->get(-1);
108 $this->assertEquals($set->getDeadlinePeriod(), 0);
109 $this->assertEquals($set->getDeadlineDate()->format('Ymd'), (new DateTime())->format('Ymd'));
110 $this->assertEquals($set->getValidityOfQualificationDate()->format('Ymd'), '20200101');
111 $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
112 $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
113
115 $this->db,
116 $this->tps
117 );
119 $set = $repo->get(-1);
120 $this->assertEquals($set->getSubtypeId(), 123);
121 $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
122 $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
123 $this->assertEquals($set->getPoints(), 10);
124 }
125
126 #[\PHPUnit\Framework\Attributes\Depends('testPRGRepoEditAndUpdate')]
127 public function testPRGRepoDelete()
128 {
129 $this->expectException(\LogicException::class);
131 $this->db,
132 $this->tps
133 );
134 $set = $repo->get(-1);
135 $this->assertEquals($set->getSubtypeId(), 123);
136 $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
137 $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
138 $this->assertEquals($set->getPoints(), 10);
139 $repo->delete($set);
140 $repo->get(-1);
141 }
142}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
update(ilStudyProgrammeSettings $settings)
Update settings belonging to a SP-Object.Will throw if the record does not exist yet.
createFor(int $obj_id)
Create a record corresponding to a SP-Object and return representing settings.Will throw if a record ...
get(int $obj_id)
Load settings belonging to a SP-Object.Will throw if the record does not exist yet.
testPRGRepoEditAndUpdate(ilStudyProgrammeSettingsDBRepository $repo)
Interface ilDBInterface.