1 <?php declare(strict_types=1);
4 require_once
'Services/Contact/BuddySystem/test/ilBuddySystemBaseTest.php';
26 $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->setMethods([
'raise'])->getMock()
28 $this->
setGlobalVariable(
'ilDB', $this->getMockBuilder(ilDBInterface::class)->getMock());
31 $this->getMockBuilder(ilLanguage::class)
32 ->disableOriginalConstructor()
33 ->setMethods([
'txt',
'loadLanguageModule'])
43 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->setMethods([
'getId'])->getMock();
44 $user->expects($this->once())->method(
'getId')->will($this->returnValue(self::BUDDY_LIST_OWNER_ID));
55 $this->expectException(ilBuddySystemException::class);
56 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->setMethods([
'getId'])->getMock();
57 $user->expects($this->once())->method(
'getId')->will($this->returnValue(ANONYMOUS_USER_ID));
78 $this->assertEquals(
$buddyList, $otherBuddylist);
86 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
87 $repo->expects($this->exactly(1))->method(
'getAll')->willReturn([]);
93 $this->assertEmpty(
$buddyList->getRelations());
106 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
107 $repo->expects($this->exactly(1))->method(
'getAll')->willReturn($relations);
123 $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
124 $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
127 $expectedRelation->getBuddyUsrId() => $expectedRelation
130 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
131 $db->expects($this->exactly(2))->method(
'queryF');
132 $db->expects($this->exactly(2))->method(
'fetchAssoc')->will($this->returnValue([
137 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
138 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
139 $repo->expects($this->exactly(3))->method(
'save')->with($expectedRelation);
145 $relation =
$buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
156 $this->expectException(ilBuddySystemException::class);
158 $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
159 $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
162 $expectedRelation->getBuddyUsrId() => $expectedRelation
165 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
166 $db->expects($this->once())->method(
'queryF');
167 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue([
172 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
173 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
174 $repo->expects($this->exactly(1))->method(
'save')->with($expectedRelation);
180 $relation =
$buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
191 $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
192 $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
195 $expectedRelation->getBuddyUsrId() => $expectedRelation
198 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
199 $db->expects($this->any())->method(
'queryF');
200 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue([
205 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
206 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
207 $repo->expects($this->any())->method(
'save')->with($expectedRelation);
215 $other_buddylist->reset();
216 $other_buddylist->setRepository($repo);
217 $other_buddylist->link($expectedRelation);
225 $this->expectException(ilBuddySystemException::class);
227 $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
228 $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
231 $expectedRelation->getBuddyUsrId() => $expectedRelation
234 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
235 $db->expects($this->once())->method(
'queryF');
236 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue([
241 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
242 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
243 $repo->expects($this->exactly(1))->method(
'save')->with($expectedRelation);
249 $relation =
$buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
260 $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
261 $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
264 $expectedRelation->getBuddyUsrId() => $expectedRelation
267 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
268 $db->expects($this->any())->method(
'queryF');
269 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue([
274 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
275 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
276 $repo->expects($this->any())->method(
'save')->with($expectedRelation);
284 $other_buddylist->reset();
285 $other_buddylist->setRepository($repo);
286 $other_buddylist->ignore($expectedRelation);
294 $this->expectException(ilBuddySystemException::class);
296 $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
297 $expectedRelation->setBuddyUsrId(ANONYMOUS_USER_ID);
299 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
300 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
301 $repo->expects($this->never())->method(
'save');
314 $this->expectException(ilBuddySystemException::class);
316 $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
317 $expectedRelation->setBuddyUsrId(-3);
319 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
320 $db->expects($this->once())->method(
'queryF');
321 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue(null));
324 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
325 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
326 $repo->expects($this->never())->method(
'save');
339 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
340 $repo->expects($this->once())->method(
'destroy');
353 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
354 $repo->expects($this->once())->method(
'getAll')->willReturn([]);
359 $this->assertInstanceOf(
'ilBuddySystemUnlinkedRelationState',
$buddyList->getRelationByUserId(-3)->getState());
369 $buddyList->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
370 $this->assertEquals(self::BUDDY_LIST_BUDDY_ID,
$buddyList->getOwnerId());
372 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
373 $repo->expects($this->never())->method(
'getAll')->willReturn([]);
375 $this->assertEquals($repo,
$buddyList->getRepository());
395 $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
396 $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
397 $relations[self::BUDDY_LIST_BUDDY_ID] = $relation;
400 $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID + 1);
401 $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
402 $relations[self::BUDDY_LIST_BUDDY_ID + 1] = $relation;
405 $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID + 2);
406 $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
407 $relations[self::BUDDY_LIST_BUDDY_ID + 2] = $relation;
410 $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID + 3);
411 $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
412 $relations[self::BUDDY_LIST_BUDDY_ID + 3] = $relation;
415 $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
416 $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID + 4);
417 $relations[self::BUDDY_LIST_BUDDY_ID + 4] = $relation;
420 $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID + 5);
421 $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
422 $relations[self::BUDDY_LIST_BUDDY_ID + 5] = $relation;
425 $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
426 $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID + 6);
427 $relations[self::BUDDY_LIST_BUDDY_ID + 6] = $relation;
430 $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
431 $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID + 7);
432 $relations[self::BUDDY_LIST_BUDDY_ID + 7] = $relation;
434 $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
435 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
438 $this->assertCount(3,
$buddyList->getLinkedRelations());
439 $this->assertCount(1,
$buddyList->getRequestRelationsForOwner());
440 $this->assertCount(1,
$buddyList->getRequestRelationsByOwner());
441 $this->assertCount(1,
$buddyList->getIgnoredRelationsForOwner());
442 $this->assertCount(2,
$buddyList->getIgnoredRelationsByOwner());
443 $this->assertEquals(array_keys($relations),
$buddyList->getRelationUserIds());
455 $object =
new ReflectionObject($relation);
456 $property = $object->getProperty(
'priorState');
457 $property->setAccessible(
true);
459 $property->setValue($relation, $state);
467 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
474 $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
475 $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
487 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
494 $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID);
495 $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
507 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
514 $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
515 $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
527 $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
534 $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID);
535 $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
539 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
540 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue([
553 $this->expectException(ilBuddySystemRelationStateTransitionException::class);
560 $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
561 $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
Class ilBuddySystemIgnoredRequestRelationState.
testRelationCannotBeRequestedForAnonymous()
const BUDDY_LIST_OWNER_ID
testInstanceCanBeCreatedByGlobalUserObject()
static getInstanceByGlobalUser()
testValuesCanBeFetchedByGettersWhenSetBySetters()
testListIsInitiallyEmpty()
testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored()
Class ilBuddySystemUnlinkedRelationState.
testInstanceCannotBeCreatedByAnonymousGlobalUserObject()
testRelationRequestCannotBeIgnoredByTheRelationOwner()
testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked()
testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed()
static getInstanceByUserId(int $usrId)
testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested()
Class ilBuddySystemLinkedState.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
const BUDDY_LIST_BUDDY_ID
testRelationRequestCannotBeApprovedByTheRelationOwner()
testRelationCannotBeRequestedForUnknownUserAccounts()
testInstanceByBeCreatedBySingletonMethod()
Class ilBuddySystemRequestedRelationState.
testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAnUnknownBuddyId()
testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly()
Class ilBuddySystemRelation.
setGlobalVariable(string $name, $value)
testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly()
testDifferentRelationStatesCanBeRetrieved()
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
testRelationRequestCanBeIgnoredByTheRelationTarget()
testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()
Interface ilBuddySystemRelationState.
testRelationRequestCanBeApprovedByTheRelationTarget()
testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()