ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilObjStudyProgrammeTest Class Reference

TestCase for the ilObjStudyProgramme @group needsInstalledILIAS. More...

+ Inheritance diagram for ilObjStudyProgrammeTest:
+ Collaboration diagram for ilObjStudyProgrammeTest:

Public Member Functions

 testCreation ()
 Test creation of ilObjStudyProgramme. More...
 
 testDefaults ()
 
 testLoadByObjId ()
 Test loading of ilObjStudyProgramme with obj_id. More...
 
 testLoadByRefId ()
 Test loading of ilObjStudyProgramme with ref_id. More...
 
 testGetInstanceByRefId ()
 Test loading over getInstance. More...
 
 testSettings ()
 Test tings on ilObjStudyProgramme. More...
 
 testDelete ()
 Test deletion of a ilObjStudyProgramme. More...
 
 testTreeCreation ()
 Test creating a small tree. More...
 
 testTreeGetChildren ()
 Test function to get children or information about them. More...
 
 testTreeGetParent ()
 Test getParent on ilObjStudyProgramme. More...
 
 testTreeGetParents ()
 @depends testTreeCreation More...
 
 testTreeDepth ()
 Test getDepth on ilObjStudyProgramme. More...
 
 testTreeGetRoot ()
 Test getRoot on ilObjStudyProgramme. More...
 
 testApplyToSubTreeNodes ()
 Test applyToSubTreeNodes on ilObjStudyProgramme. More...
 
 testAddNode ()
 Test on addNode. More...
 
 testRemoveNode ()
 Test on removeNode. More...
 
 testAddLeaf ()
 Test on addLeaf. More...
 
 testRemoveLeaf ()
 Test on removeLead. More...
 
 testAddWrongChildType ()
 Test whether nodes can only be added when there is no leaf in the parent and vice versa. More...
 
 testMoveTo ()
 Test on moveTo. More...
 
 testCantRemoveNodeWithRelevantProgress ()
 @expectedException ilStudyProgrammeTreeException More...
 
 testCanRemoveNodeWithNotRelevantProgress ()
 
 testCreateableSubObjects ()
 
 testCreatableSubObjectsWithoutRef ()
 
 testCreatableSubObjectsRaisesOnNonProgramRef ()
 @expectedException ilException More...
 
 testDeleteRemovesEntriesInPrgSettings ()
 
 testCreatePermissionExists ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 
 createSmallTree ()
 Creates a small tree, used by various tests. More...
 

Protected Attributes

 $backupGlobals = false
 

Detailed Description

Member Function Documentation

◆ createSmallTree()

ilObjStudyProgrammeTest::createSmallTree ( )
protected

Creates a small tree, used by various tests.

Definition at line 199 of file ilObjStudyProgrammeTest.php.

200 {
204
205 $this->root_object->addNode($first_node);
206 $this->root_object->addNode($second_node);
207 $this->root_object->addNode($third_node);
208
209 $third_first_node = ilObjStudyProgramme::createInstance();
210 $third_node->addNode($third_first_node);
211 }
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.

References ilObjStudyProgramme\createInstance().

Referenced by testAddLeaf(), testAddNode(), testAddWrongChildType(), testApplyToSubTreeNodes(), testCanRemoveNodeWithNotRelevantProgress(), testCantRemoveNodeWithRelevantProgress(), testCreateableSubObjects(), testMoveTo(), testRemoveNode(), testTreeCreation(), testTreeDepth(), testTreeGetChildren(), testTreeGetParent(), testTreeGetParents(), and testTreeGetRoot().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUp()

ilObjStudyProgrammeTest::setUp ( )
protected

Definition at line 39 of file ilObjStudyProgrammeTest.php.

40 {
41 PHPUnit_Framework_Error_Deprecated::$enabled = false;
42
43 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
44
45 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
46 ilUnitUtil::performInitialisation();
47
48 $this->root_object = ilObjStudyProgramme::createInstance();
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);
52
53 //
54
55 global $DIC;
56 $tree = $DIC['tree'];
57 $this->tree = $tree;
58
59 global $DIC;
60 $objDefinition = $DIC['objDefinition'];
61 $this->obj_definition = $objDefinition;
62 }
global $DIC
Definition: saml.php:7

References $DIC, $tree, and ilObjStudyProgramme\createInstance().

+ Here is the call graph for this function:

◆ tearDown()

ilObjStudyProgrammeTest::tearDown ( )
protected

Definition at line 64 of file ilObjStudyProgrammeTest.php.

65 {
66 if ($this->root_object) {
67 $this->root_object->delete();
68 }
69 }

◆ testAddLeaf()

ilObjStudyProgrammeTest::testAddLeaf ( )

Test on addLeaf.

@depends testTreeCreation

Definition at line 413 of file ilObjStudyProgrammeTest.php.

414 {
415 $this->createSmallTree();
416 $mock_leaf = new ilStudyProgrammeLeafMock();
417
418 $children = $this->root_object->getChildren();
419 $first_child = $children[0];
420
421 $first_child->addLeaf($mock_leaf);
422
423 // We use our mock factory, since the original factory won't know how
424 // to create our mock leaf.
425 $first_child->object_factory = new ilObjectFactoryWrapperMock();
426
427 $this->assertEquals(3, $this->root_object->getAmountOfChildren(), "getAmountOfChildren()");
428 // Check if StudyProgrammes are not counted as LP-Children
429 $this->assertEquals(0, $this->root_object->getAmountOfLPChildren(), "getAmountOfLPChildren() on root");
430 $this->assertEquals(false, $this->root_object->hasLPChildren(), "hasLPChildren() on root");
431
432 $this->assertEquals(1, $first_child->getAmountOfLPChildren(), "getAmountOfLPChildren() on first child");
433 $this->assertEquals(true, $first_child->hasLPChildren(), "hasLPChildren() on first child");
434 $this->assertEquals($first_child->getLPMode(), ilStudyProgramme::MODE_LP_COMPLETED);
435
436 $lp_children = $first_child->getLPChildren();
437 $this->assertEquals(1, count($lp_children));
438 $this->assertEquals($mock_leaf->getId(), $lp_children[0]->getId());
439 }
createSmallTree()
Creates a small tree, used by various tests.
Mock for object factory.
Definition: mocks.php:69
Mock classes for tests.
Definition: mocks.php:21

References createSmallTree(), and ilStudyProgramme\MODE_LP_COMPLETED.

+ Here is the call graph for this function:

◆ testAddNode()

ilObjStudyProgrammeTest::testAddNode ( )

Test on addNode.

@depends testTreeCreation

Definition at line 353 of file ilObjStudyProgrammeTest.php.

354 {
355 $this->createSmallTree();
356
357 $children = $this->root_object->getChildren();
358 $child = $children[0];
359 $grandchild = new ilObjStudyProgramme();
360 $grandchild->create();
361 $child->addNode($grandchild);
362
363 $this->assertEquals($child->getId(), $grandchild->getParent()->getId());
364 $this->assertEquals(
365 $this->root_object->getId(),
366 $grandchild->getRoot()->getId(),
367 "Root of grandchild is root of tree."
368 );
369 $this->assertEquals(1, $child->getAmountOfChildren());
370 $this->assertEquals(2, $grandchild->getDepth());
371 $this->assertEquals($child->getLPMode(), ilStudyProgramme::MODE_POINTS);
372 }
Class ilObjStudyProgramme.

References createSmallTree(), and ilStudyProgramme\MODE_POINTS.

+ Here is the call graph for this function:

◆ testAddWrongChildType()

ilObjStudyProgrammeTest::testAddWrongChildType ( )

Test whether nodes can only be added when there is no leaf in the parent and vice versa.

Definition at line 463 of file ilObjStudyProgrammeTest.php.

464 {
465 $this->createSmallTree();
466 $children = $this->root_object->getChildren();
467 $child_n = $children[0];
468 $child_l = $children[1];
469
470 $mock_leaf1 = new ilStudyProgrammeLeafMock();
471 $mock_leaf2 = new ilStudyProgrammeLeafMock();
472 $node1 = new ilObjStudyProgramme();
473 $node2 = new ilObjStudyProgramme();
474 $node1->create();
475 $node2->create();
476
477 $child_n->addNode($node1);
478 $child_l->addLeaf($mock_leaf1);
479
480 $raised = false;
481 try {
482 $child_n->addLeaf($mock_leaf2);
483 } catch (ilStudyProgrammeTreeException $e) {
484 $raised = true;
485 }
486 $this->assertTrue($raised, "Could add leaf to program containing node.");
487
488 $raised = false;
489 try {
490 $child_n->addLeaf($mock_leaf2);
491 } catch (ilStudyProgrammeTreeException $e) {
492 $raised = true;
493 }
494 $this->assertTrue($raised, "Could add node to program containing leaf.");
495 }
Exception is thrown when invariants on the program tree would be violated by manipulation of tree.

