19 declare(strict_types=1);
40 $valueAsObject->thr_top_fk = 8;
41 $valueAsObject->thr_display_user_id = 8;
42 $valueAsObject->thr_usr_alias =
'';
43 $valueAsObject->thr_subject =
'';
44 $valueAsObject->thr_date =
'';
45 $valueAsObject->thr_update =
'';
46 $valueAsObject->import_name =
'';
47 $valueAsObject->thr_num_posts = 8;
48 $valueAsObject->thr_last_post =
'';
49 $valueAsObject->visits = 8;
50 $valueAsObject->is_sticky =
false;
51 $valueAsObject->is_closed =
false;
52 $valueAsObject->frm_obj_id = 8;
53 $valueAsObject->avg_rating = 9;
54 $valueAsObject->thr_author_id = 8;
56 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
57 $mockStatement->expects(self::once())
60 ->willReturn($valueAsObject);
63 $this->mockDatabase->expects(self::once())->method(
'queryF'),
66 )->willReturn($mockStatement);
70 $this->assertInstanceOf(ilForumTopic::class, $instance);
79 'thr_display_user_id' =>
'',
80 'thr_usr_alias' =>
'',
81 'thr_last_post' =>
'',
89 'thr_author_id' =>
'',
92 'num_unread_posts' =>
'',
93 'usr_notification_is_enabled' =>
'',
97 $instance->assignData(
$data);
99 $this->assertSame(0, $instance->getId());
100 $this->assertSame(0, $instance->getForumId());
101 $this->assertSame(
'', $instance->getSubject());
102 $this->assertSame(0, $instance->getDisplayUserId());
103 $this->assertSame(
'', $instance->getUserAlias());
104 $this->assertSame(
'', $instance->getLastPostString());
105 $this->assertSame(
'', $instance->getCreateDate());
106 $this->assertSame(
'', $instance->getChangeDate());
107 $this->assertSame(0, $instance->getVisits());
108 $this->assertSame(
'', $instance->getImportName());
109 $this->assertFalse($instance->isSticky());
110 $this->assertFalse($instance->isClosed());
111 $this->assertSame(0.0, $instance->getAverageRating());
112 $this->assertSame(0, $instance->getThrAuthorId());
114 $this->assertSame(0, $instance->getNumPosts());
115 $this->assertSame(0, $instance->getNumUnreadPosts());
116 $this->assertFalse($instance->isUserNotificationEnabled());
124 $instance->setForumId(10);
125 $instance->setSubject(
'aa');
126 $instance->setDisplayUserId(188);
127 $instance->setUserAlias(
'jl');
128 $instance->setNumPosts(86);
129 $instance->setLastPostString(
'ahssh');
130 $instance->setCreateDate(
'some date');
131 $instance->setImportName(
'xaii');
132 $instance->setSticky(
true);
133 $instance->setClosed(
true);
134 $instance->setAverageRating(78);
135 $instance->setThrAuthorId(8890);
137 $this->mockDatabase->expects(self::once())->method(
'nextId')->with(
'frm_threads')->willReturn($nextId);
139 $this->mockDatabase->expects(self::once())->method(
'insert')->with(
142 'thr_pk' => [
'integer', $nextId],
143 'thr_top_fk' => [
'integer', 10],
144 'thr_subject' => [
'text',
'aa'],
145 'thr_display_user_id' => [
'integer', 188],
146 'thr_usr_alias' => [
'text',
'jl'],
147 'thr_num_posts' => [
'integer', 86],
148 'thr_last_post' => [
'text',
'ahssh'],
149 'thr_date' => [
'timestamp',
'some date'],
150 'thr_update' => [
'timestamp',
null],
151 'import_name' => [
'text',
'xaii'],
152 'is_sticky' => [
'integer', 1],
153 'is_closed' => [
'integer', 1],
154 'avg_rating' => [
'text', 78],
155 'thr_author_id' => [
'integer', 8890],
159 $this->assertTrue($instance->insert());
165 $this->mockDatabase->expects(self::never())->method(
'nextId');
166 $this->mockDatabase->expects(self::never())->method(
'insert');
167 $instance->setForumId(0);
168 $this->assertFalse($instance->insert());
175 $instance->setForumId(789);
176 $instance->setSubject(
'abc');
177 $instance->setNumPosts(67);
178 $instance->setLastPostString(
'hej');
179 $instance->setAverageRating(27);
182 $this->mockDatabase->expects(self::once())->method(
'manipulateF'),
183 [
'integer',
'text',
'timestamp',
'integer',
'text',
'text',
'integer'],
194 $this->assertTrue($instance->update());
200 $this->mockDatabase->expects(self::never())->method(
'manipulateF');
201 $instance->setForumId(0);
202 $this->assertFalse($instance->update());
207 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
208 $mockStatement->expects(self::once())->method(
'fetchRow')->willReturn(
null);
209 $this->mockDatabase->expects(self::once())->method(
'queryF')->willReturn($mockStatement);
211 $instance->setId(89);
219 $stdObject->pos_fk = 5678;
220 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
221 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
222 'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos = %s AND depth = %s ORDER BY rgt DESC',
223 [
'integer',
'integer',
'integer'],
225 )->willReturn($mockStatement);
226 $this->mockDatabase->expects(self::once())->method(
'fetchObject')->with($mockStatement)->willReturn($stdObject);
229 $instance->setId(
$id);
230 $this->assertSame($stdObject->pos_fk, $instance->getPostRootId());
237 $stdObject->pos_fk = 5678;
238 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
239 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
240 'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos != %s AND depth = %s ORDER BY rgt DESC',
241 [
'integer',
'integer',
'integer'],
243 )->willReturn($mockStatement);
244 $this->mockDatabase->expects(self::once())->method(
'fetchObject')->with($mockStatement)->willReturn($stdObject);
247 $instance->setId(
$id);
248 $this->assertSame($stdObject->pos_fk, $instance->getFirstVisiblePostId());
254 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
255 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
256 'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos = %s AND depth = %s ORDER BY rgt DESC',
257 [
'integer',
'integer',
'integer'],
259 )->willReturn($mockStatement);
260 $this->mockDatabase->expects(self::once())->method(
'fetchObject')->with($mockStatement)->willReturn(
null);
263 $instance->setId(
$id);
264 $this->assertSame(0, $instance->getPostRootId());
270 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
271 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
272 'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos != %s AND depth = %s ORDER BY rgt DESC',
273 [
'integer',
'integer',
'integer'],
275 )->willReturn($mockStatement);
276 $this->mockDatabase->expects(self::once())->method(
'fetchObject')->with($mockStatement)->willReturn(
null);
279 $instance->setId(
$id);
280 $this->assertSame(0, $instance->getFirstVisiblePostId());
286 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
288 $this->mockDatabase->expects(self::once())->method(
'queryF'),
291 )->willReturn($mockStatement);
292 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'cnt' => 678]);
295 $instance->setId(
$id);
296 $this->assertSame(678, $instance->countPosts(
true));
302 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
304 $this->mockDatabase->expects(self::once())->method(
'queryF'),
307 )->willReturn($mockStatement);
308 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn(
null);
311 $instance->setId(
$id);
312 $this->assertSame(0, $instance->countPosts(
true));
319 $this->mockUser->expects(self::once())->method(
'getId')->willReturn($userId);
320 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
322 $this->mockDatabase->expects(self::once())->method(
'queryF'),
323 [
'integer',
'integer',
'integer',
'integer'],
324 [
'1',
'0', $userId,
$id]
325 )->willReturn($mockStatement);
326 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'cnt' => 79]);
329 $instance->setId(
$id);
330 $this->assertSame(79, $instance->countActivePosts(
true));
337 $this->mockUser->expects(self::once())->method(
'getId')->willReturn($userId);
338 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
340 $this->mockDatabase->expects(self::once())->method(
'queryF'),
341 [
'integer',
'integer',
'integer',
'integer'],
342 [
'1',
'0', $userId,
$id]
343 )->willReturn($mockStatement);
344 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn(
null);
347 $instance->setId(
$id);
348 $this->assertSame(0, $instance->countActivePosts(
true));
354 $firstRow->pos_pk = 89;
356 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
357 $mockStatement->expects(self::exactly(2))
360 ->willReturnOnConsecutiveCalls($firstRow,
null);
361 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
362 'SELECT pos_pk FROM frm_posts WHERE pos_thr_fk = %s',
365 )->willReturn($mockStatement);
368 $instance->setId(
$id);
369 $this->assertSame([$firstRow->pos_pk => $firstRow->pos_pk], $instance->getAllPostIds());
378 $instance->setId(
$id);
380 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
381 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
382 'SELECT COUNT(notification_id) cnt FROM frm_notification WHERE user_id = %s AND thread_id = %s',
383 [
'integer',
'integer'],
385 )->willReturn($mockStatement);
386 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'cnt' => 46]);
388 $this->assertTrue($instance->isNotificationEnabled($userId));
397 $instance->setId(
$id);
399 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
400 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
401 'SELECT COUNT(notification_id) cnt FROM frm_notification WHERE user_id = %s AND thread_id = %s',
402 [
'integer',
'integer'],
404 )->willReturn($mockStatement);
405 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn(
null);
407 $this->assertFalse($instance->isNotificationEnabled($userId));
416 $instance->setId(
$id);
418 $this->mockDatabase->expects(self::never())->method(
'queryF');
419 $this->mockDatabase->expects(self::never())->method(
'fetchAssoc');
421 $this->assertFalse($instance->isNotificationEnabled($userId));
430 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
431 $this->mockDatabase->expects(self::once())->method(
'nextId')->with(
'frm_notification')->willReturn($nextId);
432 $this->mockDatabase->expects(self::once())->method(
'queryF')->willReturn($mockStatement);
434 $this->mockDatabase->expects(self::once())->method(
'manipulateF'),
435 [
'integer',
'integer',
'integer'],
436 [$nextId, $userId,
$id]
438 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'cnt' => 0]);
441 $instance->setId(
$id);
442 $instance->enableNotification($userId);
450 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
451 'DELETE FROM frm_notification WHERE user_id = %s AND thread_id = %s',
452 [
'integer',
'integer'],
457 $instance->setId(
$id);
458 $instance->disableNotification($userId);
465 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
466 'UPDATE frm_threads SET is_sticky = %s WHERE thr_pk = %s',
467 [
'integer',
'integer'],
472 $instance->setId(
$id);
473 $this->assertTrue($instance->makeSticky());
478 $this->mockDatabase->expects(self::never())->method(
'manipulateF');
481 $this->assertFalse($instance->makeSticky());
488 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
489 'UPDATE frm_threads SET is_sticky = %s WHERE thr_pk = %s',
490 [
'integer',
'integer'],
495 $instance->setId(
$id);
496 $instance->setSticky(
true);
497 $this->assertTrue($instance->unmakeSticky());
504 $this->mockDatabase->expects(self::never())->method(
'manipulateF');
507 $instance->setId(
$id);
508 $this->assertFalse($instance->unmakeSticky());
515 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
516 'UPDATE frm_threads SET is_closed = %s WHERE thr_pk = %s',
517 [
'integer',
'integer'],
522 $instance->setId(
$id);
523 $instance->setClosed(
false);
531 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
532 'UPDATE frm_threads SET is_closed = %s WHERE thr_pk = %s',
533 [
'integer',
'integer'],
538 $instance->setId(
$id);
539 $instance->setClosed(
true);
547 $this->dic = is_object($DIC) ? clone
$DIC :
$DIC;
551 $this->mockDatabase = $this->getMockBuilder(ilDBInterface::class)->getMock();
552 $this->mockUser = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
567 private function withIgnoredQuery(InvocationMocker $mock, array ...$expected): InvocationMocker
569 return $mock->willReturnCallback(
function ($ignored, ...$actual) use ($expected):
void {
570 $this->assertSame($expected, $actual);
Customizing of pimple-DIC for ILIAS.
testGetFirstVisiblePostId()
withIgnoredQuery(InvocationMocker $mock, array ... $expected)
testIsNotificationEnabledNoResult()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
testGetPostRootIdFailed()
testIsNotificationEnabledInvalidIds()
testDisableNotification()
testIsNotificationEnabled()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
testCountActivePostsFailed()
testGetFirstVisiblePostIdFailed()