ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilIndividualAssessmentMembersTest.php
Go to the documentation of this file.
1 <?php
2 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMembers.php';
3 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMember.php';
4 require_once 'Modules/IndividualAssessment/classes/Members/class.ilIndividualAssessmentMembersStorageDB.php';
5 require_once 'Modules/IndividualAssessment/classes/Settings/class.ilIndividualAssessmentSettings.php';
6 require_once 'Modules/IndividualAssessment/interfaces/AccessControl/interface.IndividualAssessmentAccessHandler.php';
7 require_once 'Modules/IndividualAssessment/interfaces/Notification/interface.ilIndividualAssessmentNotificator.php';
8 
10 {
11  public function setMemberRecords(array $records)
12  {
13  $this->member_records = $records;
14  }
15 }
16 
22 {
23  public static $iass;
24  public static $created_users = array();
25 
26  public function setUp()
27  {
28  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
29  ilUnitUtil::performInitialisation();
30  }
31 
32  public function createUser()
33  {
34  $user = new ilObjUser;
35  $user->setFirstname('iass_test_firstname' . (count(self::$created_users) + time()));
36  $user->setLastname('iass_test_lastname' . (count(self::$created_users) + time()));
37  $user->setLogin('iass_tesst_login' . (count(self::$created_users) + time()));
38  $user->create();
39  $user->saveAsNew();
40  self::$created_users[] = $user;
41  return $user;
42  }
43 
44  protected function compareMembersUsrList($members, $usr_list)
45  {
46  $usr_it = array();
47 
48 
49  foreach ($members as $member_id => $member_data) {
51  $usr_it[] = $member_id;
52  $this->assertTrue(isset($usr_list[$member_id]));
53  }
54  return;
55  foreach ($usr_list as $usr_id => $usr) {
56  $this->assertTrue($members->userAllreadyMember($usr));
57  }
58  $this->assertEquals(count($usr_it), count($usr_list));
59  }
60 
61  protected function rbacHandlerMock()
62  {
63  return $this->createMock('IndividualAssessmentAccessHandler');
64  }
65 
66  protected function notificaterMock()
67  {
68  return $this->createMock('ilIndividualAssessmentNotificator');
69  }
70 
71  public function test_init_iass()
72  {
74  $iass ->setTitle("iass_test");
75  $iass ->setDescription("iass_test_desc");
76  $iass ->setId(100000000);
77  global $ilDB;
78  $storage = new ilIndividualAssessmentMembersStorageDB($ilDB);
79  return array($iass,$storage);
80  }
81 
85  public function test_create_members($args)
86  {
87  $iass = $args[0];
88  $storage = $args[1];
89  $members = $storage->loadMembers($iass);
90 
91  $usr_1 = $this->createUser();
92  $usr_2 = $this->createUser();
93 
94  $usrs = array($usr_1->getId() => $usr_1,$usr_2->getId() => $usr_2);
95  $members = $members->withAdditionalUser($usr_1)->withAdditionalUser($usr_2);
96  $members->updateStorageAndRBAC($storage, $this->rbacHandlerMock());
97  $this->compareMembersUsrList($members, $usrs);
98 
99  return array($usrs,$iass,$storage);
100  }
101 
105  public function test_load_members($args)
106  {
107  $usrs = $args[0];
108  $iass = $args[1];
109  $storage = $args[2];
110  $members = $storage->loadMembers($iass);
111  $this->compareMembersUsrList($members, $usrs);
112  return array($usrs,$iass,$storage);
113  }
114 
118  public function test_load_member($args)
119  {
120  $usrs = $args[0];
121  $iass = $args[1];
122  $storage = $args[2];
123  foreach ($usrs as $usr_id => $usr) {
124  $member = $storage->loadMember($iass, $usr);
125  $this->assertEquals($usr_id, $member->id());
126  $this->assertEquals($member->record(), ilIndividualAssessmentSettings::DEF_RECORD_TEMPLATE);
127  $this->assertEquals($member->lastname(), $usr->getLastname());
128  $member = $member->withRecord("record_of" . $usr_id);
129  $storage->updateMember($member);
130  }
131  return array($usrs,$iass,$storage);
132  }
133 
137  public function test_reload_member($args)
138  {
139  $usrs = $args[0];
140  $iass = $args[1];
141  $storage = $args[2];
142  foreach ($usrs as $usr_id => $usr) {
143  $member = $storage->loadMember($iass, $usr);
144  $this->assertEquals($usr_id, $member->id());
145  $this->assertEquals($member->record(), "record_of" . $usr_id);
146  $this->assertEquals($member->lastname(), $usr->getLastname());
147  $member = $member->withRecord(ilIndividualAssessmentSettings::DEF_RECORD_TEMPLATE);
148  $storage->updateMember($member);
149  }
150  return array($usrs,$iass,$storage);
151  }
152 
156  public function test_remove_members($args)
157  {
158  $usrs = $args[0];
159  $iass = $args[1];
160  $storage = $args[2];
161  $new_usr = $this->createUser();
162  $members = $storage->loadMembers($iass)->withAdditionalUser($new_usr);
163  $members->updateStorageAndRBAC($storage, $this->rbacHandlerMock());
164  $members = $storage->loadMembers($iass);
165  $usrs[$new_usr->getId()] = $new_usr;
166  $this->compareMembersUsrList($members, $usrs);
167  $members->withoutPresentUser($new_usr)->updateStorageAndRBAC($storage, $this->rbacHandlerMock());
168  $members = $storage->loadMembers($iass);
169  unset($usrs[$new_usr->getId()]);
170  $this->compareMembersUsrList($members, $usrs);
171  return array($usrs,$iass,$storage);
172  }
173 
178  public function test_finalize_nongraded($args)
179  {
180  $usrs = $args[0];
181  $iass = $args[1];
182  $storage = $args[2];
183  $member = $storage->loadMember($iass, current($usrs))->withFinalized();
184  }
185 
189  public function test_finalize_graded($args)
190  {
191  $usrs = $args[0];
192  $iass = $args[1];
193  $storage = $args[2];
194  $storage->updateMember($storage->loadMember($iass, current($usrs))->withLPStatus(ilIndividualAssessmentMembers::LP_COMPLETED)->withFinalized());
195  $this->assertEquals($storage->loadMember($iass, current($usrs))->LPStatus(), ilIndividualAssessmentMembers::LP_COMPLETED);
196  $this->assertTrue($storage->loadMember($iass, current($usrs))->finalized());
197  return array($usrs,$iass,$storage);
198  }
199 
204  public function test_re_grade($args)
205  {
206  $usrs = $args[0];
207  $iass = $args[1];
208  $storage = $args[2];
209  $storage->loadMember($iass, current($usrs))->withLPStatus(ilIndividualAssessmentMembers::LP_COMPLETED);
210  }
211 
216  public function test_re_finalize($args)
217  {
218  $usrs = $args[0];
219  $iass = $args[1];
220  $storage = $args[2];
221  $storage->loadMember($iass, current($usrs))->withFinalized();
222  }
223 
224  public function test_withOnlyUsersByIds()
225  {
226  $obj = $this
227  ->getMockBuilder(\ilObjIndividualAssessment::class)
228  ->disableOriginalConstructor()
229  ->getMock();
230 
231  $members = new RiggedMembers($obj);
232 
233  $records = [1 => 1, 2 => 2, 3 => 3, 23 => 23, 42 => 42, 1337 => 1337];
234 
235  $members->setMemberRecords($records);
236 
237  $members = $members->withOnlyUsersByIds([3,42]);
238 
239  $this->assertEquals([3, 42], $members->membersIds());
240  }
241 
242  public function test_withAccessHandling()
243  {
244  $ah = $this
245  ->getMockBuilder(\ilOrgUnitPositionAndRBACAccessHandler::class)
246  ->setMethods(["filterUserIdsByRbacOrPositionOfCurrentUser", "checkRbacOrPositionPermissionAccess"])
247  ->getMock();
248 
249  $obj = $this
250  ->getMockBuilder(\ilObjIndividualAssessment::class)
251  ->disableOriginalConstructor()
252  ->setMethods(["getRefId"])
253  ->getMock();
254 
255  $members = $this
256  ->getMockBuilder(\ilIndividualAssessmentMembers::class)
257  ->setMethods(["withOnlyUsersByIds", "membersIds", "referencedObject"])
258  ->disableOriginalConstructor()
259  ->getMock();
260 
261  $ref_id = 1985;
262 
263  $obj->method("getRefId")->willReturn($ref_id);
264 
265  $user_ids = [1,2,3,23,42,1337];
266  $keep_user_ids = [3, 23];
267 
268  $members
269  ->expects($this->once())
270  ->method("membersIds")
271  ->willReturn($user_ids);
272 
273  $members
274  ->expects($this->once())
275  ->method("referencedObject")
276  ->willReturn($obj);
277 
278  $ah
279  ->expects($this->once())
280  ->method("filterUserIdsByRbacOrPositionOfCurrentUser")
281  ->with("read_learning_progress", "read_learning_progress", $ref_id, $user_ids)
282  ->willReturn($keep_user_ids);
283 
284  $members
285  ->expects($this->once())
286  ->method("withOnlyUsersByIds")
287  ->with($keep_user_ids);
288 
289  $members->withAccessHandling($ah);
290  }
291 
292  public static function tearDownAfterClass()
293  {
294  global $ilDB;
295  foreach (self::$created_users as $user) {
296  $user->delete;
297  $ilDB->manipulate('DELETE FROM iass_settings WHERE obj_id = 100000000');
298  $ilDB->manipulate('DELETE FROM iass_info_settings WHERE obj_id = 100000000');
299  $ilDB->manipulate('DELETE FROM iass_members WHERE obj_id = 100000000');
300  }
301  }
302 }
For the purpose of streamlining the grading and learning-process status definition outside of tests...
test_finalize_nongraded($args)
test_remove_members ilIndividualAssessmentException
$records
Definition: simple_test.php:22
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$user
Definition: migrateto20.php:57
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