References createSmallTree().

+ Here is the call graph for this function:

◆ testApplyToSubTreeNodes()

ilObjStudyProgrammeTest::testApplyToSubTreeNodes ( )

Test applyToSubTreeNodes on ilObjStudyProgramme.

@depends testTreeCreation

Definition at line 318 of file ilObjStudyProgrammeTest.php.

319 {
320 $this->createSmallTree();
321 $children = $this->root_object->getChildren();
322
323 $val = 0;
324 $this->root_object->applyToSubTreeNodes(function ($node) use (&$val) {
325 $val += $node->getPoints();
326 });
327
328 // We didn't make modification on the points of the nodes.
329 $this->assertEquals($val, 5 * ilStudyProgramme::DEFAULT_POINTS);
330
331
332 $this->root_object->setPoints(1);
333 $children[0]->setPoints(2);
334 $children[1]->setPoints(4);
335 $children[2]->setPoints(1);
336
337 $third_level = $children[2]->getChildren();
338 $third_level[0]->setPoints(2);
339
340 $val = 0;
341 $this->root_object->applyToSubTreeNodes(function ($node) use (&$val) {
342 $val += $node->getPoints();
343 });
344
345 $this->assertEquals($val, 10);
346 }

References createSmallTree(), and ilStudyProgramme\DEFAULT_POINTS.

+ Here is the call graph for this function:

◆ testCanRemoveNodeWithNotRelevantProgress()

ilObjStudyProgrammeTest::testCanRemoveNodeWithNotRelevantProgress ( )

Definition at line 553 of file ilObjStudyProgrammeTest.php.

554 {
555 $this->createSmallTree();
556 $children = $this->root_object->getChildren();
557 $child_l = $children[0];
558 $child_r = $children[1];
559 $this->root_object->setStatus(ilStudyProgramme::STATUS_ACTIVE);
560 $child_l->setStatus(ilStudyProgramme::STATUS_ACTIVE);
561 $child_r->setStatus(ilStudyProgramme::STATUS_OUTDATED);
562
563 $user = new ilObjUser();
564 $user->create();
565
566 $this->root_object->assignUser($user->getId());
567 $this->root_object->removeNode($child_r);
568 }
$user
Definition: migrateto20.php:57

References $user, createSmallTree(), ilStudyProgramme\STATUS_ACTIVE, and ilStudyProgramme\STATUS_OUTDATED.

+ Here is the call graph for this function:

◆ testCantRemoveNodeWithRelevantProgress()

ilObjStudyProgrammeTest::testCantRemoveNodeWithRelevantProgress ( )

@expectedException ilStudyProgrammeTreeException

Definition at line 536 of file ilObjStudyProgrammeTest.php.

537 {
538 $this->createSmallTree();
539 $children = $this->root_object->getChildren();
540 $child_l = $children[0];
541 $child_r = $children[1];
542 $this->root_object->setStatus(ilStudyProgramme::STATUS_ACTIVE);
543 $child_l->setStatus(ilStudyProgramme::STATUS_ACTIVE);
544 $child_r->setStatus(ilStudyProgramme::STATUS_ACTIVE);
545
546 $user = new ilObjUser();
547 $user->create();
548
549 $child_l->assignUser($user->getId());
550 $this->root_object->removeNode($child_l);
551 }

References $user, createSmallTree(), and ilStudyProgramme\STATUS_ACTIVE.

+ Here is the call graph for this function:

◆ testCreatableSubObjectsRaisesOnNonProgramRef()

ilObjStudyProgrammeTest::testCreatableSubObjectsRaisesOnNonProgramRef ( )

@expectedException ilException

Definition at line 621 of file ilObjStudyProgrammeTest.php.

622 {
624 }
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...

References ilObjStudyProgramme\getCreatableSubObjects().

+ Here is the call graph for this function:

◆ testCreatableSubObjectsWithoutRef()

ilObjStudyProgrammeTest::testCreatableSubObjectsWithoutRef ( )

