24require_once(__DIR__ .
"/mocks.php");
41 PHPUnit_Framework_Error_Deprecated::$enabled =
false;
43 require_once(
"./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
45 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
46 ilUnitUtil::performInitialisation();
49 $this->root_object_obj_id = $this->root_object->getId();
50 $this->root_object_ref_id = $this->root_object->getRefId();
51 $this->root_object->putInTree(ROOT_FOLDER_ID);
60 $objDefinition =
$DIC[
'objDefinition'];
61 $this->obj_definition = $objDefinition;
66 if ($this->root_object) {
67 $this->root_object->delete();
76 $this->assertNotEmpty($this->root_object_obj_id);
77 $this->assertGreaterThan(0, $this->root_object_obj_id);
79 $this->assertNotEmpty($this->root_object_ref_id);
80 $this->assertGreaterThan(0, $this->root_object_ref_id);
82 $this->assertTrue($this->tree->isInTree($this->root_object_ref_id));
98 $orig = $this->root_object;
101 $this->assertNotNull($loaded);
102 $this->assertGreaterThan(0, $loaded->getId());
103 $this->assertEquals(
$orig->getId(), $loaded->getId());
108 $this->assertEquals(
$orig->getPoints(), $loaded->getPoints());
109 $this->assertEquals(
$orig->getLPMode(), $loaded->getLPMode());
110 $this->assertEquals(
$orig->getStatus(), $loaded->getStatus());
121 $orig = $this->root_object;
123 $this->assertNotNull($loaded);
124 $this->assertGreaterThan(0, $loaded->getId());
125 $this->assertEquals(
$orig->getId(), $loaded->getId());
130 $this->assertEquals(
$orig->getPoints(), $loaded->getPoints());
131 $this->assertEquals(
$orig->getLPMode(), $loaded->getLPMode());
132 $this->assertEquals(
$orig->getStatus(), $loaded->getStatus());
142 require_once(
"Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
148 $orig = $this->root_object;
150 $this->assertNotNull($loaded);
151 $this->assertGreaterThan(0, $loaded->getId());
152 $this->assertEquals(
$orig->getId(), $loaded->getId());
157 $this->assertEquals(
$orig->getPoints(), $loaded->getPoints());
158 $this->assertEquals(
$orig->getLPMode(), $loaded->getLPMode());
159 $this->assertEquals(
$orig->getStatus(), $loaded->getStatus());
177 $this->assertEquals(10, $obj->getPoints());
180 $midnight = strtotime(
"today midnight");
181 $this->assertGreaterThan($midnight, $obj->getLastChange()->getUnixTime());
193 $this->assertTrue($deleted_object->delete());
205 $this->root_object->addNode($first_node);
206 $this->root_object->addNode($second_node);
207 $this->root_object->addNode($third_node);
210 $third_node->addNode($third_first_node);
221 $this->assertEquals(3, $this->root_object->getAmountOfChildren());
234 $children = $this->root_object->getChildren();
235 $this->assertEquals(3, count($children),
"getChildren()");
238 $this->assertEquals(4, count($children),
"ilObjStudyProgramme::getAllChildren(" . $this->root_object_ref_id .
")");
240 $this->assertTrue($this->root_object->hasChildren(),
"hasChildren()");
241 $this->assertEquals(3, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
243 $this->assertFalse($children[0]->hasChildren(),
"hasChildren()");
244 $this->assertEquals(0, $children[0]->getAmountOfChildren(),
"getAmountOfChildren()");
245 $this->assertEquals(0, count($children[0]->getChildren()));
256 $children = $this->root_object->getChildren();
258 $child = $children[0];
259 $this->assertNotNull($child->getParent());
260 $this->assertNull($this->root_object->getParent());
270 $children = $this->root_object->getChildren();
271 $children[0]->addNode($node3);
273 $parents = $node3->getParents();
274 $parent_ids = array_map(
function ($node) {
275 return $node->getId();
277 $parent_ids_expected = array( $this->root_object->getId()
278 , $children[0]->getId()
281 $this->assertEquals($parent_ids_expected, $parent_ids);
292 $children = $this->root_object->getChildren();
294 $child = $children[0];
296 $this->assertEquals(1, $child->getDepth());
307 $children = $this->root_object->getChildren();
308 $child = $children[0];
310 $this->assertEquals($this->root_object->getId(), $child->getRoot()->getId());
321 $children = $this->root_object->getChildren();
324 $this->root_object->applyToSubTreeNodes(
function ($node) use (&$val) {
325 $val += $node->getPoints();
332 $this->root_object->setPoints(1);
333 $children[0]->setPoints(2);
334 $children[1]->setPoints(4);
335 $children[2]->setPoints(1);
337 $third_level = $children[2]->getChildren();
338 $third_level[0]->setPoints(2);
341 $this->root_object->applyToSubTreeNodes(
function ($node) use (&$val) {
342 $val += $node->getPoints();
345 $this->assertEquals($val, 10);
357 $children = $this->root_object->getChildren();
358 $child = $children[0];
360 $grandchild->create();
361 $child->addNode($grandchild);
363 $this->assertEquals($child->getId(), $grandchild->getParent()->getId());
365 $this->root_object->getId(),
366 $grandchild->getRoot()->getId(),
367 "Root of grandchild is root of tree."
369 $this->assertEquals(1, $child->getAmountOfChildren());
370 $this->assertEquals(2, $grandchild->getDepth());
383 $children = $this->root_object->getChildren();
384 $child = $children[0];
385 $this->root_object->removeNode($child);
394 $this->assertTrue($raised,
"Child does not raise on getParent after it is removed.");
396 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
401 $this->root_object->removeNode($child);
405 $this->assertTrue($raised,
"Child can be removed two times.");
418 $children = $this->root_object->getChildren();
419 $first_child = $children[0];
421 $first_child->addLeaf($mock_leaf);
427 $this->assertEquals(3, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
429 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(),
"getAmountOfLPChildren() on root");
430 $this->assertEquals(
false, $this->root_object->hasLPChildren(),
"hasLPChildren() on root");
432 $this->assertEquals(1, $first_child->getAmountOfLPChildren(),
"getAmountOfLPChildren() on first child");
433 $this->assertEquals(
true, $first_child->hasLPChildren(),
"hasLPChildren() on first child");
436 $lp_children = $first_child->getLPChildren();
437 $this->assertEquals(1, count($lp_children));
438 $this->assertEquals($mock_leaf->getId(), $lp_children[0]->getId());
449 $this->root_object->addLeaf($mock_leaf);
451 $this->root_object->removeLeaf($mock_leaf);
452 $this->assertEquals(0, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
453 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(),
"getAmountOfLPChildren()");
455 $lp_children = $this->root_object->getLPChildren();
456 $this->assertEquals(0, count($lp_children));
466 $children = $this->root_object->getChildren();
467 $child_n = $children[0];
468 $child_l = $children[1];
477 $child_n->addNode($node1);
478 $child_l->addLeaf($mock_leaf1);
482 $child_n->addLeaf($mock_leaf2);
486 $this->assertTrue($raised,
"Could add leaf to program containing node.");
490 $child_n->addLeaf($mock_leaf2);
494 $this->assertTrue($raised,
"Could add node to program containing leaf.");
503 $children = $this->root_object->getChildren();
504 $child_l = $children[0];
505 $child_r = $children[1];
506 $child_m = $children[2];
508 $child_r->moveTo($child_l);
510 $this->assertEquals(2, $child_r->getDepth());
511 $this->assertEquals($child_l->getId(), $child_r->getParent()->getId());
512 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
513 $this->assertEquals(1, $child_l->getAmountOfChildren());
516 $this->assertEquals(1, $child_m->getAmountOfChildren());
518 $child_m->moveTo($child_r);
520 $m_children = $child_m->getChildren();
521 $first_third_node = $m_children[0];
523 $this->assertEquals(3, $child_m->getDepth());
524 $this->assertEquals(1, $child_m->getAmountOfChildren());
525 $this->assertNotNull($first_third_node);
526 $this->assertEquals(4, $first_third_node->getDepth());
527 $this->assertEquals($child_m->getId(), $first_third_node->getParent()->getId());
529 $this->assertEquals(1, $this->root_object->getAmountOfChildren());
539 $children = $this->root_object->getChildren();
540 $child_l = $children[0];
541 $child_r = $children[1];
549 $child_l->assignUser($user->getId());
550 $this->root_object->removeNode($child_l);
556 $children = $this->root_object->getChildren();
557 $child_l = $children[0];
558 $child_r = $children[1];
566 $this->root_object->assignUser($user->getId());
567 $this->root_object->removeNode($child_r);
573 $children = $this->root_object->getChildren();
574 $child_l = $children[0];
576 $all_possible_subobjects = $this->root_object->getPossibleSubObjects();
578 unset($all_possible_subobjects[
"rolf"]);
581 $this->assertCount(2, $all_possible_subobjects);
582 $this->assertArrayHasKey(
"prg", $all_possible_subobjects);
583 $this->assertArrayHasKey(
"crsr", $all_possible_subobjects);
587 $this->assertCount(1, $subobjs);
588 $this->assertArrayHasKey(
"prg", $subobjs);
592 $this->assertCount(2, $subobjs);
593 $this->assertArrayHasKey(
"prg", $subobjs);
594 $this->assertArrayHasKey(
"crsr", $subobjs);
597 $children = $this->root_object->getChildren();
599 $child_l->addLeaf($mock_leaf);
603 $this->assertCount(1, $subobjs);
604 $this->assertArrayHasKey(
"crsr", $subobjs);
609 $all_possible_subobjects = $this->obj_definition->getSubObjects(
"prg");
611 unset($all_possible_subobjects[
"rolf"]);
613 $all_possible_subobjects,
628 $this->root_object->delete();
629 $this->root_object =
null;
634 "SELECT COUNT(*) cnt "
636 .
" WHERE obj_id = " . $this->root_object_obj_id
639 $this->assertEquals(0, $rec[
"cnt"]);
647 $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 tings 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.
Class ilObjStudyProgramme.
static getCreatableSubObjects($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($a_ref_id)
Get a list of all ilObjStudyProgrammes in the subtree starting at $a_ref_id.
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
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.
static returnDbTableName()
foreach($_POST as $key=> $value) $res