ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilStudyProgrammeUserAssignmentTest Class Reference

TestCase for the assignment of users to a programme. More...

+ Inheritance diagram for ilStudyProgrammeUserAssignmentTest:
+ Collaboration diagram for ilStudyProgrammeUserAssignmentTest:

Public Member Functions

 testNoAssignmentWhenDraft ()
 ilException More...
 
 testNoAssignmentWhenOutdated ()
 ilException More...
 
 testNoAssignementWhenNotCreated ()
 ilException More...
 
 testUserId ()
 
 testHasAssignmentOf ()
 
 testGetAmountOfAssignments ()
 
 testGetAssignmentsOf ()
 
 testRemoveOnRootNodeOnly1 ()
 ilException More...
 
 testRemoveOnRootNodeOnly2 ()
 ilException More...
 
 testRemoveAssignment1 ()
 
 testRemoveAssignment2 ()
 
 testGetAssignments ()
 
 testDeleteOfProgrammeRemovesEntriesInPrgUsrAssignment ()
 
 testDeassignRemovesEntriesInPrgUsrAssignment ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 
 newUser ()
 

Protected Attributes

 $backupGlobals = FALSE
 

Detailed Description

TestCase for the assignment of users to a programme.

Author
Michael Herren mh@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Richard Klees richa.nosp@m.rd.k.nosp@m.lees@.nosp@m.conc.nosp@m.epts-.nosp@m.and-.nosp@m.train.nosp@m.ing..nosp@m.de
Version
1.0.0

Definition at line 14 of file ilStudyProgrammeUserAssignmentTest.php.

Member Function Documentation

◆ newUser()

◆ setUp()

ilStudyProgrammeUserAssignmentTest::setUp ( )
protected

Definition at line 17 of file ilStudyProgrammeUserAssignmentTest.php.

References ilObjStudyProgramme\createInstance().

17  {
18  PHPUnit_Framework_Error_Deprecated::$enabled = FALSE;
19 
20  require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
21 
22  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
23  ilUnitUtil::performInitialisation();
24 
26  $this->root->putInTree(ROOT_FOLDER_ID);
27  $this->root->object_factory = new ilObjectFactoryWrapperMock();
28 
29  $this->node1 = ilObjStudyProgramme::createInstance();
30  $this->node2 = ilObjStudyProgramme::createInstance();
31 
32  $this->leaf1 = new ilStudyProgrammeLeafMock();
33  $this->leaf2 = new ilStudyProgrammeLeafMock();
34 
35  $this->root->addNode($this->node1);
36  $this->root->addNode($this->node2);
37  $this->node1->addLeaf($this->leaf1);
38  $this->node2->addLeaf($this->leaf2);
39 
40  global $tree;
41  $this->tree = $tree;
42  }
Mock classes for tests.
Definition: mocks.php:20
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
Mock for object factory.
Definition: mocks.php:65
+ Here is the call graph for this function:

◆ tearDown()

ilStudyProgrammeUserAssignmentTest::tearDown ( )
protected

Definition at line 44 of file ilStudyProgrammeUserAssignmentTest.php.

44  {
45  if ($this->root) {
46  $this->root->delete();
47  }
48  }

◆ testDeassignRemovesEntriesInPrgUsrAssignment()

ilStudyProgrammeUserAssignmentTest::testDeassignRemovesEntriesInPrgUsrAssignment ( )

Definition at line 251 of file ilStudyProgrammeUserAssignmentTest.php.

References $ilDB, $res, newUser(), ilStudyProgrammeAssignment\returnDbTableName(), and ilStudyProgramme\STATUS_ACTIVE.

251  {
252  $user = $this->newUser();
253  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
254  $ass1 = $this->root->assignUser($user->getId());
255  $ass1->deassign();
256 
257  global $ilDB;
258  $res = $ilDB->query( "SELECT COUNT(*) cnt "
260  ." WHERE id = ".$ass1->getId()
261  );
262  $rec = $ilDB->fetchAssoc($res);
263  $this->assertEquals(0, $rec["cnt"]);
264  }
global $ilDB
+ Here is the call graph for this function:

◆ testDeleteOfProgrammeRemovesEntriesInPrgUsrAssignment()

ilStudyProgrammeUserAssignmentTest::testDeleteOfProgrammeRemovesEntriesInPrgUsrAssignment ( )

Definition at line 233 of file ilStudyProgrammeUserAssignmentTest.php.

References $ilDB, $res, newUser(), ilStudyProgrammeAssignment\returnDbTableName(), and ilStudyProgramme\STATUS_ACTIVE.

233  {
234  $user1 = $this->newUser();
235  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
236  $ass = $this->root->assignUser($user1->getId());
237 
238  $root_id = $this->root->getId();
239  $this->root->delete();
240  $this->root = null;
241 
242  global $ilDB;
243  $res = $ilDB->query( "SELECT COUNT(*) cnt "
245  ." WHERE root_prg_id = ".$root_id
246  );
247  $rec = $ilDB->fetchAssoc($res);
248  $this->assertEquals(0, $rec["cnt"]);
249  }
global $ilDB
+ Here is the call graph for this function:

◆ testGetAmountOfAssignments()

ilStudyProgrammeUserAssignmentTest::testGetAmountOfAssignments ( )

Definition at line 109 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

109  {
110  $user1 = $this->newUser();
111  $user2 = $this->newUser();
112  $user3 = $this->newUser();
113  $user4 = $this->newUser();
114 
115  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
116  $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE);
117  $this->node2->setStatus(ilStudyProgramme::STATUS_ACTIVE);
118 
119  $this->assertEquals(0, $this->root->getAmountOfAssignmentsOf($user1->getId()));
120 
121  $this->root->assignUser($user2->getId());
122  $this->assertEquals(1, $this->root->getAmountOfAssignmentsOf($user2->getId()));
123  $this->assertEquals(1, $this->node1->getAmountOfAssignmentsOf($user2->getId()));
124  $this->assertEquals(1, $this->node2->getAmountOfAssignmentsOf($user2->getId()));
125 
126  $this->root->assignUser($user3->getId());
127  $this->root->assignUser($user3->getId());
128  $this->assertEquals(2, $this->root->getAmountOfAssignmentsOf($user3->getId()));
129  $this->assertEquals(2, $this->node1->getAmountOfAssignmentsOf($user3->getId()));
130  $this->assertEquals(2, $this->node2->getAmountOfAssignmentsOf($user3->getId()));
131 
132  $this->root->assignUser($user4->getId());
133  $this->node1->assignUser($user4->getId());
134  $this->assertEquals(1, $this->root->getAmountOfAssignmentsOf($user4->getId()));
135  $this->assertEquals(2, $this->node1->getAmountOfAssignmentsOf($user4->getId()));
136  $this->assertEquals(1, $this->node2->getAmountOfAssignmentsOf($user4->getId()));
137  }
+ Here is the call graph for this function:

◆ testGetAssignments()

ilStudyProgrammeUserAssignmentTest::testGetAssignments ( )

Definition at line 215 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

215  {
216  $user1 = $this->newUser();
217  $user2 = $this->newUser();
218 
219  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
220  $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE);
221 
222  $ass1 = $this->root->assignUser($user1->getId());
223  $ass2 = $this->node1->assignUser($user2->getId());
224 
225  $asses = $this->node1->getAssignments();
226  $ass_ids = array_map(function($ass) {
227  return $ass->getId();
228  }, $asses);
229  $this->assertContains($ass1->getId(), $ass_ids);
230  $this->assertContains($ass2->getId(), $ass_ids);
231  }
+ Here is the call graph for this function:

◆ testGetAssignmentsOf()

ilStudyProgrammeUserAssignmentTest::testGetAssignmentsOf ( )

Definition at line 139 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

139  {
140  $user1 = $this->newUser();
141  $user2 = $this->newUser();
142 
143  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
144  $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE);
145 
146  $this->assertEquals(0, count($this->root->getAssignmentsOf($user1->getId())));
147  $this->assertEquals(0, count($this->node1->getAssignmentsOf($user1->getId())));
148  $this->assertEquals(0, count($this->node2->getAssignmentsOf($user1->getId())));
149 
150  $this->root->assignUser($user2->getId());
151  $this->node1->assignUser($user2->getId());
152 
153  $root_ass = $this->root->getAssignmentsOf($user2->getId());
154  $node1_ass = $this->node1->getAssignmentsOf($user2->getId());
155  $node2_ass = $this->node2->getAssignmentsOf($user2->getId());
156 
157  $this->assertEquals(1, count($root_ass));
158  $this->assertEquals(2, count($node1_ass));
159  $this->assertEquals(1, count($node2_ass));
160 
161  $this->assertEquals($this->root->getId(), $root_ass[0]->getStudyProgramme()->getId());
162  $this->assertEquals($this->root->getId(), $node2_ass[0]->getStudyProgramme()->getId());
163 
164  $node1_ass_prg_ids = array_map(function($ass) {
165  return $ass->getStudyProgramme()->getId();
166  }, $node1_ass);
167  $this->assertContains($this->root->getId(), $node1_ass_prg_ids);
168  $this->assertContains($this->node1->getId(), $node1_ass_prg_ids);
169  }
+ Here is the call graph for this function:

◆ testHasAssignmentOf()

ilStudyProgrammeUserAssignmentTest::testHasAssignmentOf ( )

Definition at line 93 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

93  {
94  $user1 = $this->newUser();
95  $user2 = $this->newUser();
96 
97  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
98 
99  $this->root->assignUser($user1->getId());
100  $this->assertTrue($this->root->hasAssignmentOf($user1->getId()));
101  $this->assertTrue($this->node1->hasAssignmentOf($user1->getId()));
102  $this->assertTrue($this->node2->hasAssignmentOf($user1->getId()));
103 
104  $this->assertFalse($this->root->hasAssignmentOf($user2->getId()));
105  $this->assertFalse($this->node1->hasAssignmentOf($user2->getId()));
106  $this->assertFalse($this->node2->hasAssignmentOf($user2->getId()));
107  }
+ Here is the call graph for this function:

◆ testNoAssignementWhenNotCreated()

ilStudyProgrammeUserAssignmentTest::testNoAssignementWhenNotCreated ( )

ilException

Definition at line 80 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser().

80  {
81  $user = $this->newUser();
82  $prg = new ilObjStudyProgramme();
83  $prg->assignUser($user->getId());
84  }
Class ilObjStudyProgramme.
+ Here is the call graph for this function:

◆ testNoAssignmentWhenDraft()

ilStudyProgrammeUserAssignmentTest::testNoAssignmentWhenDraft ( )

ilException

Definition at line 60 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_DRAFT.

60  {
61  $user = $this->newUser();
62  $this->assertEquals(ilStudyProgramme::STATUS_DRAFT, $this->root->getStatus());
63  $this->root->assignUser($user->getId());
64  }
+ Here is the call graph for this function:

◆ testNoAssignmentWhenOutdated()

ilStudyProgrammeUserAssignmentTest::testNoAssignmentWhenOutdated ( )

ilException

Definition at line 69 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_OUTDATED.

69  {
70  $user = $this->newUser();
71 
72  $this->root->setStatus(ilStudyProgramme::STATUS_OUTDATED);
73  $this->assertEquals(ilStudyProgramme::STATUS_OUTDATED, $this->root->getStatus());
74  $this->root->assignUser($user->getId());
75  }
+ Here is the call graph for this function:

◆ testRemoveAssignment1()

ilStudyProgrammeUserAssignmentTest::testRemoveAssignment1 ( )

Definition at line 195 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

195  {
196  $user = $this->newUser();
197 
198  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
199 
200  $ass1 = $this->root->assignUser($user->getId());
201  $this->root->removeAssignment($ass1);
202  $this->assertFalse($this->root->hasAssignmentOf($user->getId()));
203  }
+ Here is the call graph for this function:

◆ testRemoveAssignment2()

ilStudyProgrammeUserAssignmentTest::testRemoveAssignment2 ( )

Definition at line 205 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

205  {
206  $user = $this->newUser();
207 
208  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
209 
210  $ass1 = $this->root->assignUser($user->getId());
211  $ass1->deassign();
212  $this->assertFalse($this->root->hasAssignmentOf($user->getId()));
213  }
+ Here is the call graph for this function:

◆ testRemoveOnRootNodeOnly1()

ilStudyProgrammeUserAssignmentTest::testRemoveOnRootNodeOnly1 ( )

ilException

Definition at line 174 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

174  {
175  $user = $this->newUser();
176 
177  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
178 
179  $ass1 = $this->root->assignUser($user->getId());
180  $this->node1->removeAssignment($ass1);
181  }
+ Here is the call graph for this function:

◆ testRemoveOnRootNodeOnly2()

ilStudyProgrammeUserAssignmentTest::testRemoveOnRootNodeOnly2 ( )

ilException

Definition at line 186 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

186  {
187  $user = $this->newUser();
188 
189  $this->node1->setStatus(ilStudyProgramme::STATUS_ACTIVE);
190 
191  $ass1 = $this->node1->assignUser($user->getId());
192  $this->root->removeAssignment($ass1);
193  }
+ Here is the call graph for this function:

◆ testUserId()

ilStudyProgrammeUserAssignmentTest::testUserId ( )

Definition at line 86 of file ilStudyProgrammeUserAssignmentTest.php.

References newUser(), and ilStudyProgramme\STATUS_ACTIVE.

86  {
87  $user1 = $this->newUser();
88  $this->root->setStatus(ilStudyProgramme::STATUS_ACTIVE);
89  $ass = $this->root->assignUser($user1->getId());
90  $this->assertEquals($user1->getId(), $ass->getUserId());
91  }
+ Here is the call graph for this function:

Field Documentation

◆ $backupGlobals

ilStudyProgrammeUserAssignmentTest::$backupGlobals = FALSE
protected

Definition at line 15 of file ilStudyProgrammeUserAssignmentTest.php.


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