19 declare(strict_types=1);
30 protected function setUp(): void
36 $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->onlyMethods([
'raise'])->getMock()
41 $this->getMockBuilder(ilLanguage::class)
42 ->disableOriginalConstructor()
43 ->onlyMethods([
'txt',
'loadLanguageModule'])
50 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods([
'getId'])->getMock();
51 $user->expects($this->once())->method(
'getId')->willReturn(self::BUDDY_LIST_OWNER_ID);
59 $this->expectException(ilBuddySystemException::class);
61 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods([
'getId'])->getMock();
73 self::BUDDY_LIST_BUDDY_ID,
74 self::BUDDY_LIST_OWNER_ID,
80 self::BUDDY_LIST_BUDDY_ID,
81 self::BUDDY_LIST_OWNER_ID,
92 $this->assertEquals($buddyList, $otherBuddylist);
97 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
98 $repo->expects($this->once())->method(
'getAll')->willReturn([]);
102 $buddyList->setRepository($repo);
104 $this->assertEmpty($buddyList->getRelations());
112 self::BUDDY_LIST_BUDDY_ID,
113 self::BUDDY_LIST_OWNER_ID,
119 self::BUDDY_LIST_BUDDY_ID,
120 self::BUDDY_LIST_OWNER_ID,
126 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
127 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
131 $buddyList->setRepository($repo);
141 self::BUDDY_LIST_BUDDY_ID,
142 self::BUDDY_LIST_OWNER_ID,
146 $expectedRelation = $expectedRelation->withUsrId(self::BUDDY_LIST_OWNER_ID);
147 $expectedRelation = $expectedRelation->withBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
150 $expectedRelation->getBuddyUsrId() => $expectedRelation
153 $db = $this->createMock(ilDBInterface::class);
154 $db->expects($this->exactly(2))->method(
'queryF');
155 $db->expects($this->exactly(2))->method(
'fetchAssoc')->willReturn([
160 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
161 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
162 $repo->expects($this->exactly(3))->method(
'save')->with($expectedRelation);
166 $buddyList->setRepository($repo);
168 $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
176 $this->expectException(ilBuddySystemException::class);
180 self::BUDDY_LIST_OWNER_ID,
181 self::BUDDY_LIST_BUDDY_ID,
187 $expectedRelation->getBuddyUsrId() => $expectedRelation
190 $db = $this->createMock(ilDBInterface::class);
191 $db->expects($this->once())->method(
'queryF');
192 $db->expects($this->once())->method(
'fetchAssoc')->willReturn([
197 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
198 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
199 $repo->expects($this->once())->method(
'save')->with($expectedRelation);
203 $buddyList->setRepository($repo);
205 $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
214 self::BUDDY_LIST_OWNER_ID,
215 self::BUDDY_LIST_BUDDY_ID,
221 $expectedRelation->getBuddyUsrId() => $expectedRelation
224 $db = $this->createMock(ilDBInterface::class);
225 $db->method(
'queryF');
226 $db->method(
'fetchAssoc')->willReturn([
231 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
232 $repo->method(
'getAll')->willReturn($relations);
233 $repo->method(
'save')->with($expectedRelation);
237 $buddyList->setRepository($repo);
238 $buddyList->request($expectedRelation);
241 $other_buddylist->reset();
242 $other_buddylist->setRepository($repo);
243 $other_buddylist->link($expectedRelation);
250 $this->expectException(ilBuddySystemException::class);
254 self::BUDDY_LIST_OWNER_ID,
255 self::BUDDY_LIST_BUDDY_ID,
261 $expectedRelation->getBuddyUsrId() => $expectedRelation
264 $db = $this->createMock(ilDBInterface::class);
265 $db->expects($this->once())->method(
'queryF');
266 $db->expects($this->once())->method(
'fetchAssoc')->willReturn([
271 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
272 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
273 $repo->expects($this->once())->method(
'save')->with($expectedRelation);
277 $buddyList->setRepository($repo);
279 $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
288 self::BUDDY_LIST_OWNER_ID,
289 self::BUDDY_LIST_BUDDY_ID,
295 $expectedRelation->getBuddyUsrId() => $expectedRelation
298 $db = $this->createMock(ilDBInterface::class);
299 $db->method(
'queryF');
300 $db->method(
'fetchAssoc')->willReturn([
305 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
306 $repo->method(
'getAll')->willReturn($relations);
307 $repo->method(
'save')->with($expectedRelation);
311 $buddyList->setRepository($repo);
312 $buddyList->request($expectedRelation);
315 $other_buddylist->reset();
316 $other_buddylist->setRepository($repo);
317 $other_buddylist->ignore($expectedRelation);
324 $this->expectException(ilBuddySystemException::class);
328 self::BUDDY_LIST_OWNER_ID,
334 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
335 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
336 $repo->expects($this->never())->method(
'save');
340 $buddyList->setRepository($repo);
341 $buddyList->request($expectedRelation);
346 $this->expectException(ilBuddySystemException::class);
350 self::BUDDY_LIST_BUDDY_ID,
351 self::BUDDY_LIST_OWNER_ID,
355 $expectedRelation = $expectedRelation->withUsrId(self::BUDDY_LIST_OWNER_ID);
356 $expectedRelation = $expectedRelation->withBuddyUsrId(-3);
358 $db = $this->createMock(ilDBInterface::class);
359 $db->expects($this->once())->method(
'queryF');
360 $db->expects($this->once())->method(
'fetchAssoc')->willReturn(
null);
363 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
364 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
365 $repo->expects($this->never())->method(
'save');
369 $buddyList->setRepository($repo);
370 $buddyList->request($expectedRelation);
377 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
378 $repo->expects($this->once())->method(
'destroy');
382 $buddyList->setRepository($repo);
383 $buddyList->destroy();
388 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
389 $repo->expects($this->once())->method(
'getAll')->willReturn([]);
393 $buddyList->setRepository($repo);
394 $this->assertInstanceOf(ilBuddySystemUnlinkedRelationState::class, $buddyList->getRelationByUserId(-3)->getState());
401 $buddyList->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
402 $this->assertSame(self::BUDDY_LIST_BUDDY_ID, $buddyList->getOwnerId());
404 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
405 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
406 $buddyList->setRepository($repo);
407 $this->assertEquals($repo, $buddyList->getRepository());
412 self::BUDDY_LIST_BUDDY_ID,
413 self::BUDDY_LIST_OWNER_ID,
431 self::BUDDY_LIST_OWNER_ID,
432 self::BUDDY_LIST_BUDDY_ID,
436 $relations[self::BUDDY_LIST_BUDDY_ID] =
$relation;
440 self::BUDDY_LIST_BUDDY_ID + 1,
441 self::BUDDY_LIST_OWNER_ID,
445 $relations[self::BUDDY_LIST_BUDDY_ID + 1] =
$relation;
449 self::BUDDY_LIST_BUDDY_ID + 2,
450 self::BUDDY_LIST_OWNER_ID,
454 $relations[self::BUDDY_LIST_BUDDY_ID + 2] =
$relation;
458 self::BUDDY_LIST_BUDDY_ID + 3,
459 self::BUDDY_LIST_OWNER_ID,
463 $relations[self::BUDDY_LIST_BUDDY_ID + 3] =
$relation;
467 self::BUDDY_LIST_OWNER_ID,
468 self::BUDDY_LIST_BUDDY_ID + 4,
472 $relations[self::BUDDY_LIST_BUDDY_ID + 4] =
$relation;
476 self::BUDDY_LIST_BUDDY_ID + 5,
477 self::BUDDY_LIST_OWNER_ID,
481 $relations[self::BUDDY_LIST_BUDDY_ID + 5] =
$relation;
485 self::BUDDY_LIST_OWNER_ID,
486 self::BUDDY_LIST_BUDDY_ID + 6,
490 $relations[self::BUDDY_LIST_BUDDY_ID + 6] =
$relation;
494 self::BUDDY_LIST_OWNER_ID,
495 self::BUDDY_LIST_BUDDY_ID + 7,
499 $relations[self::BUDDY_LIST_BUDDY_ID + 7] =
$relation;
501 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
502 $repo->method(
'getAll')->willReturn($relations);
503 $buddyList->setRepository($repo);
505 $this->assertCount(3, $buddyList->getLinkedRelations());
506 $this->assertCount(1, $buddyList->getRequestRelationsForOwner());
507 $this->assertCount(1, $buddyList->getRequestRelationsByOwner());
508 $this->assertCount(1, $buddyList->getIgnoredRelationsForOwner());
509 $this->assertCount(2, $buddyList->getIgnoredRelationsByOwner());
510 $this->assertEquals(array_keys($relations), $buddyList->getRelationUserIds());
517 $object =
new ReflectionObject($relation);
518 $property = $object->getProperty(
'priorState');
519 $property->setAccessible(
true);
521 $property->setValue($relation, $state);
526 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
535 self::BUDDY_LIST_OWNER_ID,
536 self::BUDDY_LIST_BUDDY_ID,
548 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
557 self::BUDDY_LIST_BUDDY_ID,
558 self::BUDDY_LIST_OWNER_ID,
570 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
579 self::BUDDY_LIST_OWNER_ID,
580 self::BUDDY_LIST_BUDDY_ID,
592 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
601 self::BUDDY_LIST_BUDDY_ID,
602 self::BUDDY_LIST_OWNER_ID,
609 $db = $this->createMock(ilDBInterface::class);
610 $db->method(
'fetchAssoc')->willReturn([
620 $this->expectException(ilBuddySystemRelationStateTransitionException::class);
629 self::BUDDY_LIST_OWNER_ID,
630 self::BUDDY_LIST_BUDDY_ID,
testRelationCannotBeRequestedForAnonymous()
Class ilBuddySystemIgnoredRequestRelationState.
testRelationRequestCanBeIgnoredByTheRelationTarget()
testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly()
testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly()
testDifferentRelationStatesCanBeRetrieved()
testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored()
Class ilBuddySystemUnlinkedRelationState.
testRelationRequestCannotBeApprovedByTheRelationOwner()
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed()
testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAnUnknownBuddyId()
static getInstanceByUserId(int $usrId)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class ilBuddySystemLinkedState.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()
setGlobalVariable(string $name, mixed $value)
testInstanceCanBeCreatedByGlobalUserObject()
const BUDDY_LIST_BUDDY_ID
Class ilBuddySystemRequestedRelationState.
testRelationCannotBeRequestedForUnknownUserAccounts()
testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()
testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked()
testRelationRequestCanBeApprovedByTheRelationTarget()
testInstanceByBeCreatedBySingletonMethod()
testListIsInitiallyEmpty()
testValuesCanBeFetchedByGettersWhenSetBySetters()
testInstanceCannotBeCreatedByAnonymousGlobalUserObject()
const BUDDY_LIST_OWNER_ID
Interface ilBuddySystemRelationState.
testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested()
testRelationRequestCannotBeIgnoredByTheRelationOwner()
static getInstanceByGlobalUser(?ilObjUser $user=null)