ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 439 of file ilForumNotificationTest.php.

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

439  : void
440  {
441  global $DIC;
442 
443  $this->dic = is_object($DIC) ? clone $DIC : $DIC;
444 
445  $DIC = new Container();
446 
447  $DIC['ilDB'] = ($this->database = $this->createMock(ilDBInterface::class));
448  $DIC['ilUser'] = ($this->user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock());
449  $DIC['ilObjDataCache'] = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
450  $DIC['tree'] = ($this->tree = $this->getMockBuilder(ilTree::class)->disableOriginalConstructor()->getMock());
451  }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

◆ tearDown()

ilForumNotificationTest::tearDown ( )
protected

Definition at line 453 of file ilForumNotificationTest.php.

References $DIC, and $dic.

453  : void
454  {
455  global $DIC;
456 
457  $DIC = $this->dic;
458 
459  parent::tearDown();
460  }
global $DIC
Definition: shib_login.php:22

◆ 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 417 of file ilForumNotificationTest.php.

417  : void
418  {
419  $adminForce = false;
420  $forumId = 7332;
421  $userId = 5758;
422 
423  $statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
424  $this->database->expects(self::once())->method('queryF')->with(
425  'SELECT user_id FROM frm_notification WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
426  ['integer', 'integer', 'integer'],
427  [$userId, $forumId, (int) $adminForce]
428  )->willReturn($statement);
429 
430  $this->database->expects(self::once())->method('numRows')->with($statement)->willReturn(8);
431 
432  $instance = new ilForumNotification(434);
433  $instance->setForumId($forumId);
434  $instance->setUserId($userId);
435 
436  $this->assertTrue($instance->existsNotification());
437  }
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.

References null.

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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ 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.

References null.

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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ testMergeThreadNotifications()

ilForumNotificationTest::testMergeThreadNotifications ( )

Definition at line 359 of file ilForumNotificationTest.php.

References ilForumNotification\mergeThreadNotifications(), and null.

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  $consecutive_query_string = [
369  'SELECT notification_id, user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
370  'SELECT DISTINCT user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC'
371  ];
372  $consecutive_query_value = [[0, $srcId], [0, $targetId]];
373  $this->database->expects(self::exactly(2))->method('queryF')->with(
374  $this->callback(function ($value) use (&$consecutive_query_string) {
375  $this->assertSame(array_shift($consecutive_query_string), $value);
376  return true;
377  }),
378  $this->identicalTo(['integer', 'integer']),
379  $this->callback(function ($value) use (&$consecutive_query_value) {
380  $this->assertSame(array_shift($consecutive_query_value), $value);
381  return true;
382  })
383  )->willReturnOnConsecutiveCalls($srcStatement, $targetStatement);
384 
385  $consecutive_fetch = [
386  $targetStatement,
387  $targetStatement,
388  $srcStatement,
389  $srcStatement,
390  $srcStatement
391  ];
392  $this->database->expects(self::exactly(5))
393  ->method('fetchAssoc')
394  ->with(
395  $this->callback(function ($value) use (&$consecutive_fetch) {
396  $this->assertSame(array_shift($consecutive_fetch), $value);
397  return true;
398  })
399  )
400  ->willReturnOnConsecutiveCalls($srcRow, null, $matchUserIdRow, $mismatchUserIdRow, null);
401 
402  $this->database->expects(self::once())->method('manipulateF')->with(
403  'DELETE FROM frm_notification WHERE notification_id = %s',
404  ['integer'],
405  [$matchUserIdRow['notification_id']]
406  );
407 
408  $this->database->expects(self::once())->method('update')->with(
409  'frm_notification',
410  ['thread_id' => ['integer', $targetId]],
411  ['thread_id' => ['integer', $srcId]]
412  );
413 
415  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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.

References null.

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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ 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: