24use PHPUnit\Framework\TestCase;
26require_once(__DIR__ .
"/mocks.php");
41 protected function setUp() : void
43 require_once(
"./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
44 PHPUnit\Framework\Error\Deprecated::$enabled =
false;
49 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
50 ilUnitUtil::performInitialisation();
51 }
catch (Exception
$e) {
56 $this->root_object_obj_id = $this->root_object->getId();
57 $this->root_object_ref_id = $this->root_object->getRefId();
64 $objDefinition =
$DIC[
'objDefinition'];
65 $this->obj_definition = $objDefinition;
70 if ($this->root_object) {
71 $this->root_object->delete();
80 $this->assertNotEmpty($this->root_object_obj_id);
81 $this->assertGreaterThan(0, $this->root_object_obj_id);
83 $this->assertNotEmpty($this->root_object_ref_id);
84 $this->assertGreaterThan(0, $this->root_object_ref_id);
86 $this->assertTrue($this->tree->isInTree($this->root_object_ref_id));
102 $orig = $this->root_object;
105 $this->assertNotNull($loaded);
106 $this->assertGreaterThan(0, $loaded->getId());
107 $this->assertEquals($orig->getId(), $loaded->getId());
109 $orig->getLastChange()->format(
'YmdHis'),
110 $loaded->getLastChange()->format(
'YmdHis')
112 $this->assertEquals($orig->getPoints(), $loaded->getPoints());
113 $this->assertEquals($orig->getLPMode(), $loaded->getLPMode());
114 $this->assertEquals($orig->getStatus(), $loaded->getStatus());
125 $orig = $this->root_object;
127 $this->assertNotNull($loaded);
128 $this->assertGreaterThan(0, $loaded->getId());
129 $this->assertEquals($orig->getId(), $loaded->getId());
131 $orig->getLastChange()->format(
'YmdHis'),
132 $loaded->getLastChange()->format(
'YmdHis')
134 $this->assertEquals($orig->getPoints(), $loaded->getPoints());
135 $this->assertEquals($orig->getLPMode(), $loaded->getLPMode());
136 $this->assertEquals($orig->getStatus(), $loaded->getStatus());
146 require_once(
"Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
152 $orig = $this->root_object;
154 $this->assertNotNull($loaded);
155 $this->assertGreaterThan(0, $loaded->getId());
156 $this->assertEquals($orig->getId(), $loaded->getId());
158 $orig->getLastChange()->format(
'YmdHis'),
159 $loaded->getLastChange()->format(
'YmdHis')
161 $this->assertEquals($orig->getPoints(), $loaded->getPoints());
162 $this->assertEquals($orig->getLPMode(), $loaded->getLPMode());
163 $this->assertEquals($orig->getStatus(), $loaded->getStatus());
173 $date =
new DateTime();
176 $assessment_settings = $obj->getAssessmentSettings();
177 $auto_mail_settings = $obj->getAutoMailSettings();
178 $validity_of_qualification_settings = $obj->getValidityOfQualificationSettings();
179 $deadline_settings = $obj->getDeadlineSettings();
180 $type_settings = $obj->getTypeSettings();
182 $this->assertInstanceOf(ilStudyProgrammeAssessmentSettings::class, $assessment_settings);
183 $this->assertInstanceOf(ilStudyProgrammeAutoMailSettings::class, $auto_mail_settings);
184 $this->assertInstanceOf(
185 ilStudyProgrammeValidityOfAchievedQualificationSettings::class,
186 $validity_of_qualification_settings
188 $this->assertInstanceOf(ilStudyProgrammeDeadlineSettings::class, $deadline_settings);
189 $this->assertInstanceOf(ilStudyProgrammeTypeSettings::class, $type_settings);
191 $assessment_settings = $assessment_settings
196 $auto_mail_settings = $auto_mail_settings
197 ->withProcessingEndsNotSuccessfulDays(10)
198 ->withReminderNotRestartedByUserDays(10)
199 ->withSendReAssignedMail(
true)
202 $validity_of_qualification_settings = $validity_of_qualification_settings
203 ->withRestartPeriod(10)
204 ->withQualificationPeriod(10)
205 ->withQualificationDate($date)
208 $deadline_settings = $deadline_settings
209 ->withDeadlinePeriod(10)
210 ->withDeadlineDate($date)
213 $type_settings = $type_settings->withTypeId(10);
215 $obj->setAssessmentSettings($assessment_settings);
216 $obj->setAutoMailSettings($auto_mail_settings);
217 $obj->setValidityOfQualificationSettings($validity_of_qualification_settings);
218 $obj->setDeadlineSettings($deadline_settings);
219 $obj->setTypeSettings($type_settings);
224 $assessment_settings = $obj->getAssessmentSettings();
225 $auto_mail_settings = $obj->getAutoMailSettings();
226 $validity_of_qualification_settings = $obj->getValidityOfQualificationSettings();
227 $deadline_settings = $obj->getDeadlineSettings();
228 $type_settings = $obj->getTypeSettings();
232 $assessment_settings->getStatus()
234 $this->assertEquals(10, $assessment_settings->getPoints());
235 $this->assertEquals(10, $auto_mail_settings->getProcessingEndsNotSuccessfulDays());
236 $this->assertEquals(10, $auto_mail_settings->getReminderNotRestartedByUserDays());
237 $this->assertTrue($auto_mail_settings->getSendReAssignedMail());
238 $this->assertEquals(10, $validity_of_qualification_settings->getRestartPeriod());
239 $this->assertEquals(10, $validity_of_qualification_settings->getQualificationPeriod());
240 $this->assertSame($date, $validity_of_qualification_settings->getQualificationDate());
241 $this->assertEquals(10, $deadline_settings->getDeadlinePeriod());
242 $this->assertSame($date, $deadline_settings->getDeadlineDate());
243 $this->assertEquals(10, $type_settings->getTypeId());
255 $this->assertTrue($deleted_object->delete());
267 $this->root_object->addNode($first_node);
268 $this->root_object->addNode($second_node);
269 $this->root_object->addNode($third_node);
272 $third_node->addNode($third_first_node);
283 $this->assertEquals(3, $this->root_object->getAmountOfChildren());
296 $children = $this->root_object->getChildren();
297 $this->assertEquals(3, count($children),
"getChildren()");
300 $this->assertEquals(4, count($children),
"ilObjStudyProgramme::getAllChildren(" . $this->root_object_ref_id .
")");
302 $this->assertTrue($this->root_object->hasChildren(),
"hasChildren()");
303 $this->assertEquals(3, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
305 $this->assertFalse($children[0]->hasChildren(),
"hasChildren()");
306 $this->assertEquals(0, $children[0]->getAmountOfChildren(),
"getAmountOfChildren()");
307 $this->assertEquals(0, count($children[0]->getChildren()));
315 $this->root_object->getAllPrgChildren()
327 $children = $this->root_object->getChildren();
329 $child = $children[0];
330 $this->assertNotNull($child->getParent());
331 $this->assertNull($this->root_object->getParent());
341 $children = $this->root_object->getChildren();
342 $children[0]->addNode($node3);
344 $parents = $node3->getParents();
345 $parent_ids = array_map(
function ($node) {
346 return $node->getId();
348 $parent_ids_expected = array( $this->root_object->getId()
349 , $children[0]->getId()
352 $this->assertEquals($parent_ids_expected, $parent_ids);
363 $children = $this->root_object->getChildren();
365 $child = $children[0];
367 $this->assertEquals(1, $child->getDepth());
378 $children = $this->root_object->getChildren();
379 $child = $children[0];
381 $this->assertEquals($this->root_object->getId(), $child->getRoot()->getId());
392 $children = $this->root_object->getChildren();
395 $this->root_object->applyToSubTreeNodes(
function ($node) use (&$val) {
396 $val += $node->getPoints();
403 $this->root_object->setPoints(1);
404 $children[0]->setPoints(2);
405 $children[1]->setPoints(4);
406 $children[2]->setPoints(1);
408 $third_level = $children[2]->getChildren();
409 $third_level[0]->setPoints(2);
412 $this->root_object->applyToSubTreeNodes(
function ($node) use (&$val) {
413 $val += $node->getPoints();
416 $this->assertEquals($val, 10);
428 $children = $this->root_object->getChildren();
429 $child = $children[0];
431 $grandchild->create();
432 $child->addNode($grandchild);
434 $this->assertEquals($child->getId(), $grandchild->getParent()->getId());
436 $this->root_object->getId(),
437 $grandchild->getRoot()->getId(),
438 "Root of grandchild is root of tree."
440 $this->assertEquals(1, $child->getAmountOfChildren());
441 $this->assertEquals(2, $grandchild->getDepth());
454 $children = $this->root_object->getChildren();
455 $child = $children[0];
456 $this->root_object->removeNode($child);
465 $this->assertTrue($raised,
"Child does not raise on getParent after it is removed.");
467 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
472 $this->root_object->removeNode($child);
476 $this->assertTrue($raised,
"Child can be removed two times.");
489 $children = $this->root_object->getChildren();
490 $first_child = $children[0];
492 $first_child->addLeaf($mock_leaf);
498 $this->assertEquals(3, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
500 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(),
"getAmountOfLPChildren() on root");
501 $this->assertEquals(
false, $this->root_object->hasLPChildren(),
"hasLPChildren() on root");
503 $this->assertEquals(1, $first_child->getAmountOfLPChildren(),
"getAmountOfLPChildren() on first child");
504 $this->assertEquals(
true, $first_child->hasLPChildren(),
"hasLPChildren() on first child");
507 $lp_children = $first_child->getLPChildren();
508 $this->assertEquals(1, count($lp_children));
509 $this->assertEquals($mock_leaf->getId(), $lp_children[0]->getId());
520 $this->root_object->addLeaf($mock_leaf);
522 $this->root_object->removeLeaf($mock_leaf);
523 $this->assertEquals(0, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
524 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(),
"getAmountOfLPChildren()");
526 $lp_children = $this->root_object->getLPChildren();
527 $this->assertEquals(0, count($lp_children));
537 $children = $this->root_object->getChildren();
538 $child_n = $children[0];
539 $child_l = $children[1];
548 $child_n->addNode($node1);
549 $child_l->addLeaf($mock_leaf1);
553 $child_n->addLeaf($mock_leaf2);
557 $this->assertTrue($raised,
"Could add leaf to program containing node.");
561 $child_n->addLeaf($mock_leaf2);
565 $this->assertTrue($raised,
"Could add node to program containing leaf.");
574 $children = $this->root_object->getChildren();
575 $child_l = $children[0];
576 $child_r = $children[1];
577 $child_m = $children[2];
579 $child_r->moveTo($child_l);
581 $this->assertEquals(2, $child_r->getDepth());
582 $this->assertEquals($child_l->getId(), $child_r->getParent()->getId());
583 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
584 $this->assertEquals(1, $child_l->getAmountOfChildren());
587 $this->assertEquals(1, $child_m->getAmountOfChildren());
589 $child_m->moveTo($child_r);
591 $m_children = $child_m->getChildren();
592 $first_third_node = $m_children[0];
594 $this->assertEquals(3, $child_m->getDepth());
595 $this->assertEquals(1, $child_m->getAmountOfChildren());
596 $this->assertNotNull($first_third_node);
597 $this->assertEquals(4, $first_third_node->getDepth());
598 $this->assertEquals($child_m->getId(), $first_third_node->getParent()->getId());
600 $this->assertEquals(1, $this->root_object->getAmountOfChildren());
610 $children = $this->root_object->getChildren();
611 $child_l = $children[0];
612 $child_r = $children[1];
620 $child_l->assignUser($user->getId(), 6);
621 $this->root_object->removeNode($child_l);
627 $children = $this->root_object->getChildren();
628 $child_l = $children[0];
629 $child_r = $children[1];
637 $this->root_object->assignUser($user->getId(), 6);
638 $this->root_object->removeNode($child_r);
644 $children = $this->root_object->getChildren();
645 $child_l = $children[0];
647 $all_possible_subobjects = $this->root_object->getPossibleSubObjects();
649 unset($all_possible_subobjects[
"rolf"]);
652 $this->assertCount(3, $all_possible_subobjects);
653 $this->assertArrayHasKey(
"prg", $all_possible_subobjects);
654 $this->assertArrayHasKey(
"crsr", $all_possible_subobjects);
655 $this->assertArrayHasKey(
"prgr", $all_possible_subobjects);
658 $this->assertCount(2, $subobjs);
659 $this->assertArrayHasKey(
"prg", $subobjs);
660 $this->assertArrayHasKey(
"prgr", $all_possible_subobjects);
663 $this->assertCount(3, $subobjs);
664 $this->assertArrayHasKey(
"prg", $subobjs);
665 $this->assertArrayHasKey(
"crsr", $subobjs);
666 $this->assertArrayHasKey(
"prgr", $all_possible_subobjects);
668 $children = $this->root_object->getChildren();
670 $child_l->addLeaf($mock_leaf);
674 $this->assertCount(1, $subobjs);
675 $this->assertArrayHasKey(
"crsr", $subobjs);
680 $all_possible_subobjects = $this->obj_definition->getSubObjects(
"prg");
682 unset($all_possible_subobjects[
"rolf"]);
684 $all_possible_subobjects,
699 $this->root_object->delete();
700 $this->root_object =
null;
705 "SELECT COUNT(*) cnt "
707 .
" WHERE obj_id = " . $this->root_object_obj_id
710 $this->assertEquals(0, $rec[
"cnt"]);
718 $this->assertCount(1, $op_ids);
An exception for terminatinating execution or to throw for unit testing.
TestCase for the ilObjStudyProgramme @group needsInstalledILIAS.
testCreateableSubObjects()
testTreeDepth()
Test getDepth on ilObjStudyProgramme.
testApplyToSubTreeNodes()
Test applyToSubTreeNodes on ilObjStudyProgramme.
testLoadByObjId()
Test loading of ilObjStudyProgramme with obj_id.
testAddNode()
Test on addNode.
testRemoveLeaf()
Test on removeLead.
testDelete()
Test deletion of a ilObjStudyProgramme.
testCanRemoveNodeWithNotRelevantProgress()
testTreeGetChildren()
Test function to get children or information about them.
testCreation()
Test creation of ilObjStudyProgramme.
testCreatableSubObjectsWithoutRef()
testMoveTo()
Test on moveTo.
testTreeCreation()
Test creating a small tree.
testCantRemoveNodeWithRelevantProgress()
@expectedException ilStudyProgrammeTreeException
testTreeGetParents()
@depends testTreeCreation
testAddWrongChildType()
Test whether nodes can only be added when there is no leaf in the parent and vice versa.
testCreatePermissionExists()
testRemoveNode()
Test on removeNode.
testCreatableSubObjectsRaisesOnNonProgramRef()
@expectedException ilException
createSmallTree()
Creates a small tree, used by various tests.
testSettings()
Test settings on ilObjStudyProgramme.
testLoadByRefId()
Test loading of ilObjStudyProgramme with ref_id.
testGetInstanceByRefId()
Test loading over getInstance.
testTreeGetRoot()
Test getRoot on ilObjStudyProgramme.
testTreeGetParent()
Test getParent on ilObjStudyProgramme.
testDeleteRemovesEntriesInPrgSettings()
testAddLeaf()
Test on addLeaf.
testTreeGetAllPrgChildren()
static getInstanceByRefId($a_ref_id)
static getCreatableSubObjects(array $a_subobjects, $a_ref_id)
Filter the list of possible subobjects for the objects that actually could be created on a concrete n...
static getAllChildren(int $a_ref_id, bool $include_references=false)
Get a list of all ilObjStudyProgrammes in the subtree starting at $a_ref_id.
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
static lookupCreateOperationIds($a_type_arr)
Lookup operation ids.
Exception is thrown when invariants on the program tree would be violated by manipulation of tree.
foreach($_POST as $key=> $value) $res