19declare(strict_types=1);
22use PHPUnit\Framework\TestCase;
23use PHPUnit\Framework\MockObject\MockObject;
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());
163 $interested_in_events = 15;
166 $this->
user->expects(self::once())->method(
'getId')->willReturn($objUserId);
168 $this->
database->expects(self::once())->method(
'nextId')->willReturn($nextId);
169 $this->
database->expects(self::once())->method(
'manipulateF')->with(
171 INSERT INTO frm_notification
172 (notification_id, user_id, frm_id, admin_force_noti, user_toggle_noti, interested_events, user_id_noti)
173 VALUES(%s, %s, %s, %s, %s, %s, %s)',
174 [
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'],
181 $interested_in_events,
187 $instance->setUserId($userId);
188 $instance->setForumId($forumId);
189 $instance->setAdminForce($adminForce);
190 $instance->setUserToggle($userToggle);
191 $instance->setInterestedEvents($interested_in_events);
193 $instance->insertAdminForce();
201 $this->
database->expects(self::once())->method(
'manipulateF')->with(
203 DELETE FROM frm_notification
206 AND admin_force_noti = %s
207 AND user_id_noti > %s',
208 [
'integer',
'integer',
'integer',
'integer'],
209 [$userId, $forumId, 1, 0]
213 $instance->setUserId($userId);
214 $instance->setForumId($forumId);
216 $instance->deleteAdminForce();
223 $this->
database->expects(self::once())->method(
'manipulateF')->with(
225 DELETE FROM frm_notification
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]
236 $instance->setUserId($userId);
237 $instance->setForumId($forumId);
238 $instance->deleteUserToggle();
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]
254 $instance->setUserId($userId);
255 $instance->setForumId($forumId);
256 $instance->setUserToggle($userToggle);
257 $instance->updateUserToggle();
267 $subTree = [[
'child' => 3719,
'ref_id' => 3738,
'obj_id' => 182]];
268 $pathNode = [[
'child' =>
$refId,
'type' =>
'aa']];
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(
276 )->willReturn($subTree);
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'],
302 $instance->setAdminForce($adminForce);
303 $instance->setUserToggle($userToggle);
304 $instance->setInterestedEvents($events);
305 $instance->setUserId($userId);
306 $instance->setForumId($forumId);
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'],
321 $instance->setForumId($forumId);
323 $instance->deleteNotificationAllUsers();
331 'notification_id' => 789,
335 'admin_force_noti' => 20,
336 'user_toggle_noti' => 90,
337 'interested_events' => 8,
340 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
341 $this->
database->expects(self::exactly(2))->method(
'fetchAssoc')->willReturn(
345 $this->
database->expects(self::once())->method(
'queryF')->with(
346 'SELECT * FROM frm_notification WHERE frm_id = %s',
349 )->willReturn($mockStatement);
352 $instance->setForumId($forumId);
355 $row[
'user_id'] => $row,
356 ], $instance->read());
361 $srcRow = [
'user_id' => 47349];
362 $mismatchUserIdRow = [
'user_id' => 37,
'notification_id' => 48];
363 $matchUserIdRow = [
'user_id' => $srcRow[
'user_id'],
'notification_id' => 380];
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'
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);
378 $this->identicalTo([
'integer',
'integer']),
379 $this->callback(
function ($value) use (&$consecutive_query_value) {
380 $this->assertSame(array_shift($consecutive_query_value), $value);
383 )->willReturnOnConsecutiveCalls($srcStatement, $targetStatement);
385 $consecutive_fetch = [
392 $this->
database->expects(self::exactly(5))
393 ->method(
'fetchAssoc')
395 $this->callback(
function ($value) use (&$consecutive_fetch) {
396 $this->assertSame(array_shift($consecutive_fetch), $value);
400 ->willReturnOnConsecutiveCalls($srcRow,
null, $matchUserIdRow, $mismatchUserIdRow,
null);
402 $this->
database->expects(self::once())->method(
'manipulateF')->with(
403 'DELETE FROM frm_notification WHERE notification_id = %s',
405 [$matchUserIdRow[
'notification_id']]
408 $this->
database->expects(self::once())->method(
'update')->with(
410 [
'thread_id' => [
'integer', $targetId]],
411 [
'thread_id' => [
'integer', $srcId]]
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);
430 $this->
database->expects(self::once())->method(
'numRows')->with($statement)->willReturn(8);
433 $instance->setForumId($forumId);
434 $instance->setUserId($userId);
436 $this->assertTrue($instance->existsNotification());
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());
Customizing of pimple-DIC for ILIAS.
testIsAdminForceNotification()
MockObject &ilObjUser $user
MockObject &ilDBInterface $database
testCheckForumsExistsInsert()
testIsUserToggleNotificationFailed()
testMergeThreadNotifications()
testIsUserToggleNotification()
testDeleteNotificationAllUsers()
testIsAdminForceNotificationFailed()
Class ilForumNotification.
static checkForumsExistsInsert(int $ref_id, int $user_id)
static mergeThreadNotifications($merge_source_thread_id, $merge_target_thread_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...