Definition at line 607 of file ilObjStudyProgrammeTest.php.

608 {
609 $all_possible_subobjects = $this->obj_definition->getSubObjects("prg");
610 // don't take rolfs into account, we don't need rolf anymore
611 unset($all_possible_subobjects["rolf"]);
612 $this->assertEquals(
613 $all_possible_subobjects,
614 ilObjStudyProgramme::getCreatableSubObjects($all_possible_subobjects, null)
615 );
616 }

References ilObjStudyProgramme\getCreatableSubObjects().

+ Here is the call graph for this function:

◆ testCreateableSubObjects()

ilObjStudyProgrammeTest::testCreateableSubObjects ( )

Definition at line 570 of file ilObjStudyProgrammeTest.php.

571 {
572 $this->createSmallTree();
573 $children = $this->root_object->getChildren();
574 $child_l = $children[0];
575
576 $all_possible_subobjects = $this->root_object->getPossibleSubObjects();
577 // don't take rolfs into account, we don't need rolf anymore
578 unset($all_possible_subobjects["rolf"]);
579
580 // this is course reference and training programme
581 $this->assertCount(2, $all_possible_subobjects);
582 $this->assertArrayHasKey("prg", $all_possible_subobjects);
583 $this->assertArrayHasKey("crsr", $all_possible_subobjects);
584
585 // root already contains program nodes, so course ref is forbidden
586 $subobjs = ilObjStudyProgramme::getCreatableSubObjects($all_possible_subobjects, $this->root_object->getRefId());
587 $this->assertCount(1, $subobjs);
588 $this->assertArrayHasKey("prg", $subobjs);
589
590 // first node contains nothing, so course ref and program node are allowed
591 $subobjs = ilObjStudyProgramme::getCreatableSubObjects($all_possible_subobjects, $child_l->getRefId());
592 $this->assertCount(2, $subobjs);
593 $this->assertArrayHasKey("prg", $subobjs);
594 $this->assertArrayHasKey("crsr", $subobjs);
595
596 $mock_leaf = new ilStudyProgrammeLeafMock();
597 $children = $this->root_object->getChildren();
598 $child_l->object_factory = new ilObjectFactoryWrapperMock();
599 $child_l->addLeaf($mock_leaf);
600
601 // Now we added a leaf, so no program nodes are allowed anymore.
602 $subobjs = ilObjStudyProgramme::getCreatableSubObjects($all_possible_subobjects, $child_l->getRefId());
603 $this->assertCount(1, $subobjs);
604 $this->assertArrayHasKey("crsr", $subobjs);
605 }

References createSmallTree(), and ilObjStudyProgramme\getCreatableSubObjects().

+ Here is the call graph for this function:

◆ testCreatePermissionExists()

ilObjStudyProgrammeTest::testCreatePermissionExists ( )

Definition at line 642 of file ilObjStudyProgrammeTest.php.

643 {
644 // Ask for permission id for creation of "foobar" to check assumption
645 // that lookupCreateOperationIds just drops unknown object types.
646 $op_ids = ilRbacReview::lookupCreateOperationIds(array("prg", "foobar"));
647 $this->assertCount(1, $op_ids);
648 }
static lookupCreateOperationIds($a_type_arr)
Lookup operation ids.

References ilRbacReview\lookupCreateOperationIds().

+ Here is the call graph for this function:

◆ testCreation()

ilObjStudyProgrammeTest::testCreation ( )

Test creation of ilObjStudyProgramme.

Definition at line 74 of file ilObjStudyProgrammeTest.php.

75 {
76 $this->assertNotEmpty($this->root_object_obj_id);
77 $this->assertGreaterThan(0, $this->root_object_obj_id);
78
79 $this->assertNotEmpty($this->root_object_ref_id);
80 $this->assertGreaterThan(0, $this->root_object_ref_id);
81
82 $this->assertTrue($this->tree->isInTree($this->root_object_ref_id));
83 }

◆ testDefaults()

ilObjStudyProgrammeTest::testDefaults ( )

Definition at line 85 of file ilObjStudyProgrammeTest.php.

86 {
87 $this->assertEquals($this->root_object->getStatus(), ilStudyProgramme::STATUS_DRAFT);
88 }

References ilStudyProgramme\STATUS_DRAFT.

◆ testDelete()

