ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStudyProgrammeProgressTreeTest Class Reference
+ Inheritance diagram for ilStudyProgrammeProgressTreeTest:
+ Collaboration diagram for ilStudyProgrammeProgressTreeTest:

Public Member Functions

 setUp ()
 
 testPGSTreeCreation ()
 
 testPGSTreeZipperNav ()
 
 testPGSTreeZipperManipulation ()
 
 testPGSTreeZipperManipulateAll ()
 

Protected Member Functions

 build (array $data, $node_id)
 

Detailed Description

Definition at line 41 of file ilStudyProgrammeProgressTreeTest.php.

Member Function Documentation

◆ build()

ilStudyProgrammeProgressTreeTest::build ( array  $data,
  $node_id 
)
protected

Definition at line 43 of file ilStudyProgrammeProgressTreeTest.php.

References ILIAS\StudyProgramme\Assignment\Node\$subnodes.

43  : Node
44  {
45  $subnodes = [];
46  foreach ($data[$node_id] as $subnode_id) {
47  $subnodes[] = $this->build($data, $subnode_id);
48  }
49  return (new NodeMock($node_id))->setSubnodes($subnodes);
50  }

◆ setUp()

ilStudyProgrammeProgressTreeTest::setUp ( )

Definition at line 52 of file ilStudyProgrammeProgressTreeTest.php.

References $data.

52  : void
53  {
54  $data = [
55  'top' => ['1.2', '1.1'],
56  '1.1' => [],
57  '1.2' => ['1.2.1', '1.2.2'],
58  '1.2.1' => ['1.2.1.1'],
59  '1.2.2' => [],
60  '1.2.1.1' => []
61  ];
62 
63  $this->topnode = $this->build($data, 'top');
64  }

◆ testPGSTreeCreation()

ilStudyProgrammeProgressTreeTest::testPGSTreeCreation ( )

Definition at line 66 of file ilStudyProgrammeProgressTreeTest.php.

66  : void
67  {
68  $n = $this->topnode;
69  $this->assertEquals($n->getId(), 'top');
70  $this->assertInstanceOf(Node::class, $n->getSubnode('1.1'));
71 
72  $this->assertEquals(
73  ['top', '1.2', '1.2.2'],
74  $n->getSubnode('1.2')->getSubnode('1.2.2')->getPath()
75  );
76 
77  $this->assertEquals(
78  ['top', '1.2', '1.2.1'],
79  $n->findSubnodePath('1.2.1')
80  );
81  }

◆ testPGSTreeZipperManipulateAll()

ilStudyProgrammeProgressTreeTest::testPGSTreeZipperManipulateAll ( )

Definition at line 126 of file ilStudyProgrammeProgressTreeTest.php.

126  : void
127  {
128  $zipper = new Zipper($this->topnode);
129  $modified = $zipper
130  ->modifyAll(fn ($n) => $n->withScore(count($n->getSubnodes())))
131  ->getRoot();
132 
133  $this->assertEquals(2, $modified->getScore());
134  $this->assertEquals(0, $modified->getSubnode('1.1')->getScore());
135  $this->assertEquals(2, $modified->getSubnode('1.2')->getScore());
136  $this->assertEquals(1, $modified->getSubnode('1.2')->getSubnode('1.2.1')->getScore());
137  $this->assertEquals(0, $modified->getSubnode('1.2')->getSubnode('1.2.1')->getSubnode('1.2.1.1')->getScore());
138  $this->assertEquals(0, $modified->getSubnode('1.2')->getSubnode('1.2.2')->getScore());
139  }

◆ testPGSTreeZipperManipulation()

ilStudyProgrammeProgressTreeTest::testPGSTreeZipperManipulation ( )

Definition at line 97 of file ilStudyProgrammeProgressTreeTest.php.

References $path.

97  : void
98  {
99  $zipper = new Zipper($this->topnode);
100 
101  $path = $this->topnode->findSubnodePath('1.2.1');
102  $modified = $zipper
103  ->toPath($path)->modifyFocus(fn ($n) => $n->withScore(7))
104  ->toParent()->modifyFocus(fn ($n) => $n->withScore(6))
105  ->getRoot();
106 
107  $zipper = new Zipper($modified);
108  $other_path = $this->topnode->findSubnodePath('1.1');
109  $modified = $zipper
110  ->toPath($other_path)->modifyFocus(fn ($n) => $n->withScore(8))
111  ->getRoot();
112  $this->assertEquals(7, $modified->getSubnode('1.2')->getSubnode('1.2.1')->getScore());
113  $this->assertEquals(6, $modified->getSubnode('1.2')->getScore());
114  $this->assertEquals(8, $modified->getSubnode('1.1')->getScore());
115 
116  //should not change others...
117  $zipper = new Zipper($modified);
118  $modified = $zipper
119  ->toPath($path)->modifyFocus(fn ($n) => $n->withScore(17))
120  ->getRoot();
121  $this->assertEquals(17, $modified->getSubnode('1.2')->getSubnode('1.2.1')->getScore());
122  $this->assertEquals(6, $modified->getSubnode('1.2')->getScore());
123  $this->assertEquals(8, $modified->getSubnode('1.1')->getScore());
124  }
$path
Definition: ltiservices.php:32

◆ testPGSTreeZipperNav()

ilStudyProgrammeProgressTreeTest::testPGSTreeZipperNav ( )

Definition at line 83 of file ilStudyProgrammeProgressTreeTest.php.

83  : void
84  {
85  $zipper = new Zipper($this->topnode);
86  $this->assertInstanceOf(Zipper::class, $zipper->toChild('1.1'));
87  $this->assertInstanceOf(
88  Zipper::class,
89  $zipper->toPath($this->topnode->findSubnodePath('1.2.1'))->toParent()
90  );
91  $this->assertInstanceOf(
92  Node::class,
93  $zipper->toPath($this->topnode->findSubnodePath('1.2.1'))->getRoot()
94  );
95  }

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