ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 423 of file ilForumNotificationTest.php.

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

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

◆ tearDown()

ilForumNotificationTest::tearDown ( )
protected

Definition at line 437 of file ilForumNotificationTest.php.

References $DIC, and $dic.

437  : void
438  {
439  global $DIC;
440 
441  $DIC = $this->dic;
442 
443  parent::tearDown();
444  }
global $DIC
Definition: feed.php:28

◆ testCheckForumsExistsInsert()

ilForumNotificationTest::testCheckForumsExistsInsert ( )

Definition at line 260 of file ilForumNotificationTest.php.

References $refId, and ilForumNotification\checkForumsExistsInsert().

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

◆ 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  }
Class ilForumNotification.

◆ testDeleteNotificationAllUsers()

ilForumNotificationTest::testDeleteNotificationAllUsers ( )

Definition at line 311 of file ilForumNotificationTest.php.

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

◆ 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  }
Class ilForumNotification.

◆ testExistsNotification()

ilForumNotificationTest::testExistsNotification ( )

Definition at line 401 of file ilForumNotificationTest.php.

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

◆ 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  }
Class ilForumNotification.

◆ testInsertAdminForce()

ilForumNotificationTest::testInsertAdminForce ( )

Definition at line 159 of file ilForumNotificationTest.php.

References ILIAS\Repository\user().

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  }
Class ilForumNotification.
+ 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  }
Class ilForumNotification.

◆ 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  }
Class ilForumNotification.

◆ 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  }
Class ilForumNotification.

◆ 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  }
Class ilForumNotification.

◆ testMergeThreadNotifications()

ilForumNotificationTest::testMergeThreadNotifications ( )

Definition at line 359 of file ilForumNotificationTest.php.

References ilForumNotification\mergeThreadNotifications().

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

◆ testRead()

ilForumNotificationTest::testRead ( )

Definition at line 327 of file ilForumNotificationTest.php.

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

◆ testUpdate()

ilForumNotificationTest::testUpdate ( )

Definition at line 281 of file ilForumNotificationTest.php.

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

◆ 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  }
Class ilForumNotification.

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: