ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ilForumNotificationTest Class Reference
+ Inheritance diagram for ilForumNotificationTest:
+ Collaboration diagram for ilForumNotificationTest:

Public Member Functions

 testConstruct ()
 
 testGetterAndSetter ()
 
 testIsAdminForceNotification ()
 
 testIsAdminForceNotificationFailed ()
 
 testIsUserToggleNotification ()
 
 testIsUserToggleNotificationFailed ()
 
 testInsertAdminForce ()
 
 testDeleteAdminForce ()
 
 testDeleteUserToggle ()
 
 testupdateUserToggle ()
 
 testCheckForumsExistsInsert ()
 
 testUpdate ()
 
 testDeleteNotificationAllUsers ()
 
 testRead ()
 
 testMergeThreadNotifications ()
 
 testExistsNotification ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Private Attributes

 $database
 
 $user
 
 $tree
 
Container $dic = null
 

Detailed Description

Definition at line 25 of file ilForumNotificationTest.php.

Member Function Documentation

◆ setUp()

ilForumNotificationTest::setUp ( )
protected

Definition at line 421 of file ilForumNotificationTest.php.

421 : void
422 {
423 global $DIC;
424
425 $this->dic = is_object($DIC) ? clone $DIC : $DIC;
426
427 $DIC = new Container();
428
429 $DIC['ilDB'] = ($this->database = $this->createMock(ilDBInterface::class));
430 $DIC['ilUser'] = ($this->user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock());
431 $DIC['ilObjDataCache'] = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
432 $DIC['tree'] = ($this->tree = $this->getMockBuilder(ilTree::class)->disableOriginalConstructor()->getMock());
433 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
global $DIC
Definition: feed.php:28

References $DIC, and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ tearDown()

ilForumNotificationTest::tearDown ( )
protected

Definition at line 435 of file ilForumNotificationTest.php.

435 : void
436 {
437 global $DIC;
438
440
441 parent::tearDown();
442 }

References $DIC, and $dic.

◆ testCheckForumsExistsInsert()

ilForumNotificationTest::testCheckForumsExistsInsert ( )

Definition at line 260 of file ilForumNotificationTest.php.

260 : void
261 {
262 $nodeData = [];
263 $userId = 927;
264 $refId = 847;
265 $subTree = [['child' => 3719, 'ref_id' => 3738, 'obj_id' => 182]];
266 $pathNode = [['child' => $refId, 'type' => 'aa']];
267
268 $this->tree->expects(self::once())->method('getNodePath')->with($subTree[0]['child'], $refId)->willReturn($pathNode);
269 $this->tree->expects(self::once())->method('getNodeData')->with($refId)->willReturn($nodeData);
270 $this->tree->expects(self::once())->method('getSubTree')->with(
271 $nodeData,
272 true,
273 ['frm']
274 )->willReturn($subTree);
275
277 }
static checkForumsExistsInsert(int $ref_id, int $user_id)
$refId
Definition: xapitoken.php:58

References $refId, and ilForumNotification\checkForumsExistsInsert().

+ Here is the call graph for this function:

◆ testConstruct()

ilForumNotificationTest::testConstruct ( )

Definition at line 35 of file ilForumNotificationTest.php.

35 : void
36 {
37 $this->assertInstanceOf(ilForumNotification::class, new ilForumNotification(938));
38 }

◆ testDeleteAdminForce()

ilForumNotificationTest::testDeleteAdminForce ( )

Definition at line 196 of file ilForumNotificationTest.php.

196 : void
197 {
198 $userId = 739;
199 $forumId = 48849;
200
201 $this->database->expects(self::once())->method('manipulateF')->with(
202 '
203 DELETE FROM frm_notification
204 WHERE user_id = %s
205 AND frm_id = %s
206 AND admin_force_noti = %s
207 AND user_id_noti > %s',
208 ['integer', 'integer', 'integer', 'integer'],
209 [$userId, $forumId, 1, 0]
210 );
211
212 $instance = new ilForumNotification(292);
213 $instance->setUserId($userId);
214 $instance->setForumId($forumId);
215
216 $instance->deleteAdminForce();
217 }

◆ testDeleteNotificationAllUsers()

ilForumNotificationTest::testDeleteNotificationAllUsers ( )

Definition at line 309 of file ilForumNotificationTest.php.

309 : void
310 {
311 $forumId = 490;
312 $this->database->expects(self::once())->method('manipulateF')->with(
313 'DELETE FROM frm_notification WHERE frm_id = %s AND user_id_noti > %s',
314 ['integer', 'integer'],
315 [$forumId, 0]
316 );
317
318 $instance = new ilForumNotification(3490);
319 $instance->setForumId($forumId);
320
321 $instance->deleteNotificationAllUsers();
322 }

◆ testDeleteUserToggle()

ilForumNotificationTest::testDeleteUserToggle ( )

Definition at line 219 of file ilForumNotificationTest.php.

219 : void
220 {
221 $forumId = 3877;
222 $userId = 3839;
223 $this->database->expects(self::once())->method('manipulateF')->with(
224 '
225 DELETE FROM frm_notification
226 WHERE user_id = %s
227 AND frm_id = %s
228 AND admin_force_noti = %s
229 AND user_toggle_noti = %s
230 AND user_id_noti > %s',
231 ['integer', 'integer', 'integer', 'integer', 'integer'],
232 [$userId, $forumId, 1, 1, 0]
233 );
234
235 $instance = new ilForumNotification(3830);
236 $instance->setUserId($userId);
237 $instance->setForumId($forumId);
238 $instance->deleteUserToggle();
239 }

◆ testExistsNotification()

ilForumNotificationTest::testExistsNotification ( )

Definition at line 399 of file ilForumNotificationTest.php.

399 : void
400 {
401 $adminForce = false;
402 $forumId = 7332;
403 $userId = 5758;
404
405 $statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
406 $this->database->expects(self::once())->method('queryF')->with(
407 'SELECT user_id FROM frm_notification WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
408 ['integer', 'integer', 'integer'],
409 [$userId, $forumId, (int) $adminForce]
410 )->willReturn($statement);
411
412 $this->database->expects(self::once())->method('numRows')->with($statement)->willReturn(8);
413
414 $instance = new ilForumNotification(434);
415 $instance->setForumId($forumId);
416 $instance->setUserId($userId);
417
418 $this->assertTrue($instance->existsNotification());
419 }

◆ testGetterAndSetter()

ilForumNotificationTest::testGetterAndSetter ( )

Definition at line 40 of file ilForumNotificationTest.php.

40 : void
41 {
42 $instance = new ilForumNotification(940);
43 $instance->setNotificationId(1);
44 $this->assertSame(1, $instance->getNotificationId());
45 $instance->setUserId(2);
46 $this->assertSame(2, $instance->getUserId());
47 $instance->setForumId(3);
48 $this->assertSame(3, $instance->getForumId());
49 $instance->setThreadId(4);
50 $this->assertSame(4, $instance->getThreadId());
51 $instance->setInterestedEvents(5);
52 $this->assertSame(5, $instance->getInterestedEvents());
53 $instance->setAdminForce(true);
54 $this->assertTrue($instance->getAdminForce());
55 $instance->setUserToggle(true);
56 $this->assertTrue($instance->getUserToggle());
57 $instance->setForumRefId(6);
58 $this->assertSame(6, $instance->getForumRefId());
59 $instance->setUserIdNoti(7);
60 $this->assertSame(7, $instance->getUserIdNoti());
61 }

◆ testInsertAdminForce()

ilForumNotificationTest::testInsertAdminForce ( )

Definition at line 159 of file ilForumNotificationTest.php.

159 : void
160 {
161 $userToggle = true;
162 $adminForce = false;
163 $forumId = 970;
164 $userId = 530;
165 $objUserId = 3627;
166 $nextId = 3737;
167
168 $this->user->expects(self::once())->method('getId')->willReturn($objUserId);
169
170 $this->database->expects(self::once())->method('nextId')->willReturn($nextId);
171 $this->database->expects(self::once())->method('manipulateF')->with(
172 '
173 INSERT INTO frm_notification
174 (notification_id, user_id, frm_id, admin_force_noti, user_toggle_noti, user_id_noti)
175 VALUES(%s, %s, %s, %s, %s, %s)',
176 ['integer', 'integer', 'integer', 'integer', 'integer', 'integer'],
177 [
178 $nextId,
179 $userId,
180 $forumId,
181 $adminForce,
182 $userToggle,
183 $objUserId
184 ]
185 );
186
187 $instance = new ilForumNotification(480);
188 $instance->setUserId($userId);
189 $instance->setForumId($forumId);
190 $instance->setAdminForce($adminForce);
191 $instance->setUserToggle($userToggle);
192
193 $instance->insertAdminForce();
194 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testIsAdminForceNotification()

ilForumNotificationTest::testIsAdminForceNotification ( )

Definition at line 63 of file ilForumNotificationTest.php.

63 : void
64 {
65 $forumId = 745;
66 $userId = 271;
67
68 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
69 $this->database->expects(self::once())->method('queryF')->with(
70 '
71 SELECT admin_force_noti FROM frm_notification
72 WHERE user_id = %s
73 AND frm_id = %s
74 AND user_id_noti > %s ',
75 ['integer', 'integer', 'integer'],
76 [$userId, $forumId, 0]
77 )->willReturn($mockStatement);
78 $this->database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn(['admin_force_noti' => '1']);
79
80 $instance = new ilForumNotification(375);
81 $instance->setForumId($forumId);
82 $instance->setUserId($userId);
83
84 $this->assertTrue($instance->isAdminForceNotification());
85 }

◆ testIsAdminForceNotificationFailed()

ilForumNotificationTest::testIsAdminForceNotificationFailed ( )

Definition at line 87 of file ilForumNotificationTest.php.

87 : void
88 {
89 $forumId = 745;
90 $userId = 271;
91
92 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
93 $this->database->expects(self::once())->method('queryF')->with(
94 '
95 SELECT admin_force_noti FROM frm_notification
96 WHERE user_id = %s
97 AND frm_id = %s
98 AND user_id_noti > %s ',
99 ['integer', 'integer', 'integer'],
100 [$userId, $forumId, 0]
101 )->willReturn($mockStatement);
102 $this->database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn(null);
103
104 $instance = new ilForumNotification(375);
105 $instance->setForumId($forumId);
106 $instance->setUserId($userId);
107
108 $this->assertFalse($instance->isAdminForceNotification());
109 }

◆ testIsUserToggleNotification()

ilForumNotificationTest::testIsUserToggleNotification ( )

Definition at line 111 of file ilForumNotificationTest.php.

111 : void
112 {
113 $forumId = 745;
114 $userId = 271;
115
116 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
117 $this->database->expects(self::once())->method('queryF')->with(
118 '
119 SELECT user_toggle_noti FROM frm_notification
120 WHERE user_id = %s
121 AND frm_id = %s
122 AND user_id_noti > %s',
123 ['integer', 'integer', 'integer'],
124 [$userId, $forumId, 0]
125 )->willReturn($mockStatement);
126 $this->database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn(['user_toggle_noti' => '1']);
127
128 $instance = new ilForumNotification(375);
129 $instance->setForumId($forumId);
130 $instance->setUserId($userId);
131
132 $this->assertTrue($instance->isUserToggleNotification());
133 }

◆ testIsUserToggleNotificationFailed()

ilForumNotificationTest::testIsUserToggleNotificationFailed ( )

Definition at line 135 of file ilForumNotificationTest.php.

135 : void
136 {
137 $forumId = 745;
138 $userId = 271;
139
140 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
141 $this->database->expects(self::once())->method('queryF')->with(
142 '
143 SELECT user_toggle_noti FROM frm_notification
144 WHERE user_id = %s
145 AND frm_id = %s
146 AND user_id_noti > %s',
147 ['integer', 'integer', 'integer'],
148 [$userId, $forumId, 0]
149 )->willReturn($mockStatement);
150 $this->database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn(null);
151
152 $instance = new ilForumNotification(375);
153 $instance->setForumId($forumId);
154 $instance->setUserId($userId);
155
156 $this->assertFalse($instance->isUserToggleNotification());
157 }

◆ testMergeThreadNotifications()

ilForumNotificationTest::testMergeThreadNotifications ( )

Definition at line 357 of file ilForumNotificationTest.php.

357 : void
358 {
359 $srcRow = ['user_id' => 47349];
360 $mismatchUserIdRow = ['user_id' => 37, 'notification_id' => 48];
361 $matchUserIdRow = ['user_id' => $srcRow['user_id'], 'notification_id' => 380];
362 $targetId = 840;
363 $srcId = 5749;
364 $srcStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
365 $targetStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
366 $this->database->expects(self::exactly(2))->method('queryF')->withConsecutive(
367 [
368 'SELECT notification_id, user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
369 ['integer', 'integer'],
370 [0, $srcId],
371 ],
372 [
373 'SELECT DISTINCT user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
374 ['integer', 'integer'],
375 [0, $targetId],
376 ],
377 )->willReturnOnConsecutiveCalls($srcStatement, $targetStatement);
378
379 $this->database->expects(self::exactly(5))
380 ->method('fetchAssoc')
381 ->withConsecutive([$srcStatement], [$srcStatement], [$targetStatement], [$targetStatement], [$targetStatement])
382 ->willReturnOnConsecutiveCalls($srcRow, null, $matchUserIdRow, $mismatchUserIdRow, null);
383
384 $this->database->expects(self::once())->method('manipulateF')->with(
385 'DELETE FROM frm_notification WHERE notification_id = %s',
386 ['integer'],
387 [$matchUserIdRow['notification_id']]
388 );
389
390 $this->database->expects(self::once())->method('update')->with(
391 'frm_notification',
392 ['thread_id' => ['integer', $targetId]],
393 ['thread_id' => ['integer', $srcId]]
394 );
395
397 }
static mergeThreadNotifications($merge_source_thread_id, $merge_target_thread_id)

References ilForumNotification\mergeThreadNotifications().

+ Here is the call graph for this function:

◆ testRead()

ilForumNotificationTest::testRead ( )

Definition at line 325 of file ilForumNotificationTest.php.

325 : void
326 {
327 $forumId = 4859;
328 $row = [
329 'notification_id' => 789,
330 'user_id' => 490,
331 'frm_id' => 380,
332 'thread_id' => 280,
333 'admin_force_noti' => 20,
334 'user_toggle_noti' => 90,
335 'interested_events' => 8,
336 'user_id_noti' => 6,
337 ];
338 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
339 $this->database->expects(self::exactly(2))->method('fetchAssoc')->willReturn(
340 $row,
341 null
342 );
343 $this->database->expects(self::once())->method('queryF')->with(
344 'SELECT * FROM frm_notification WHERE frm_id = %s',
345 ['integer'],
346 [$forumId]
347 )->willReturn($mockStatement);
348
349 $instance = new ilForumNotification(84849);
350 $instance->setForumId($forumId);
351
352 $this->assertSame([
353 $row['user_id'] => $row,
354 ], $instance->read());
355 }

◆ testUpdate()

ilForumNotificationTest::testUpdate ( )

Definition at line 279 of file ilForumNotificationTest.php.

279 : void
280 {
281 $forumId = 1122;
282 $userId = 484;
283 $events = 848;
284 $userToggle = true;
285 $adminForce = false;
286 $this->database->expects(self::once())->method('manipulateF')->with(
287 'UPDATE frm_notification SET admin_force_noti = %s, user_toggle_noti = %s, ' .
288 'interested_events = %s WHERE user_id = %s AND frm_id = %s',
289 ['integer', 'integer', 'integer', 'integer', 'integer'],
290 [
291 (int) $adminForce,
292 (int) $userToggle,
293 $events,
294 $userId,
295 $forumId
296 ]
297 );
298
299 $instance = new ilForumNotification(8380);
300 $instance->setAdminForce($adminForce);
301 $instance->setUserToggle($userToggle);
302 $instance->setInterestedEvents($events);
303 $instance->setUserId($userId);
304 $instance->setForumId($forumId);
305
306 $instance->update();
307 }

◆ testupdateUserToggle()

ilForumNotificationTest::testupdateUserToggle ( )

Definition at line 241 of file ilForumNotificationTest.php.

241 : void
242 {
243 $userToggle = true;
244 $forumId = 3877;
245 $userId = 3839;
246
247 $this->database->expects(self::once())->method('manipulateF')->with(
248 'UPDATE frm_notification SET user_toggle_noti = %s WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
249 ['integer', 'integer', 'integer', 'integer'],
250 [$userToggle, $userId, $forumId, 1]
251 );
252
253 $instance = new ilForumNotification(3830);
254 $instance->setUserId($userId);
255 $instance->setForumId($forumId);
256 $instance->setUserToggle($userToggle);
257 $instance->updateUserToggle();
258 }

Field Documentation

◆ $database

ilForumNotificationTest::$database
private

Definition at line 28 of file ilForumNotificationTest.php.

◆ $dic

Container ilForumNotificationTest::$dic = null
private

Definition at line 33 of file ilForumNotificationTest.php.

Referenced by tearDown().

◆ $tree

ilForumNotificationTest::$tree
private

Definition at line 32 of file ilForumNotificationTest.php.

◆ $user

ilForumNotificationTest::$user
private

Definition at line 30 of file ilForumNotificationTest.php.


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