24require_once(__DIR__.
"/mocks.php");
38 PHPUnit_Framework_Error_Deprecated::$enabled = FALSE;
40 require_once(
"./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
42 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
43 ilUnitUtil::performInitialisation();
46 $this->root_object_obj_id = $this->root_object->getId();
47 $this->root_object_ref_id = $this->root_object->getRefId();
48 $this->root_object->putInTree(ROOT_FOLDER_ID);
55 global $objDefinition;
56 $this->obj_definition = $objDefinition;
60 if ($this->root_object) {
61 $this->root_object->delete();
69 $this->assertNotEmpty($this->root_object_obj_id);
70 $this->assertGreaterThan(0, $this->root_object_obj_id);
72 $this->assertNotEmpty($this->root_object_ref_id);
73 $this->assertGreaterThan(0, $this->root_object_ref_id);
75 $this->assertTrue($this->tree->isInTree($this->root_object_ref_id));
89 $orig = $this->root_object;
92 $this->assertNotNull($loaded);
93 $this->assertGreaterThan(0, $loaded->getId());
94 $this->assertEquals( $orig->getId(), $loaded->getId());
98 $this->assertEquals( $orig->getPoints(), $loaded->getPoints());
99 $this->assertEquals( $orig->getLPMode(), $loaded->getLPMode());
100 $this->assertEquals( $orig->getStatus(), $loaded->getStatus());
110 $orig = $this->root_object;
112 $this->assertNotNull($loaded);
113 $this->assertGreaterThan(0, $loaded->getId());
114 $this->assertEquals( $orig->getId(), $loaded->getId());
118 $this->assertEquals( $orig->getPoints(), $loaded->getPoints());
119 $this->assertEquals( $orig->getLPMode(), $loaded->getLPMode());
120 $this->assertEquals( $orig->getStatus(), $loaded->getStatus());
129 require_once(
"Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
135 $orig = $this->root_object;
137 $this->assertNotNull($loaded);
138 $this->assertGreaterThan(0, $loaded->getId());
139 $this->assertEquals( $orig->getId(), $loaded->getId());
143 $this->assertEquals( $orig->getPoints(), $loaded->getPoints());
144 $this->assertEquals( $orig->getLPMode(), $loaded->getLPMode());
145 $this->assertEquals( $orig->getStatus(), $loaded->getStatus());
162 $this->assertEquals(10, $obj->getPoints());
165 $midnight = strtotime(
"today midnight");
166 $this->assertGreaterThan($midnight, $obj->getLastChange()->getUnixTime());
177 $this->assertTrue($deleted_object->delete());
188 $this->root_object->addNode($first_node);
189 $this->root_object->addNode($second_node);
190 $this->root_object->addNode($third_node);
193 $third_node->addNode($third_first_node);
203 $this->assertEquals(3, $this->root_object->getAmountOfChildren());
215 $children = $this->root_object->getChildren();
216 $this->assertEquals(3, count($children),
"getChildren()");
219 $this->assertEquals(4, count($children),
"ilObjStudyProgramme::getAllChildren(".$this->root_object_ref_id.
")");
221 $this->assertTrue($this->root_object->hasChildren(),
"hasChildren()");
222 $this->assertEquals(3, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
224 $this->assertFalse($children[0]->hasChildren(),
"hasChildren()");
225 $this->assertEquals(0, $children[0]->getAmountOfChildren(),
"getAmountOfChildren()");
226 $this->assertEquals(0, count($children[0]->getChildren()));
236 $children = $this->root_object->getChildren();
238 $child = $children[0];
239 $this->assertNotNull($child->getParent());
240 $this->assertNull($this->root_object->getParent());
249 $children = $this->root_object->getChildren();
250 $children[0]->addNode($node3);
252 $parents = $node3->getParents();
253 $parent_ids = array_map(
function($node) {
254 return $node->getId();
256 $parent_ids_expected = array( $this->root_object->getId()
257 , $children[0]->getId()
260 $this->assertEquals($parent_ids_expected, $parent_ids);
270 $children = $this->root_object->getChildren();
272 $child = $children[0];
274 $this->assertEquals(1, $child->getDepth());
284 $children = $this->root_object->getChildren();
285 $child = $children[0];
287 $this->assertEquals($this->root_object->getId(), $child->getRoot()->getId());
297 $children = $this->root_object->getChildren();
300 $this->root_object->applyToSubTreeNodes(
function($node) use (&$val) {
301 $val += $node->getPoints();
308 $this->root_object->setPoints(1);
309 $children[0]->setPoints(2);
310 $children[1]->setPoints(4);
311 $children[2]->setPoints(1);
313 $third_level = $children[2]->getChildren();
314 $third_level[0]->setPoints(2);
317 $this->root_object->applyToSubTreeNodes(
function($node) use (&$val) {
318 $val += $node->getPoints();
321 $this->assertEquals($val, 10);
332 $children = $this->root_object->getChildren();
333 $child = $children[0];
335 $grandchild->create();
336 $child->addNode($grandchild);
338 $this->assertEquals($child->getId(), $grandchild->getParent()->getId());
339 $this->assertEquals($this->root_object->getId(), $grandchild->getRoot()->getId(),
340 "Root of grandchild is root of tree.");
341 $this->assertEquals(1, $child->getAmountOfChildren());
342 $this->assertEquals(2, $grandchild->getDepth());
354 $children = $this->root_object->getChildren();
355 $child = $children[0];
356 $this->root_object->removeNode($child);
366 $this->assertTrue($raised,
"Child does not raise on getParent after it is removed.");
368 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
373 $this->root_object->removeNode($child);
378 $this->assertTrue($raised,
"Child can be removed two times.");
390 $children = $this->root_object->getChildren();
391 $first_child = $children[0];
393 $first_child->addLeaf($mock_leaf);
399 $this->assertEquals(3, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
401 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(),
"getAmountOfLPChildren() on root");
402 $this->assertEquals(
false, $this->root_object->hasLPChildren(),
"hasLPChildren() on root");
404 $this->assertEquals(1, $first_child->getAmountOfLPChildren(),
"getAmountOfLPChildren() on first child");
405 $this->assertEquals(
true, $first_child->hasLPChildren(),
"hasLPChildren() on first child");
408 $lp_children = $first_child->getLPChildren();
409 $this->assertEquals(1, count($lp_children));
410 $this->assertEquals($mock_leaf->getId(), $lp_children[0]->getId());
420 $this->root_object->addLeaf($mock_leaf);
422 $this->root_object->removeLeaf($mock_leaf);
423 $this->assertEquals(0, $this->root_object->getAmountOfChildren(),
"getAmountOfChildren()");
424 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(),
"getAmountOfLPChildren()");
426 $lp_children = $this->root_object->getLPChildren();
427 $this->assertEquals(0, count($lp_children));
436 $children = $this->root_object->getChildren();
437 $child_n = $children[0];
438 $child_l = $children[1];
447 $child_n->addNode($node1);
448 $child_l->addLeaf($mock_leaf1);
452 $child_n->addLeaf($mock_leaf2);
457 $this->assertTrue($raised,
"Could add leaf to program containing node.");
461 $child_n->addLeaf($mock_leaf2);
466 $this->assertTrue($raised,
"Could add node to program containing leaf.");
474 $children = $this->root_object->getChildren();
475 $child_l = $children[0];
476 $child_r = $children[1];
477 $child_m = $children[2];
479 $child_r->moveTo($child_l);
481 $this->assertEquals(2, $child_r->getDepth());
482 $this->assertEquals($child_l->getId(), $child_r->getParent()->getId());
483 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
484 $this->assertEquals(1, $child_l->getAmountOfChildren());
487 $this->assertEquals(1, $child_m->getAmountOfChildren());
489 $child_m->moveTo($child_r);
491 $m_children = $child_m->getChildren();
492 $first_third_node = $m_children[0];
494 $this->assertEquals(3, $child_m->getDepth());
495 $this->assertEquals(1, $child_m->getAmountOfChildren());
496 $this->assertNotNull($first_third_node);
497 $this->assertEquals(4, $first_third_node->getDepth());
498 $this->assertEquals($child_m->getId(), $first_third_node->getParent()->getId());
500 $this->assertEquals(1, $this->root_object->getAmountOfChildren());
509 $children = $this->root_object->getChildren();
510 $child_l = $children[0];
511 $child_r = $children[1];
519 $child_l->assignUser($user->getId());
520 $this->root_object->removeNode($child_l);
525 $children = $this->root_object->getChildren();
526 $child_l = $children[0];
527 $child_r = $children[1];
535 $this->root_object->assignUser($user->getId());
536 $this->root_object->removeNode($child_r);
541 $children = $this->root_object->getChildren();
542 $child_l = $children[0];
544 $all_possible_subobjects = $this->root_object->getPossibleSubObjects();
546 unset($all_possible_subobjects[
"rolf"]);
549 $this->assertCount(2, $all_possible_subobjects);
550 $this->assertArrayHasKey(
"prg", $all_possible_subobjects);
551 $this->assertArrayHasKey(
"crsr", $all_possible_subobjects);
555 $this->assertCount(1, $subobjs);
556 $this->assertArrayHasKey(
"prg", $subobjs);
560 $this->assertCount(2, $subobjs);
561 $this->assertArrayHasKey(
"prg", $subobjs);
562 $this->assertArrayHasKey(
"crsr", $subobjs);
565 $children = $this->root_object->getChildren();
567 $child_l->addLeaf($mock_leaf);
571 $this->assertCount(1, $subobjs);
572 $this->assertArrayHasKey(
"crsr", $subobjs);
576 $all_possible_subobjects = $this->obj_definition->getSubObjects(
"prg");
578 unset($all_possible_subobjects[
"rolf"]);
579 $this->assertEquals( $all_possible_subobjects
592 $this->root_object->delete();
593 $this->root_object =
null;
596 $res =
$ilDB->query(
"SELECT COUNT(*) cnt "
598 .
" WHERE obj_id = ".$this->root_object_obj_id
601 $this->assertEquals(0, $rec[
"cnt"]);
608 $this->assertCount(1, $op_ids);
TestCase for the ilObjStudyProgramme.
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()