19 declare(strict_types=1);
40 $instance->setNotificationId(1);
41 $this->assertSame(1, $instance->getNotificationId());
42 $instance->setUserId(2);
43 $this->assertSame(2, $instance->getUserId());
44 $instance->setForumId(3);
45 $this->assertSame(3, $instance->getForumId());
46 $instance->setThreadId(4);
47 $this->assertSame(4, $instance->getThreadId());
48 $instance->setInterestedEvents(5);
49 $this->assertSame(5, $instance->getInterestedEvents());
50 $instance->setAdminForce(
true);
51 $this->assertTrue($instance->getAdminForce());
52 $instance->setUserToggle(
true);
53 $this->assertTrue($instance->getUserToggle());
54 $instance->setForumRefId(6);
55 $this->assertSame(6, $instance->getForumRefId());
56 $instance->setUserIdNoti(7);
57 $this->assertSame(7, $instance->getUserIdNoti());
65 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
66 $this->
database->expects(self::once())->method(
'queryF')->with(
68 SELECT admin_force_noti FROM frm_notification 71 AND user_id_noti > %s ',
72 [
'integer',
'integer',
'integer'],
73 [$userId, $forumId, 0]
74 )->willReturn($mockStatement);
75 $this->
database->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'admin_force_noti' =>
'1']);
78 $instance->setForumId($forumId);
79 $instance->setUserId($userId);
81 $this->assertTrue($instance->isAdminForceNotification());
89 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
90 $this->
database->expects(self::once())->method(
'queryF')->with(
92 SELECT admin_force_noti FROM frm_notification 95 AND user_id_noti > %s ',
96 [
'integer',
'integer',
'integer'],
97 [$userId, $forumId, 0]
98 )->willReturn($mockStatement);
99 $this->
database->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn(
null);
102 $instance->setForumId($forumId);
103 $instance->setUserId($userId);
105 $this->assertFalse($instance->isAdminForceNotification());
113 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
114 $this->
database->expects(self::once())->method(
'queryF')->with(
116 SELECT user_toggle_noti FROM frm_notification 119 AND user_id_noti > %s',
120 [
'integer',
'integer',
'integer'],
121 [$userId, $forumId, 0]
122 )->willReturn($mockStatement);
123 $this->
database->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'user_toggle_noti' =>
'1']);
126 $instance->setForumId($forumId);
127 $instance->setUserId($userId);
129 $this->assertTrue($instance->isUserToggleNotification());
137 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
138 $this->
database->expects(self::once())->method(
'queryF')->with(
140 SELECT user_toggle_noti FROM frm_notification 143 AND user_id_noti > %s',
144 [
'integer',
'integer',
'integer'],
145 [$userId, $forumId, 0]
146 )->willReturn($mockStatement);
147 $this->
database->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn(
null);
150 $instance->setForumId($forumId);
151 $instance->setUserId($userId);
153 $this->assertFalse($instance->isUserToggleNotification());
165 $this->
user->expects(self::once())->method(
'getId')->willReturn($objUserId);
167 $this->
database->expects(self::once())->method(
'nextId')->willReturn($nextId);
168 $this->
database->expects(self::once())->method(
'manipulateF')->with(
170 INSERT INTO frm_notification 171 (notification_id, user_id, frm_id, admin_force_noti, user_toggle_noti, user_id_noti) 172 VALUES(%s, %s, %s, %s, %s, %s)',
173 [
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'],
185 $instance->setUserId($userId);
186 $instance->setForumId($forumId);
187 $instance->setAdminForce($adminForce);
188 $instance->setUserToggle($userToggle);
190 $instance->insertAdminForce();
198 $this->
database->expects(self::once())->method(
'manipulateF')->with(
200 DELETE FROM frm_notification 203 AND admin_force_noti = %s 204 AND user_id_noti > %s',
205 [
'integer',
'integer',
'integer',
'integer'],
206 [$userId, $forumId, 1, 0]
210 $instance->setUserId($userId);
211 $instance->setForumId($forumId);
213 $instance->deleteAdminForce();
220 $this->
database->expects(self::once())->method(
'manipulateF')->with(
222 DELETE FROM frm_notification 225 AND admin_force_noti = %s 226 AND user_toggle_noti = %s 227 AND user_id_noti > %s',
228 [
'integer',
'integer',
'integer',
'integer',
'integer'],
229 [$userId, $forumId, 1, 1, 0]
233 $instance->setUserId($userId);
234 $instance->setForumId($forumId);
235 $instance->deleteUserToggle();
244 $this->
database->expects(self::once())->method(
'manipulateF')->with(
245 'UPDATE frm_notification SET user_toggle_noti = %s WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
246 [
'integer',
'integer',
'integer',
'integer'],
247 [$userToggle, $userId, $forumId, 1]
251 $instance->setUserId($userId);
252 $instance->setForumId($forumId);
253 $instance->setUserToggle($userToggle);
254 $instance->updateUserToggle();
264 $subTree = [[
'child' => 3719,
'ref_id' => 3738,
'obj_id' => 182]];
265 $pathNode = [[
'child' =>
$refId,
'type' =>
'aa']];
267 $this->tree->expects(self::once())->method(
'getNodeData')->with(
$refId)->willReturn($nodeData);
268 $this->tree->expects(self::once())->method(
'getNodePath')->with($subTree[0][
'child'],
$refId)->willReturn($pathNode);
269 $this->tree->expects(self::once())->method(
'getSubTree')->with(
273 )->willReturn($subTree);
285 $this->
database->expects(self::once())->method(
'manipulateF')->with(
286 'UPDATE frm_notification SET admin_force_noti = %s, user_toggle_noti = %s, ' .
287 'interested_events = %s WHERE user_id = %s AND frm_id = %s',
288 [
'integer',
'integer',
'integer',
'integer',
'integer'],
299 $instance->setAdminForce($adminForce);
300 $instance->setUserToggle($userToggle);
301 $instance->setInterestedEvents($events);
302 $instance->setUserId($userId);
303 $instance->setForumId($forumId);
311 $this->
database->expects(self::once())->method(
'manipulateF')->with(
312 'DELETE FROM frm_notification WHERE frm_id = %s AND user_id_noti > %s',
313 [
'integer',
'integer'],
318 $instance->setForumId($forumId);
320 $instance->deleteNotificationAllUsers();
328 'notification_id' => 789,
332 'admin_force_noti' => 20,
333 'user_toggle_noti' => 90,
334 'interested_events' => 8,
337 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
338 $this->
database->expects(self::exactly(2))->method(
'fetchAssoc')->willReturn(
342 $this->
database->expects(self::once())->method(
'queryF')->with(
343 'SELECT * FROM frm_notification WHERE frm_id = %s',
346 )->willReturn($mockStatement);
349 $instance->setForumId($forumId);
352 $row[
'user_id'] => $row,
353 ], $instance->read());
358 $srcRow = [
'user_id' => 47349];
359 $mismatchUserIdRow = [
'user_id' => 37,
'notification_id' => 48];
360 $matchUserIdRow = [
'user_id' => $srcRow[
'user_id'],
'notification_id' => 380];
363 $srcStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
364 $targetStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
365 $consecutive_query_string = [
366 'SELECT notification_id, user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC',
367 'SELECT DISTINCT user_id FROM frm_notification WHERE frm_id = %s AND thread_id = %s ORDER BY user_id ASC' 369 $consecutive_query_value = [[0, $srcId], [0, $targetId]];
370 $this->
database->expects(self::exactly(2))->method(
'queryF')->with(
371 $this->callback(
function ($value) use (&$consecutive_query_string) {
372 $this->assertSame(array_shift($consecutive_query_string), $value);
375 $this->identicalTo([
'integer',
'integer']),
376 $this->callback(
function ($value) use (&$consecutive_query_value) {
377 $this->assertSame(array_shift($consecutive_query_value), $value);
380 )->willReturnOnConsecutiveCalls($srcStatement, $targetStatement);
382 $consecutive_fetch = [
389 $this->
database->expects(self::exactly(5))
390 ->method(
'fetchAssoc')
392 $this->callback(
function ($value) use (&$consecutive_fetch) {
393 $this->assertSame(array_shift($consecutive_fetch), $value);
397 ->willReturnOnConsecutiveCalls($srcRow,
null, $matchUserIdRow, $mismatchUserIdRow,
null);
399 $this->
database->expects(self::once())->method(
'manipulateF')->with(
400 'DELETE FROM frm_notification WHERE notification_id = %s',
402 [$matchUserIdRow[
'notification_id']]
405 $this->
database->expects(self::once())->method(
'update')->with(
407 [
'thread_id' => [
'integer', $targetId]],
408 [
'thread_id' => [
'integer', $srcId]]
420 $statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
421 $this->
database->expects(self::once())->method(
'queryF')->with(
422 'SELECT user_id FROM frm_notification WHERE user_id = %s AND frm_id = %s AND admin_force_noti = %s',
423 [
'integer',
'integer',
'integer'],
424 [$userId, $forumId, (
int) $adminForce]
425 )->willReturn($statement);
427 $this->
database->expects(self::once())->method(
'numRows')->with($statement)->willReturn(8);
430 $instance->setForumId($forumId);
431 $instance->setUserId($userId);
433 $this->assertTrue($instance->existsNotification());
440 $this->dic = is_object($DIC) ? clone
$DIC :
$DIC;
444 $DIC[
'ilDB'] = ($this->
database = $this->createMock(ilDBInterface::class));
445 $DIC[
'ilUser'] = ($this->
user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock());
446 $DIC[
'ilObjDataCache'] = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
447 $DIC[
'tree'] = ($this->tree = $this->getMockBuilder(ilTree::class)->disableOriginalConstructor()->getMock());
testIsAdminForceNotification()
testDeleteNotificationAllUsers()
MockObject &ilObjUser $user
Customizing of pimple-DIC for ILIAS.
testIsUserToggleNotification()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
MockObject &ilDBInterface $database
testIsUserToggleNotificationFailed()
testMergeThreadNotifications()
testCheckForumsExistsInsert()
static mergeThreadNotifications($merge_source_thread_id, $merge_target_thread_id)
static checkForumsExistsInsert(int $ref_id, int $user_id)
testIsAdminForceNotificationFailed()