ilObjStudyProgrammeTest::testDelete ( )

Test deletion of a ilObjStudyProgramme.

@depends testCreation

Definition at line 189 of file ilObjStudyProgrammeTest.php.

190 {
191 $deleted_object = ilObjStudyProgramme::getInstanceByRefId($this->root_object_ref_id);
192
193 $this->assertTrue($deleted_object->delete());
194 }
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.

References ilObjStudyProgramme\getInstanceByRefId().

+ Here is the call graph for this function:

◆ testDeleteRemovesEntriesInPrgSettings()

ilObjStudyProgrammeTest::testDeleteRemovesEntriesInPrgSettings ( )

Definition at line 626 of file ilObjStudyProgrammeTest.php.

627 {
628 $this->root_object->delete();
629 $this->root_object = null;
630
631 global $DIC;
632 $ilDB = $DIC['ilDB'];
633 $res = $ilDB->query(
634 "SELECT COUNT(*) cnt "
636 . " WHERE obj_id = " . $this->root_object_obj_id
637 );
638 $rec = $ilDB->fetchAssoc($res);
639 $this->assertEquals(0, $rec["cnt"]);
640 }
foreach($_POST as $key=> $value) $res
global $ilDB

References $DIC, $ilDB, $res, and ilStudyProgramme\returnDbTableName().

+ Here is the call graph for this function:

◆ testGetInstanceByRefId()

ilObjStudyProgrammeTest::testGetInstanceByRefId ( )

Test loading over getInstance.

@depends testCreation

Definition at line 140 of file ilObjStudyProgrammeTest.php.

141 {
142 require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
143
145 $this->assertTrue(ilObjStudyProgrammeCache::singleton()->test_isEmpty());
146
147 $loaded = ilObjStudyProgramme::getInstanceByRefId($this->root_object_ref_id);
148 $orig = $this->root_object;
149
150 $this->assertNotNull($loaded);
151 $this->assertGreaterThan(0, $loaded->getId());
152 $this->assertEquals($orig->getId(), $loaded->getId());
153 $this->assertEquals(
154 $orig->getLastChange()->get(IL_CAL_DATETIME),
155 $loaded->getLastChange()->get(IL_CAL_DATETIME)
156 );
157 $this->assertEquals($orig->getPoints(), $loaded->getPoints());
158 $this->assertEquals($orig->getLPMode(), $loaded->getLPMode());
159 $this->assertEquals($orig->getStatus(), $loaded->getStatus());
160 }
const IL_CAL_DATETIME

References ilObjStudyProgramme\getInstanceByRefId(), IL_CAL_DATETIME, and ilObjStudyProgrammeCache\singleton().

+ Here is the call graph for this function:

◆ testLoadByObjId()

ilObjStudyProgrammeTest::testLoadByObjId ( )

Test loading of ilObjStudyProgramme with obj_id.

and ref_id

@depends testCreation

Definition at line 95 of file ilObjStudyProgrammeTest.php.

96 {
97 $loaded = new ilObjStudyProgramme($this->root_object_obj_id, false);
98 $orig = $this->root_object;
99 $load_ref_id = ilObjStudyProgramme::getInstanceByRefId($this->root_object_ref_id);
100
101 $this->assertNotNull($loaded);
102 $this->assertGreaterThan(0, $loaded->getId());
103 $this->assertEquals($orig->getId(), $loaded->getId());
104 $this->assertEquals(
105 $orig->getLastChange()->get(IL_CAL_DATETIME),
106 $loaded->getLastChange()->get(IL_CAL_DATETIME)
107 );
108 $this->assertEquals($orig->getPoints(), $loaded->getPoints());
109 $this->assertEquals($orig->getLPMode(), $loaded->getLPMode());
110 $this->assertEquals($orig->getStatus(), $loaded->getStatus());
111 }

References ilObjStudyProgramme\getInstanceByRefId(), and IL_CAL_DATETIME.

+ Here is the call graph for this function:

◆ testLoadByRefId()

ilObjStudyProgrammeTest::testLoadByRefId ( )

Test loading of ilObjStudyProgramme with ref_id.

@depends testCreation

Definition at line 118 of file ilObjStudyProgrammeTest.php.

119 {
120 $loaded = new ilObjStudyProgramme($this->root_object_ref_id);
121 $orig = $this->root_object;
122
123 $this->assertNotNull($loaded);
124 $this->assertGreaterThan(0, $loaded->getId());
125 $this->assertEquals($orig->getId(), $loaded->getId());
126 $this->assertEquals(
127 $orig->getLastChange()->get(IL_CAL_DATETIME),
128 $loaded->getLastChange()->get(IL_CAL_DATETIME)
129 );
130 $this->assertEquals($orig->getPoints(), $loaded->getPoints());
131 $this->assertEquals($orig->getLPMode(), $loaded->getLPMode());
132 $this->assertEquals($orig->getStatus(), $loaded->getStatus());
133 }

References IL_CAL_DATETIME.

◆ testMoveTo()

ilObjStudyProgrammeTest::testMoveTo ( )

Test on moveTo.

Definition at line 500 of file ilObjStudyProgrammeTest.php.

501 {
502 $this->createSmallTree();
503 $children = $this->root_object->getChildren();
504 $child_l = $children[0];
505 $child_r = $children[1];
506 $child_m = $children[2];
507
508 $child_r->moveTo($child_l);
509
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());
514
515 // test recursive moving
516 $this->assertEquals(1, $child_m->getAmountOfChildren());
517
518 $child_m->moveTo($child_r);
519
520 $m_children = $child_m->getChildren();
521 $first_third_node = $m_children[0];
522
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());
528
529 $this->assertEquals(1, $this->root_object->getAmountOfChildren());
530 $this->assertEquals(3, count(ilObjStudyProgramme::getAllChildren($child_l->getRefId())));
531 }
static getAllChildren($a_ref_id)
Get a list of all ilObjStudyProgrammes in the subtree starting at $a_ref_id.

References createSmallTree(), and ilObjStudyProgramme\getAllChildren().

+ Here is the call graph for this function:

◆ testRemoveLeaf()

ilObjStudyProgrammeTest::testRemoveLeaf ( )

Test on removeLead.

@depends testAddLeaf

Definition at line 446 of file ilObjStudyProgrammeTest.php.

447 {
448 $mock_leaf = new ilStudyProgrammeLeafMock();
449 $this->root_object->addLeaf($mock_leaf);
450
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()");
454
455 $lp_children = $this->root_object->getLPChildren();
456 $this->assertEquals(0, count($lp_children));
457 }

◆ testRemoveNode()

ilObjStudyProgrammeTest::testRemoveNode ( )

Test on removeNode.

@depends testTreeCreation

Definition at line 379 of file ilObjStudyProgrammeTest.php.

380 {
381 $this->createSmallTree();
382
383 $children = $this->root_object->getChildren();
384 $child = $children[0];
385 $this->root_object->removeNode($child);
386
387 // Is not in tree anymore...
388 $raised = false;
389 try {
390 $child->getParent();
391 } catch (ilStudyProgrammeTreeException $e) {
392 $raised = true;
393 }
394 $this->assertTrue($raised, "Child does not raise on getParent after it is removed.");
395
396 $this->assertEquals(2, $this->root_object->getAmountOfChildren());
397
398 // Can't be removed a second time...
399 $raised = false;
400 try {
401 $this->root_object->removeNode($child);
402 } catch (ilStudyProgrammeTreeException $e) {
403 $raised = true;
404 }
405 $this->assertTrue($raised, "Child can be removed two times.");
406 }

References createSmallTree().

+ Here is the call graph for this function:

◆ testSettings()

ilObjStudyProgrammeTest::testSettings ( )

Test tings on ilObjStudyProgramme.

@depends testCreation

Definition at line 167 of file ilObjStudyProgrammeTest.php.

168 {
169 $obj = ilObjStudyProgramme::getInstanceByRefId($this->root_object_ref_id);
170
171 $obj->setPoints(10);
172 $obj->setStatus(ilStudyProgramme::STATUS_ACTIVE);
173 $obj->update();
174
175 $obj = ilObjStudyProgramme::getInstanceByRefId($this->root_object_ref_id);
176
177 $this->assertEquals(10, $obj->getPoints());
178 $this->assertEquals(ilStudyProgramme::STATUS_ACTIVE, $obj->getStatus());
179
180 $midnight = strtotime("today midnight");
181 $this->assertGreaterThan($midnight, $obj->getLastChange()->getUnixTime());
182 }

