19 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
21 ilUnitUtil::performInitialisation();
30 self::$usr_1->create();
32 self::$usr_2->create();
36 protected function setUp() : void
38 PHPUnit_Framework_Error_Deprecated::$enabled =
false;
42 $this->db = $DIC[
'ilDB'];
48 $this->assertInstanceOf(ilStudyProgrammeAssignmentRepository::class, $repo);
57 $ass_1 = $repo->createFor(self::$prg_2->getId(), self::$usr_1->getId(), 6);
58 self::$created[$ass_1->getID()] = $ass_1;
59 $ass_2 = $repo->createFor(self::$prg_2->getId(), self::$usr_1->getId(), 6);
60 self::$created[$ass_2->getID()] = $ass_2;
61 $ass_3 = $repo->createFor(self::$prg_2->getId(), self::$usr_2->getId(), 6);
62 self::$created[$ass_3->getID()] = $ass_3;
63 $ass_4 = $repo->createFor(self::$prg_2->getId(), self::$usr_2->getId(), 6);
64 self::$created[$ass_4->getId()] = $ass_4;
65 $this->assertEquals($ass_1->getRootId(), self::$prg_2->getId());
66 $this->assertEquals($ass_1->getUserId(), self::$usr_1->getId());
67 $this->assertEquals($ass_1->getLastChangeBy(), 6);
68 $this->assertNull($ass_1->getRestartDate());
70 $ass_1->getRestartedAssignmentId(),
81 $ass = $repo->get(current(self::$created)->getId());
82 $this->assertEquals($ass->getId(), current(self::$created)->getId());
83 $this->assertEquals($ass->getRootId(), self::$prg_2->getId());
84 $this->assertEquals($ass->getUserId(), self::$usr_1->getId());
85 $this->assertEquals($ass->getLastChangeBy(), 6);
86 $ass->setRootId(self::$prg_1->getId());
87 $ass->setLastChangeBy(self::$usr_2->getId());
88 $ass->setRestartDate(DateTime::createFromFormat(
'Ymd',
'20210102'));
89 $ass->setRestartedAssignmentId(123);
93 $ass = $repo->get(current(self::$created)->getId());
94 $this->assertEquals($ass->getId(), current(self::$created)->getId());
95 $this->assertEquals($ass->getRootId(), self::$prg_1->getId());
96 $this->assertEquals($ass->getUserId(), self::$usr_1->getId());
97 $this->assertEquals($ass->getLastChangeBy(), self::$usr_2->getId());
98 $this->assertEquals($ass->getRestartDate()->format(
'Ymd'),
'20210102');
99 $this->assertEquals($ass->getRestartedAssignmentId(), 123);
108 $this->assertCount(0, $repo->getByPrgId(-1));
110 $asss = $repo->getByPrgId(self::$prg_1->getId());
111 $this->assertCount(1, $asss);
112 $ass = array_shift($asss);
113 $this->assertEquals($ass->getRootId(), self::$prg_1->getId());
114 $this->assertEquals($ass->getUserId(), self::$usr_1->getId());
116 $asss = $repo->getByPrgId(self::$prg_2->getId());
117 $this->assertCount(3, $asss);
119 array_map(
function ($ass) {
120 return $ass->getUserId();
122 [self::$usr_1->getId(),self::$usr_2->getId(),self::$usr_2->getId()]
124 foreach ($asss as $ass) {
125 $this->assertEquals($ass->getRootId(), self::$prg_2->getId());
136 $this->assertCount(0, $repo->getByUsrId(-1));
138 $asss = $repo->getByUsrId(self::$usr_1->getId());
139 $this->assertCount(2, $asss);
141 array_map(
function ($ass) {
142 return $ass->getRootId();
144 [self::$prg_1->getId(),self::$prg_2->getId()]
147 $asss = $repo->getByUsrId(self::$usr_2->getId());
148 $this->assertCount(2, $asss);
149 foreach ($asss as $ass) {
150 $this->assertEquals($ass->getRootId(), self::$prg_2->getId());
160 $this->assertCount(0, $repo->getByUsrIdAndPrgId(-1, -2));
162 $asss = $repo->getByUsrIdAndPrgId(self::$usr_2->getId(), self::$prg_2->getId());
163 $this->assertCount(2, $asss);
164 foreach ($asss as $ass) {
165 $this->assertEquals($ass->getRootId(), self::$prg_2->getId());
166 $this->assertEquals($ass->getUserId(), self::$usr_2->getId());
176 $repo->createFor(self::$prg_1->getId(), -1, 6);
186 $repo->createFor(-1, 6, 6);
195 $one_day =
new DateInterval(
'P1D');
196 $yesterday =
new DateTime();
197 $yesterday->sub($one_day);
198 $today =
new DateTime();
199 $tomorrow =
new DateTime();
200 $tomorrow->add($one_day);
204 $repo->update(array_shift(
$created)->setRestartDate($yesterday));
205 $repo->update(array_shift(
$created)->setRestartDate($today));
206 $repo->update(array_shift(
$created)->setRestartDate($tomorrow));
207 $repo->update(array_shift(
$created)->setRestartDate(null));
211 array_map(
function ($ass) {
212 return $ass->getId();
213 }, $repo->getDueToRestart()),
217 array_map(
function ($ass) {
218 return $ass->getId();
219 }, $u_a_repo->getDueToRestart()),
225 $repo->update(array_shift(
$created)->setRestartDate($yesterday));
226 $repo->update(array_shift(
$created)->setRestartDate($today)->setRestartedAssignmentId(123));
227 $repo->update(array_shift(
$created)->setRestartDate($tomorrow)->setRestartedAssignmentId(223));
228 $repo->update(array_shift(
$created)->setRestartDate(null)->setRestartedAssignmentId(323));
230 $ref = [array_shift(
$created)->getId()];
232 array_map(
function ($ass) {
233 return $ass->getId();
234 }, $repo->getDueToRestart()),
238 array_map(
function ($ass) {
239 return $ass->getId();
240 }, $u_a_repo->getDueToRestart()),
245 $repo->update(array_shift(
$created)->setRestartDate($yesterday)->setRestartedAssignmentId(23));
246 $repo->update(array_shift(
$created)->setRestartDate($today)->setRestartedAssignmentId(123));
247 $repo->update(array_shift(
$created)->setRestartDate($tomorrow)->setRestartedAssignmentId(223));
248 $repo->update(array_shift(
$created)->setRestartDate(null)->setRestartedAssignmentId(323));
250 array_map(
function ($ass) {
251 return $ass->getId();
252 }, $repo->getDueToRestart()),
256 array_map(
function ($ass) {
257 return $ass->getId();
258 }, $u_a_repo->getDueToRestart()),
267 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
268 ilUnitUtil::performInitialisation();
273 self::$prg_1->delete();
278 self::$prg_2->delete();
281 self::$usr_1->delete();
282 self::$usr_2->delete();
283 if (count(self::$created) > 0) {
289 array_keys(self::$created),
test_save_and_load()
test_create
test_read_by_usr_id()
test_save_and_load
test_read_due_to_restart()
test_save_and_load
const NO_RESTARTED_ASSIGNMENT
test_read_by_usr_and_prg_ids()
test_save_and_load
static setUpBeforeClass()
test_create_error_prg($repo)
test_init ilException
test_read_by_prg_id()
test_save_and_load
test_create_error_user($repo)
test_init ilException
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
static tearDownAfterClass()
test_create($repo)
test_init