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->thread_sorting = 0;
52 $valueAsObject->is_closed =
false;
53 $valueAsObject->frm_obj_id = 8;
54 $valueAsObject->avg_rating = 9;
55 $valueAsObject->thr_author_id = 8;
57 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
58 $mockStatement->expects(self::once())
61 ->willReturn($valueAsObject);
64 $this->mockDatabase->expects(self::once())->method(
'queryF'),
67 )->willReturn($mockStatement);
71 $this->assertInstanceOf(ilForumTopic::class, $instance);
80 'thr_display_user_id' =>
'',
81 'thr_usr_alias' =>
'',
82 'thr_last_post' =>
'',
90 'thr_author_id' =>
'',
93 'num_unread_posts' =>
'',
94 'num_new_posts' =>
'',
95 'usr_notification_is_enabled' =>
'',
99 $instance->assignData(
$data);
101 $this->assertSame(0, $instance->getId());
102 $this->assertSame(0, $instance->getForumId());
103 $this->assertSame(
'', $instance->getSubject());
104 $this->assertSame(0, $instance->getDisplayUserId());
105 $this->assertSame(
'', $instance->getUserAlias());
106 $this->assertSame(
'', $instance->getLastPostString());
107 $this->assertSame(
'', $instance->getCreateDate());
108 $this->assertSame(
'', $instance->getChangeDate());
109 $this->assertSame(0, $instance->getVisits());
110 $this->assertSame(
'', $instance->getImportName());
111 $this->assertFalse($instance->isSticky());
112 $this->assertFalse($instance->isClosed());
113 $this->assertSame(0.0, $instance->getAverageRating());
114 $this->assertSame(0, $instance->getThrAuthorId());
116 $this->assertSame(0, $instance->getNumPosts());
117 $this->assertSame(0, $instance->getNumUnreadPosts());
118 $this->assertSame(0, $instance->getNumNewPosts());
119 $this->assertFalse($instance->isUserNotificationEnabled());
127 $instance->setForumId(10);
128 $instance->setSubject(
'aa');
129 $instance->setDisplayUserId(188);
130 $instance->setUserAlias(
'jl');
131 $instance->setNumPosts(86);
132 $instance->setLastPostString(
'ahssh');
133 $instance->setCreateDate(
'some date');
134 $instance->setImportName(
'xaii');
135 $instance->setSticky(
true);
136 $instance->setClosed(
true);
137 $instance->setAverageRating(78);
138 $instance->setThrAuthorId(8890);
140 $this->mockDatabase->expects(self::once())->method(
'nextId')->with(
'frm_threads')->willReturn($nextId);
142 $this->mockDatabase->expects(self::once())->method(
'insert')->with(
145 'thr_pk' => [
'integer', $nextId],
146 'thr_top_fk' => [
'integer', 10],
147 'thr_subject' => [
'text',
'aa'],
148 'thr_display_user_id' => [
'integer', 188],
149 'thr_usr_alias' => [
'text',
'jl'],
150 'thr_num_posts' => [
'integer', 86],
151 'thr_last_post' => [
'text',
'ahssh'],
152 'thr_date' => [
'timestamp',
'some date'],
153 'thr_update' => [
'timestamp', null],
154 'thread_sorting' => [
'integer', 0],
155 'import_name' => [
'text',
'xaii'],
156 'is_sticky' => [
'integer', 1],
157 'is_closed' => [
'integer', 1],
158 'avg_rating' => [
'text', 78],
159 'thr_author_id' => [
'integer', 8890],
163 $this->assertTrue($instance->insert());
169 $this->mockDatabase->expects(self::never())->method(
'nextId');
170 $this->mockDatabase->expects(self::never())->method(
'insert');
171 $instance->setForumId(0);
172 $this->assertFalse($instance->insert());
179 $instance->setForumId(789);
180 $instance->setSubject(
'abc');
181 $instance->setNumPosts(67);
182 $instance->setLastPostString(
'hej');
183 $instance->setAverageRating(27);
186 $this->mockDatabase->expects(self::once())->method(
'manipulateF'),
187 [
'integer',
'text',
'timestamp',
'integer',
'text',
'text',
'integer'],
198 $this->assertTrue($instance->update());
204 $this->mockDatabase->expects(self::never())->method(
'manipulateF');
205 $instance->setForumId(0);
206 $this->assertFalse($instance->update());
211 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
212 $mockStatement->expects(self::once())->method(
'fetchRow')->willReturn(null);
213 $this->mockDatabase->expects(self::once())->method(
'queryF')->willReturn($mockStatement);
215 $instance->setId(89);
223 $stdObject->pos_fk = 5678;
224 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
225 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
226 'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos = %s AND depth = %s ORDER BY rgt DESC',
227 [
'integer',
'integer',
'integer'],
229 )->willReturn($mockStatement);
230 $this->mockDatabase->expects(self::once())->method(
'fetchObject')->with($mockStatement)->willReturn($stdObject);
233 $instance->setId(
$id);
234 $this->assertSame($stdObject->pos_fk, $instance->getPostRootId());
241 $stdObject->pos_fk = 5678;
242 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
243 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
244 'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos != %s AND depth = %s ORDER BY rgt DESC',
245 [
'integer',
'integer',
'integer'],
247 )->willReturn($mockStatement);
248 $this->mockDatabase->expects(self::once())->method(
'fetchObject')->with($mockStatement)->willReturn($stdObject);
251 $instance->setId(
$id);
252 $this->assertSame($stdObject->pos_fk, $instance->getFirstVisiblePostId());
258 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
259 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
260 'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos = %s AND depth = %s ORDER BY rgt DESC',
261 [
'integer',
'integer',
'integer'],
263 )->willReturn($mockStatement);
264 $this->mockDatabase->expects(self::once())->method(
'fetchObject')->with($mockStatement)->willReturn(null);
267 $instance->setId(
$id);
268 $this->assertSame(0, $instance->getPostRootId());
274 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
275 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
276 'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos != %s AND depth = %s ORDER BY rgt DESC',
277 [
'integer',
'integer',
'integer'],
279 )->willReturn($mockStatement);
280 $this->mockDatabase->expects(self::once())->method(
'fetchObject')->with($mockStatement)->willReturn(null);
283 $instance->setId(
$id);
284 $this->assertSame(0, $instance->getFirstVisiblePostId());
290 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
292 $this->mockDatabase->expects(self::once())->method(
'queryF'),
295 )->willReturn($mockStatement);
296 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'cnt' => 678]);
299 $instance->setId(
$id);
300 $this->assertSame(678, $instance->countPosts(
true));
306 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
308 $this->mockDatabase->expects(self::once())->method(
'queryF'),
311 )->willReturn($mockStatement);
312 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn(null);
315 $instance->setId(
$id);
316 $this->assertSame(0, $instance->countPosts(
true));
323 $this->mockUser->expects(self::once())->method(
'getId')->willReturn($userId);
324 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
326 $this->mockDatabase->expects(self::once())->method(
'queryF'),
327 [
'integer',
'integer',
'integer',
'integer'],
328 [
'1',
'0', $userId,
$id]
329 )->willReturn($mockStatement);
330 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'cnt' => 79]);
333 $instance->setId(
$id);
334 $this->assertSame(79, $instance->countActivePosts(
true));
341 $this->mockUser->expects(self::once())->method(
'getId')->willReturn($userId);
342 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
344 $this->mockDatabase->expects(self::once())->method(
'queryF'),
345 [
'integer',
'integer',
'integer',
'integer'],
346 [
'1',
'0', $userId,
$id]
347 )->willReturn($mockStatement);
348 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn(null);
351 $instance->setId(
$id);
352 $this->assertSame(0, $instance->countActivePosts(
true));
358 $firstRow->pos_pk = 89;
360 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
361 $mockStatement->expects(self::exactly(2))
364 ->willReturnOnConsecutiveCalls($firstRow, null);
365 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
366 'SELECT pos_pk FROM frm_posts WHERE pos_thr_fk = %s',
369 )->willReturn($mockStatement);
372 $instance->setId(
$id);
373 $this->assertSame([$firstRow->pos_pk => $firstRow->pos_pk], $instance->getAllPostIds());
382 $instance->setId(
$id);
384 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
385 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
386 'SELECT COUNT(notification_id) cnt FROM frm_notification WHERE user_id = %s AND thread_id = %s',
387 [
'integer',
'integer'],
389 )->willReturn($mockStatement);
390 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'cnt' => 46]);
392 $this->assertTrue($instance->isNotificationEnabled($userId));
401 $instance->setId(
$id);
403 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
404 $this->mockDatabase->expects(self::once())->method(
'queryF')->with(
405 'SELECT COUNT(notification_id) cnt FROM frm_notification WHERE user_id = %s AND thread_id = %s',
406 [
'integer',
'integer'],
408 )->willReturn($mockStatement);
409 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn(null);
411 $this->assertFalse($instance->isNotificationEnabled($userId));
420 $instance->setId(
$id);
422 $this->mockDatabase->expects(self::never())->method(
'queryF');
423 $this->mockDatabase->expects(self::never())->method(
'fetchAssoc');
425 $this->assertFalse($instance->isNotificationEnabled($userId));
434 $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
435 $this->mockDatabase->expects(self::once())->method(
'nextId')->with(
'frm_notification')->willReturn($nextId);
436 $this->mockDatabase->expects(self::once())->method(
'queryF')->willReturn($mockStatement);
438 $this->mockDatabase->expects(self::once())->method(
'manipulateF'),
439 [
'integer',
'integer',
'integer'],
440 [$nextId, $userId,
$id]
442 $this->mockDatabase->expects(self::once())->method(
'fetchAssoc')->with($mockStatement)->willReturn([
'cnt' => 0]);
445 $instance->setId(
$id);
446 $instance->enableNotification($userId);
454 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
455 'DELETE FROM frm_notification WHERE user_id = %s AND thread_id = %s',
456 [
'integer',
'integer'],
461 $instance->setId(
$id);
462 $instance->disableNotification($userId);
469 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
470 'UPDATE frm_threads SET is_sticky = %s WHERE thr_pk = %s',
471 [
'integer',
'integer'],
476 $instance->setId(
$id);
477 $this->assertTrue($instance->makeSticky());
484 $this->mockDatabase->expects(self::never())->method(
'manipulateF');
487 $this->assertFalse($instance->makeSticky());
494 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
495 'UPDATE frm_threads SET is_sticky = %s WHERE thr_pk = %s',
496 [
'integer',
'integer'],
501 $instance->setId(
$id);
502 $instance->setSticky(
true);
503 $this->assertTrue($instance->unmakeSticky());
510 $this->mockDatabase->expects(self::never())->method(
'manipulateF');
513 $instance->setId(
$id);
514 $this->assertFalse($instance->unmakeSticky());
521 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
522 'UPDATE frm_threads SET is_closed = %s WHERE thr_pk = %s',
523 [
'integer',
'integer'],
528 $instance->setId(
$id);
529 $instance->setClosed(
false);
537 $this->mockDatabase->expects(self::once())->method(
'manipulateF')->with(
538 'UPDATE frm_threads SET is_closed = %s WHERE thr_pk = %s',
539 [
'integer',
'integer'],
544 $instance->setId(
$id);
545 $instance->setClosed(
true);
553 $this->dic = is_object($DIC) ? clone
$DIC :
$DIC;
557 $this->mockDatabase = $this->getMockBuilder(ilDBInterface::class)->getMock();
558 $this->mockUser = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
575 return $mock->willReturnCallback(
function ($ignored, ...$actual) use ($expected) {
576 $this->assertSame($expected, $actual);
Customizing of pimple-DIC for ILIAS.
testGetFirstVisiblePostId()
testIsNotificationEnabledNoResult()
withIgnoredQuery(InvocationMocker $mock,... $expected)
testGetPostRootIdFailed()
testIsNotificationEnabledInvalidIds()
testDisableNotification()
testIsNotificationEnabled()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
testCountActivePostsFailed()
testGetFirstVisiblePostIdFailed()