24require_once(__DIR__.
"/mocks.php");
39 PHPUnit_Framework_Error_Deprecated::$enabled = FALSE;
41 require_once(
"./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
43 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
44 ilUnitUtil::performInitialisation();
47 $this->root_object_obj_id = $this->root_object->getId();
48 $this->root_object_ref_id = $this->root_object->getRefId();
49 $this->root_object->putInTree(ROOT_FOLDER_ID);
58 $objDefinition =
$DIC[
'objDefinition'];
59 $this->obj_definition = $objDefinition;
63 if ($this->root_object) {
64 $this->root_object->delete();
72 $this->assertNotEmpty($this->root_object_obj_id);
73 $this->assertGreaterThan(0, $this->root_object_obj_id);
75 $this->assertNotEmpty($this->root_object_ref_id);
76 $this->assertGreaterThan(0, $this->root_object_ref_id);
78 $this->assertTrue($this->tree->isInTree($this->root_object_ref_id));
92 $orig = $this->root_object;
95 $this->assertNotNull($loaded);
96 $this->assertGreaterThan(0, $loaded->getId());
97 $this->assertEquals(
$orig->getId(), $loaded->getId());
101 $this->assertEquals(
$orig->getPoints(), $loaded->getPoints());
102 $this->assertEquals(
$orig->getLPMode(), $loaded->getLPMode());
103 $this->assertEquals(
$orig->getStatus(), $loaded->getStatus());
113 $orig = $this->root_object;
115 $this->assertNotNull($loaded);
116 $this->assertGreaterThan(0, $loaded->getId());
117 $this->assertEquals(
$orig->getId(), $loaded->getId());
121 $this->assertEquals(
$orig->getPoints(), $loaded->getPoints());
122 $this->assertEquals(
$orig->getLPMode(), $loaded->getLPMode());
123 $this->assertEquals(
$orig->getStatus(), $loaded->getStatus());
132 require_once(
"Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
138 $orig = $this->root_object;
140 $this->assertNotNull($loaded);
141 $this->assertGreaterThan(0, $loaded->getId());
142 $this->assertEquals(
$orig->getId(), $loaded->getId());
146 $this->assertEquals(
$orig->getPoints(), $loaded->getPoints());
147 $this->assertEquals(
$orig->getLPMode(), $loaded->getLPMode());
148 $this->assertEquals(
$orig->getStatus(), $loaded->getStatus());
165 $this->assertEquals(10, $obj->getPoints());
168 $midnight = strtotime(
"today midnight");
169 $this->assertGreaterThan($midnight, $obj->getLastChange()->getUnixTime());
180 $this->assertTrue($deleted_object->delete());
191 $this->root_object->addNode($first_node);
192 $this->root_object->addNode($second_node);
193 $this->root_object->addNode($third_node);
196 $third_node->addNode($third_first_node);
206 $this->assertEquals(3, $this->root_object->getAmountOfChildren());
218 $children = $this->root_object->getChildren();
219 $this->assertEquals(3, count($children),
"getChildren()");
222 $this->assertEquals(4, count($children),
"ilObjStudyProgramme::getAllChildren(".$this->root_object_ref_id.
")");
224 $this->assertTrue($this->root_object->hasChildren(),
"hasChildren()");
225 $this->assertEquals(3, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
227 $this->assertFalse($children[0]->hasChildren(),
"hasChildren()");
228 $this->assertEquals(0, $children[0]->getAmountOfChildren(),
"getAmountOfChildren()");
229 $this->assertEquals(0, count($children[0]->getChildren()));
239 $children = $this->root_object->getChildren();
241 $child = $children[0];
242 $this->assertNotNull($child->getParent());
243 $this->assertNull($this->root_object->getParent());
252 $children = $this->root_object->getChildren();
253 $children[0]->addNode($node3);
255 $parents = $node3->getParents();
256 $parent_ids = array_map(
function($node) {
257 return $node->getId();
259 $parent_ids_expected = array( $this->root_object->getId()
260 , $children[0]->getId()
263 $this->assertEquals($parent_ids_expected, $parent_ids);
273 $children = $this->root_object->getChildren();
275 $child = $children[0];
277 $this->assertEquals(1, $child->getDepth());
287 $children = $this->root_object->getChildren();
288 $child = $children[0];
290 $this->assertEquals($this->root_object->getId(), $child->getRoot()->getId());
300 $children = $this->root_object->getChildren();
303 $this->root_object->applyToSubTreeNodes(
function($node) use (&$val) {
304 $val += $node->getPoints();
311 $this->root_object->setPoints(1);
312 $children[0]->setPoints(2);
313 $children[1]->setPoints(4);
314 $children[2]->setPoints(1);
316 $third_level = $children[2]->getChildren();
317 $third_level[0]->setPoints(2);
320 $this->root_object->applyToSubTreeNodes(
function($node) use (&$val) {
321 $val += $node->getPoints();
324 $this->assertEquals($val, 10);
335 $children = $this->root_object->getChildren();
336 $child = $children[0];
338 $grandchild->create();
339 $child->addNode($grandchild);
341 $this->assertEquals($child->getId(), $grandchild->getParent()->getId());
342 $this->assertEquals($this->root_object->getId(), $grandchild->getRoot()->getId(),
343 "Root of grandchild is root of tree.");
344 $this->assertEquals(1, $child->getAmountOfChildren());
345 $this->assertEquals(2, $grandchild->getDepth());
357 $children = $this->root_object->getChildren();
358 $child = $children[0];
359 $this->root_object->removeNode($child);
369 $this->assertTrue($raised,
"Child does not raise on getParent after it is removed.");
371 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
376 $this->root_object->removeNode($child);
381 $this->assertTrue($raised,
"Child can be removed two times.");
393 $children = $this->root_object->getChildren();
394 $first_child = $children[0];
396 $first_child->addLeaf($mock_leaf);
402 $this->assertEquals(3, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
404 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(),
"getAmountOfLPChildren() on root");
405 $this->assertEquals(
false, $this->root_object->hasLPChildren(),
"hasLPChildren() on root");
407 $this->assertEquals(1, $first_child->getAmountOfLPChildren(),
"getAmountOfLPChildren() on first child");
408 $this->assertEquals(
true, $first_child->hasLPChildren(),
"hasLPChildren() on first child");
411 $lp_children = $first_child->getLPChildren();
412 $this->assertEquals(1, count($lp_children));
413 $this->assertEquals($mock_leaf->getId(), $lp_children[0]->getId());
423 $this->root_object->addLeaf($mock_leaf);
425 $this->root_object->removeLeaf($mock_leaf);
426 $this->assertEquals(0, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
427 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(),
"getAmountOfLPChildren()");
429 $lp_children = $this->root_object->getLPChildren();
430 $this->assertEquals(0, count($lp_children));
439 $children = $this->root_object->getChildren();
440 $child_n = $children[0];
441 $child_l = $children[1];
450 $child_n->addNode($node1);
451 $child_l->addLeaf($mock_leaf1);
455 $child_n->addLeaf($mock_leaf2);
460 $this->assertTrue($raised,
"Could add leaf to program containing node.");
464 $child_n->addLeaf($mock_leaf2);
469 $this->assertTrue($raised,
"Could add node to program containing leaf.");
477 $children = $this->root_object->getChildren();
478 $child_l = $children[0];
479 $child_r = $children[1];
480 $child_m = $children[2];
482 $child_r->moveTo($child_l);
484 $this->assertEquals(2, $child_r->getDepth());
485 $this->assertEquals($child_l->getId(), $child_r->getParent()->getId());
486 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
487 $this->assertEquals(1, $child_l->getAmountOfChildren());
490 $this->assertEquals(1, $child_m->getAmountOfChildren());
492 $child_m->moveTo($child_r);
494 $m_children = $child_m->getChildren();
495 $first_third_node = $m_children[0];
497 $this->assertEquals(3, $child_m->getDepth());
498 $this->assertEquals(1, $child_m->getAmountOfChildren());
499 $this->assertNotNull($first_third_node);
500 $this->assertEquals(4, $first_third_node->getDepth());
501 $this->assertEquals($child_m->getId(), $first_third_node->getParent()->getId());
503 $this->assertEquals(1, $this->root_object->getAmountOfChildren());
512 $children = $this->root_object->getChildren();
513 $child_l = $children[0];
514 $child_r = $children[1];
522 $child_l->assignUser($user->getId());
523 $this->root_object->removeNode($child_l);
528 $children = $this->root_object->getChildren();
529 $child_l = $children[0];
530 $child_r = $children[1];
538 $this->root_object->assignUser($user->getId());
539 $this->root_object->removeNode($child_r);
544 $children = $this->root_object->getChildren();
545 $child_l = $children[0];
547 $all_possible_subobjects = $this->root_object->getPossibleSubObjects();
549 unset($all_possible_subobjects[
"rolf"]);
552 $this->assertCount(2, $all_possible_subobjects);
553 $this->assertArrayHasKey(
"prg", $all_possible_subobjects);
554 $this->assertArrayHasKey(
"crsr", $all_possible_subobjects);
558 $this->assertCount(1, $subobjs);
559 $this->assertArrayHasKey(
"prg", $subobjs);
563 $this->assertCount(2, $subobjs);
564 $this->assertArrayHasKey(
"prg", $subobjs);
565 $this->assertArrayHasKey(
"crsr", $subobjs);
568 $children = $this->root_object->getChildren();
570 $child_l->addLeaf($mock_leaf);
574 $this->assertCount(1, $subobjs);
575 $this->assertArrayHasKey(
"crsr", $subobjs);
579 $all_possible_subobjects = $this->obj_definition->getSubObjects(
"prg");
581 unset($all_possible_subobjects[
"rolf"]);
582 $this->assertEquals( $all_possible_subobjects
595 $this->root_object->delete();
596 $this->root_object =
null;
600 $res =
$ilDB->query(
"SELECT COUNT(*) cnt "
602 .
" WHERE obj_id = ".$this->root_object_obj_id
605 $this->assertEquals(0, $rec[
"cnt"]);
612 $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()