References ilObjStudyProgramme\getInstanceByRefId(), and ilStudyProgramme\STATUS_ACTIVE.

+ Here is the call graph for this function:

◆ testTreeCreation()

ilObjStudyProgrammeTest::testTreeCreation ( )

Test creating a small tree.

@depends testCreation

Definition at line 218 of file ilObjStudyProgrammeTest.php.

219 {
220 $this->createSmallTree();
221 $this->assertEquals(3, $this->root_object->getAmountOfChildren());
222 }

References createSmallTree().

+ Here is the call graph for this function:

◆ testTreeDepth()

ilObjStudyProgrammeTest::testTreeDepth ( )

Test getDepth on ilObjStudyProgramme.

@depends testTreeCreation

Definition at line 289 of file ilObjStudyProgrammeTest.php.

290 {
291 $this->createSmallTree();
292 $children = $this->root_object->getChildren();
293
294 $child = $children[0];
295
296 $this->assertEquals(1, $child->getDepth());
297 }

References createSmallTree().

+ Here is the call graph for this function:

◆ testTreeGetChildren()

ilObjStudyProgrammeTest::testTreeGetChildren ( )

Test function to get children or information about them.

@depends testTreeCreation @depends testGetInstanceByRefId

Definition at line 230 of file ilObjStudyProgrammeTest.php.

231 {
232 $this->createSmallTree();
233
234 $children = $this->root_object->getChildren();
235 $this->assertEquals(3, count($children), "getChildren()");
236
237 $children = ilObjStudyProgramme::getAllChildren($this->root_object_ref_id);
238 $this->assertEquals(4, count($children), "ilObjStudyProgramme::getAllChildren(" . $this->root_object_ref_id . ")");
239
240 $this->assertTrue($this->root_object->hasChildren(), "hasChildren()");
241 $this->assertEquals(3, $this->root_object->getAmountOfChildren(), "getAmountOfChildren()");
242
243 $this->assertFalse($children[0]->hasChildren(), "hasChildren()");
244 $this->assertEquals(0, $children[0]->getAmountOfChildren(), "getAmountOfChildren()");
245 $this->assertEquals(0, count($children[0]->getChildren()));
246 }

References createSmallTree(), and ilObjStudyProgramme\getAllChildren().

+ Here is the call graph for this function:

◆ testTreeGetParent()

ilObjStudyProgrammeTest::testTreeGetParent ( )

Test getParent on ilObjStudyProgramme.

@depends testTreeCreation

Definition at line 253 of file ilObjStudyProgrammeTest.php.

254 {
255 $this->createSmallTree();
256 $children = $this->root_object->getChildren();
257
258 $child = $children[0];
259 $this->assertNotNull($child->getParent());
260 $this->assertNull($this->root_object->getParent());
261 }

References createSmallTree().

+ Here is the call graph for this function:

◆ testTreeGetParents()

ilObjStudyProgrammeTest::testTreeGetParents ( )

@depends testTreeCreation

Definition at line 266 of file ilObjStudyProgrammeTest.php.

267 {
268 $this->createSmallTree();
270 $children = $this->root_object->getChildren();
271 $children[0]->addNode($node3);
272
273 $parents = $node3->getParents();
274 $parent_ids = array_map(function ($node) {
275 return $node->getId();
276 }, $parents);
277 $parent_ids_expected = array( $this->root_object->getId()
278 , $children[0]->getId()
279 );
280
281 $this->assertEquals($parent_ids_expected, $parent_ids);
282 }

References ilObjStudyProgramme\createInstance(), and createSmallTree().

+ Here is the call graph for this function:

◆ testTreeGetRoot()

ilObjStudyProgrammeTest::testTreeGetRoot ( )

Test getRoot on ilObjStudyProgramme.

@depends testTreeCreation

Definition at line 304 of file ilObjStudyProgrammeTest.php.

305 {
306 $this->createSmallTree();
307 $children = $this->root_object->getChildren();
308 $child = $children[0];
309
310 $this->assertEquals($this->root_object->getId(), $child->getRoot()->getId());
311 }

References createSmallTree().

+ Here is the call graph for this function:

Field Documentation

◆ $backupGlobals

ilObjStudyProgrammeTest::$backupGlobals = false
protected

Definition at line 37 of file ilObjStudyProgrammeTest.php.


The documentation for this class was generated from the following file: