ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilIndividualAssessmentMembersTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMembers.php';
6 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMember.php';
7 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMembersStorageDB.php';
8 require_once 'Modules/IndividualAssessment/classes/Settings/class.ilIndividualAssessmentSettings.php';
9 require_once 'Modules/IndividualAssessment/interfaces/AccessControl/interface.IndividualAssessmentAccessHandler.php';
10 require_once 'Modules/IndividualAssessment/interfaces/Notification/interface.ilIndividualAssessmentNotificator.php';
11 
13 {
14  public function setMemberRecords(array $records)
15  {
16  $this->member_records = $records;
17  }
18 }
19 
25 {
26  public static $iass;
27  public static $created_users = array();
28 
29  public function setUp() : void
30  {
31  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
32  ilUnitUtil::performInitialisation();
33  }
34 
35  public function createUser()
36  {
37  $user = new ilObjUser;
38  $user->setFirstname('iass_test_firstname' . (count(self::$created_users) + time()));
39  $user->setLastname('iass_test_lastname' . (count(self::$created_users) + time()));
40  $user->setLogin('iass_tesst_login' . (count(self::$created_users) + time()));
41  $user->create();
42  $user->saveAsNew();
43  self::$created_users[] = $user;
44  return $user;
45  }
46 
47  protected function compareMembersUsrList($members, $usr_list)
48  {
49  $usr_it = array();
50 
51 
52  foreach ($members as $member_id => $member_data) {
53  $this->assertEquals($member_data[ilIndividualAssessmentMembers::FIELD_RECORD], ilIndividualAssessmentSettings::DEF_RECORD_TEMPLATE);
54  $usr_it[] = $member_id;
55  $this->assertTrue(isset($usr_list[$member_id]));
56  }
57  return;
58  foreach ($usr_list as $usr_id => $usr) {
59  $this->assertTrue($members->userAllreadyMember($usr));
60  }
61  $this->assertEquals(count($usr_it), count($usr_list));
62  }
63 
64  protected function rbacHandlerMock()
65  {
66  return $this->createMock('IndividualAssessmentAccessHandler');
67  }
68 
69  protected function notificaterMock()
70  {
71  return $this->createMock('ilIndividualAssessmentNotificator');
72  }
73 
74  public function test_init_iass()
75  {
77  $iass ->setTitle("iass_test");
78  $iass ->setDescription("iass_test_desc");
79  $iass ->setId(100000000);
80  global $ilDB;
81  $storage = new ilIndividualAssessmentMembersStorageDB($ilDB);
82  return array($iass,$storage);
83  }
84 
88  public function test_create_members($args)
89  {
90  $iass = $args[0];
91  $storage = $args[1];
92  $members = $storage->loadMembers($iass);
93 
94  $usr_1 = $this->createUser();
95  $usr_2 = $this->createUser();
96 
97  $usrs = array($usr_1->getId() => $usr_1,$usr_2->getId() => $usr_2);
98  $members = $members->withAdditionalUser($usr_1)->withAdditionalUser($usr_2);
99  $members->updateStorageAndRBAC($storage, $this->rbacHandlerMock());
100  $this->compareMembersUsrList($members, $usrs);
101 
102  return array($usrs,$iass,$storage);
103  }
104 
108  public function test_load_members($args)
109  {
110  $usrs = $args[0];
111  $iass = $args[1];
112  $storage = $args[2];
113  $members = $storage->loadMembers($iass);
114  $this->compareMembersUsrList($members, $usrs);
115  return array($usrs,$iass,$storage);
116  }
117 
121  public function test_load_member($args)
122  {
123  $usrs = $args[0];
124  $iass = $args[1];
125  $storage = $args[2];
126  foreach ($usrs as $usr_id => $usr) {
127  $member = $storage->loadMember($iass, $usr);
128  $this->assertEquals($usr_id, $member->id());
129  $this->assertEquals($member->record(), ilIndividualAssessmentSettings::DEF_RECORD_TEMPLATE);
130  $this->assertEquals($member->lastname(), $usr->getLastname());
131  $member = $member->withRecord("record_of" . $usr_id);
132  $storage->updateMember($member);
133  }
134  return array($usrs,$iass,$storage);
135  }
136 
140  public function test_reload_member($args)
141  {
142  $usrs = $args[0];
143  $iass = $args[1];
144  $storage = $args[2];
145  foreach ($usrs as $usr_id => $usr) {
146  $member = $storage->loadMember($iass, $usr);
147  $this->assertEquals($usr_id, $member->id());
148  $this->assertEquals($member->record(), "record_of" . $usr_id);
149  $this->assertEquals($member->lastname(), $usr->getLastname());
150  $member = $member->withRecord(ilIndividualAssessmentSettings::DEF_RECORD_TEMPLATE);
151  $storage->updateMember($member);
152  }
153  return array($usrs,$iass,$storage);
154  }
155 
159  public function test_remove_members($args)
160  {
161  $usrs = $args[0];
162  $iass = $args[1];
163  $storage = $args[2];
164  $new_usr = $this->createUser();
165  $members = $storage->loadMembers($iass)->withAdditionalUser($new_usr);
166  $members->updateStorageAndRBAC($storage, $this->rbacHandlerMock());
167  $members = $storage->loadMembers($iass);
168  $usrs[$new_usr->getId()] = $new_usr;
169  $this->compareMembersUsrList($members, $usrs);
170  $members->withoutPresentUser($new_usr)->updateStorageAndRBAC($storage, $this->rbacHandlerMock());
171  $members = $storage->loadMembers($iass);
172  unset($usrs[$new_usr->getId()]);
173  $this->compareMembersUsrList($members, $usrs);
174  return array($usrs,$iass,$storage);
175  }
176 
181  public function test_finalize_nongraded($args)
182  {
183  $usrs = $args[0];
184  $iass = $args[1];
185  $storage = $args[2];
186  $member = $storage->loadMember($iass, current($usrs))->withFinalized();
187  }
188 
192  public function test_finalize_graded($args)
193  {
194  $usrs = $args[0];
195  $iass = $args[1];
196  $storage = $args[2];
197  $storage->updateMember($storage->loadMember($iass, current($usrs))->withLPStatus(ilIndividualAssessmentMembers::LP_COMPLETED)->withFinalized());
198  $this->assertEquals($storage->loadMember($iass, current($usrs))->LPStatus(), ilIndividualAssessmentMembers::LP_COMPLETED);
199  $this->assertTrue($storage->loadMember($iass, current($usrs))->finalized());
200  return array($usrs,$iass,$storage);
201  }
202 
207  public function test_re_grade($args)
208  {
209  $usrs = $args[0];
210  $iass = $args[1];
211  $storage = $args[2];
212  $storage->loadMember($iass, current($usrs))->withLPStatus(ilIndividualAssessmentMembers::LP_COMPLETED);
213  }
214 
219  public function test_re_finalize($args)
220  {
221  $usrs = $args[0];
222  $iass = $args[1];
223  $storage = $args[2];
224  $storage->loadMember($iass, current($usrs))->withFinalized();
225  }
226 
227  public function test_withOnlyUsersByIds()
228  {
229  $obj = $this
230  ->getMockBuilder(\ilObjIndividualAssessment::class)
231  ->disableOriginalConstructor()
232  ->getMock();
233 
234  $members = new RiggedMembers($obj);
235 
236  $records = [1 => 1, 2 => 2, 3 => 3, 23 => 23, 42 => 42, 1337 => 1337];
237 
238  $members->setMemberRecords($records);
239 
240  $members = $members->withOnlyUsersByIds([3,42]);
241 
242  $this->assertEquals([3, 42], $members->membersIds());
243  }
244 
245  public function test_withAccessHandling()
246  {
247  $ah = $this
248  ->getMockBuilder(\ilOrgUnitPositionAndRBACAccessHandler::class)
249  ->setMethods(["filterUserIdsByRbacOrPositionOfCurrentUser", "checkRbacOrPositionPermissionAccess"])
250  ->getMock();
251 
252  $obj = $this
253  ->getMockBuilder(\ilObjIndividualAssessment::class)
254  ->disableOriginalConstructor()
255  ->setMethods(["getRefId"])
256  ->getMock();
257 
258  $members = $this
259  ->getMockBuilder(\ilIndividualAssessmentMembers::class)
260  ->setMethods(["withOnlyUsersByIds", "membersIds", "referencedObject"])
261  ->disableOriginalConstructor()
262  ->getMock();
263 
264  $ref_id = 1985;
265 
266  $obj->method("getRefId")->willReturn($ref_id);
267 
268  $user_ids = [1,2,3,23,42,1337];
269  $keep_user_ids = [3, 23];
270 
271  $members
272  ->expects($this->once())
273  ->method("membersIds")
274  ->willReturn($user_ids);
275 
276  $members
277  ->expects($this->once())
278  ->method("referencedObject")
279  ->willReturn($obj);
280 
281  $ah
282  ->expects($this->once())
283  ->method("filterUserIdsByRbacOrPositionOfCurrentUser")
284  ->with("read_learning_progress", "read_learning_progress", $ref_id, $user_ids)
285  ->willReturn($keep_user_ids);
286 
287  $members
288  ->expects($this->once())
289  ->method("withOnlyUsersByIds")
290  ->with($keep_user_ids);
291 
292  $members->withAccessHandling($ah);
293  }
294 
295  public static function tearDownAfterClass() : void
296  {
297  global $ilDB;
298  foreach (self::$created_users as $user) {
299  $user->delete;
300  $ilDB->manipulate('DELETE FROM iass_settings WHERE obj_id = 100000000');
301  $ilDB->manipulate('DELETE FROM iass_info_settings WHERE obj_id = 100000000');
302  $ilDB->manipulate('DELETE FROM iass_members WHERE obj_id = 100000000');
303  }
304  }
305 }
For the purpose of streamlining the grading and learning-process status definition outside of tests...
test_finalize_nongraded($args)
test_remove_members ilIndividualAssessmentException
global $ilDB
test_re_grade($args)
test_finalize_graded ilIndividualAssessmentException
Member administration related logic, add and remove members, get the list of all members, etc.
test_re_finalize($args)
test_finalize_graded ilIndividualAssessmentException