19 declare(strict_types=1);
26 protected function setUp(): void
32 $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->onlyMethods([
'raise'])->getMock()
37 $this->getMockBuilder(ilLanguage::class)
38 ->disableOriginalConstructor()
39 ->onlyMethods([
'txt',
'loadLanguageModule'])
46 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods([
'getId'])->getMock();
47 $user->expects($this->once())->method(
'getId')->willReturn(self::BUDDY_LIST_OWNER_ID);
55 $this->expectException(ilBuddySystemException::class);
57 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods([
'getId'])->getMock();
69 self::BUDDY_LIST_BUDDY_ID,
70 self::BUDDY_LIST_OWNER_ID,
76 self::BUDDY_LIST_BUDDY_ID,
77 self::BUDDY_LIST_OWNER_ID,
88 $this->assertEquals($buddyList, $otherBuddylist);
93 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
94 $repo->expects($this->once())->method(
'getAll')->willReturn([]);
98 $buddyList->setRepository($repo);
100 $this->assertEmpty($buddyList->getRelations());
108 self::BUDDY_LIST_BUDDY_ID,
109 self::BUDDY_LIST_OWNER_ID,
115 self::BUDDY_LIST_BUDDY_ID,
116 self::BUDDY_LIST_OWNER_ID,
122 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
123 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
127 $buddyList->setRepository($repo);
137 self::BUDDY_LIST_BUDDY_ID,
138 self::BUDDY_LIST_OWNER_ID,
142 $expectedRelation = $expectedRelation->withUsrId(self::BUDDY_LIST_OWNER_ID);
143 $expectedRelation = $expectedRelation->withBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
146 $expectedRelation->getBuddyUsrId() => $expectedRelation
149 $db = $this->createMock(ilDBInterface::class);
150 $db->expects($this->exactly(2))->method(
'queryF');
151 $db->expects($this->exactly(2))->method(
'fetchAssoc')->willReturn([
156 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
157 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
158 $repo->expects($this->exactly(3))->method(
'save')->with($expectedRelation);
162 $buddyList->setRepository($repo);
164 $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
172 $this->expectException(ilBuddySystemException::class);
176 self::BUDDY_LIST_OWNER_ID,
177 self::BUDDY_LIST_BUDDY_ID,
183 $expectedRelation->getBuddyUsrId() => $expectedRelation
186 $db = $this->createMock(ilDBInterface::class);
187 $db->expects($this->once())->method(
'queryF');
188 $db->expects($this->once())->method(
'fetchAssoc')->willReturn([
193 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
194 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
195 $repo->expects($this->once())->method(
'save')->with($expectedRelation);
199 $buddyList->setRepository($repo);
201 $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
210 self::BUDDY_LIST_OWNER_ID,
211 self::BUDDY_LIST_BUDDY_ID,
217 $expectedRelation->getBuddyUsrId() => $expectedRelation
220 $db = $this->createMock(ilDBInterface::class);
221 $db->method(
'queryF');
222 $db->method(
'fetchAssoc')->willReturn([
227 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
228 $repo->method(
'getAll')->willReturn($relations);
229 $repo->method(
'save')->with($expectedRelation);
233 $buddyList->setRepository($repo);
234 $buddyList->request($expectedRelation);
237 $other_buddylist->reset();
238 $other_buddylist->setRepository($repo);
239 $other_buddylist->link($expectedRelation);
246 $this->expectException(ilBuddySystemException::class);
250 self::BUDDY_LIST_OWNER_ID,
251 self::BUDDY_LIST_BUDDY_ID,
257 $expectedRelation->getBuddyUsrId() => $expectedRelation
260 $db = $this->createMock(ilDBInterface::class);
261 $db->expects($this->once())->method(
'queryF');
262 $db->expects($this->once())->method(
'fetchAssoc')->willReturn([
267 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
268 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
269 $repo->expects($this->once())->method(
'save')->with($expectedRelation);
273 $buddyList->setRepository($repo);
275 $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
284 self::BUDDY_LIST_OWNER_ID,
285 self::BUDDY_LIST_BUDDY_ID,
291 $expectedRelation->getBuddyUsrId() => $expectedRelation
294 $db = $this->createMock(ilDBInterface::class);
295 $db->method(
'queryF');
296 $db->method(
'fetchAssoc')->willReturn([
301 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
302 $repo->method(
'getAll')->willReturn($relations);
303 $repo->method(
'save')->with($expectedRelation);
307 $buddyList->setRepository($repo);
308 $buddyList->request($expectedRelation);
311 $other_buddylist->reset();
312 $other_buddylist->setRepository($repo);
313 $other_buddylist->ignore($expectedRelation);
320 $this->expectException(ilBuddySystemException::class);
324 self::BUDDY_LIST_OWNER_ID,
330 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
331 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
332 $repo->expects($this->never())->method(
'save');
336 $buddyList->setRepository($repo);
337 $buddyList->request($expectedRelation);
342 $this->expectException(ilBuddySystemException::class);
346 self::BUDDY_LIST_BUDDY_ID,
347 self::BUDDY_LIST_OWNER_ID,
351 $expectedRelation = $expectedRelation->withUsrId(self::BUDDY_LIST_OWNER_ID);
352 $expectedRelation = $expectedRelation->withBuddyUsrId(-3);
354 $db = $this->createMock(ilDBInterface::class);
355 $db->expects($this->once())->method(
'queryF');
356 $db->expects($this->once())->method(
'fetchAssoc')->willReturn(
null);
359 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
360 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
361 $repo->expects($this->never())->method(
'save');
365 $buddyList->setRepository($repo);
366 $buddyList->request($expectedRelation);
373 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
374 $repo->expects($this->once())->method(
'destroy');
378 $buddyList->setRepository($repo);
379 $buddyList->destroy();
384 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
385 $repo->expects($this->once())->method(
'getAll')->willReturn([]);
389 $buddyList->setRepository($repo);
390 $this->assertInstanceOf(ilBuddySystemUnlinkedRelationState::class, $buddyList->getRelationByUserId(-3)->getState());
397 $buddyList->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
398 $this->assertSame(self::BUDDY_LIST_BUDDY_ID, $buddyList->getOwnerId());
400 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
401 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
402 $buddyList->setRepository($repo);
403 $this->assertEquals($repo, $buddyList->getRepository());
408 self::BUDDY_LIST_BUDDY_ID,
409 self::BUDDY_LIST_OWNER_ID,
427 self::BUDDY_LIST_OWNER_ID,
428 self::BUDDY_LIST_BUDDY_ID,
432 $relations[self::BUDDY_LIST_BUDDY_ID] =
$relation;
436 self::BUDDY_LIST_BUDDY_ID + 1,
437 self::BUDDY_LIST_OWNER_ID,
441 $relations[self::BUDDY_LIST_BUDDY_ID + 1] =
$relation;
445 self::BUDDY_LIST_BUDDY_ID + 2,
446 self::BUDDY_LIST_OWNER_ID,
450 $relations[self::BUDDY_LIST_BUDDY_ID + 2] =
$relation;
454 self::BUDDY_LIST_BUDDY_ID + 3,
455 self::BUDDY_LIST_OWNER_ID,
459 $relations[self::BUDDY_LIST_BUDDY_ID + 3] =
$relation;
463 self::BUDDY_LIST_OWNER_ID,
464 self::BUDDY_LIST_BUDDY_ID + 4,
468 $relations[self::BUDDY_LIST_BUDDY_ID + 4] =
$relation;
472 self::BUDDY_LIST_BUDDY_ID + 5,
473 self::BUDDY_LIST_OWNER_ID,
477 $relations[self::BUDDY_LIST_BUDDY_ID + 5] =
$relation;
481 self::BUDDY_LIST_OWNER_ID,
482 self::BUDDY_LIST_BUDDY_ID + 6,
486 $relations[self::BUDDY_LIST_BUDDY_ID + 6] =
$relation;
490 self::BUDDY_LIST_OWNER_ID,
491 self::BUDDY_LIST_BUDDY_ID + 7,
495 $relations[self::BUDDY_LIST_BUDDY_ID + 7] =
$relation;
497 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
498 $repo->method(
'getAll')->willReturn($relations);
499 $buddyList->setRepository($repo);
501 $this->assertCount(3, $buddyList->getLinkedRelations());
502 $this->assertCount(1, $buddyList->getRequestRelationsForOwner());
503 $this->assertCount(1, $buddyList->getRequestRelationsByOwner());
504 $this->assertCount(1, $buddyList->getIgnoredRelationsForOwner());
505 $this->assertCount(2, $buddyList->getIgnoredRelationsByOwner());
506 $this->assertEquals(array_keys($relations), $buddyList->getRelationUserIds());
513 $object =
new ReflectionObject($relation);
514 $property = $object->getProperty(
'priorState');
516 $property->setValue($relation, $state);
521 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
530 self::BUDDY_LIST_OWNER_ID,
531 self::BUDDY_LIST_BUDDY_ID,
543 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
552 self::BUDDY_LIST_BUDDY_ID,
553 self::BUDDY_LIST_OWNER_ID,
565 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
574 self::BUDDY_LIST_OWNER_ID,
575 self::BUDDY_LIST_BUDDY_ID,
587 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
596 self::BUDDY_LIST_BUDDY_ID,
597 self::BUDDY_LIST_OWNER_ID,
604 $db = $this->createMock(ilDBInterface::class);
605 $db->method(
'fetchAssoc')->willReturn([
615 $this->expectException(ilBuddySystemRelationStateTransitionException::class);
624 self::BUDDY_LIST_OWNER_ID,
625 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)
const int BUDDY_LIST_OWNER_ID
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class ilBuddySystemLinkedState.
testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()
setGlobalVariable(string $name, mixed $value)
testInstanceCanBeCreatedByGlobalUserObject()
Class ilBuddySystemRequestedRelationState.
testRelationCannotBeRequestedForUnknownUserAccounts()
testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()
const int BUDDY_LIST_BUDDY_ID
testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked()
testRelationRequestCanBeApprovedByTheRelationTarget()
testInstanceByBeCreatedBySingletonMethod()
testListIsInitiallyEmpty()
testValuesCanBeFetchedByGettersWhenSetBySetters()
testInstanceCannotBeCreatedByAnonymousGlobalUserObject()
testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested()
testRelationRequestCannotBeIgnoredByTheRelationOwner()
static getInstanceByGlobalUser(?ilObjUser $user=null)