4 require_once
'Services/Contact/BuddySystem/test/ilBuddySystemBaseTest.php';
32 $DIC[$name] =
function ($c) use ($name) {
44 $this->getMockBuilder(
'ilAppEventHandler')->disableOriginalConstructor()->setMethods(
array(
'raise'))->getMock()
46 $this->
setGlobalVariable(
'ilDB', $this->getMockBuilder(
'ilDBInterface')->getMock());
49 $this->getMockBuilder(
'ilLanguage')
50 ->disableOriginalConstructor()
51 ->setMethods(
array(
'txt',
'loadLanguageModule'))
61 $user = $this->getMockBuilder(
'ilObjUser')->disableOriginalConstructor()->setMethods(
array(
'getId'))->getMock();
62 $user->expects($this->once())->method(
'getId')->will($this->returnValue(self::BUDDY_LIST_OWNER_ID));
74 $user = $this->getMockBuilder(
'ilObjUser')->disableOriginalConstructor()->setMethods(
array(
'getId'))->getMock();
75 $user->expects($this->once())->method(
'getId')->will($this->returnValue(ANONYMOUS_USER_ID));
96 $this->assertEquals(
$buddylist, $other_buddylist);
104 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
105 $repo->expects($this->exactly(1))->method(
'getAll')->willReturn(
array());
111 $this->assertEmpty(
$buddylist->getRelations());
124 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
125 $repo->expects($this->exactly(1))->method(
'getAll')->willReturn($relations);
141 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
142 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
145 $expected_relation->getBuddyUserId() => $expected_relation
148 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
149 $db->expects($this->exactly(2))->method(
'queryF');
150 $db->expects($this->exactly(2))->method(
'fetchAssoc')->will($this->returnValue(
array(
155 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
156 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
157 $repo->expects($this->exactly(3))->method(
'save')->with($expected_relation);
163 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
176 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
177 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
180 $expected_relation->getBuddyUserId() => $expected_relation
183 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
184 $db->expects($this->once())->method(
'queryF');
185 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue(
array(
190 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
191 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
192 $repo->expects($this->exactly(1))->method(
'save')->with($expected_relation);
198 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
209 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
210 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
213 $expected_relation->getBuddyUserId() => $expected_relation
216 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
217 $db->expects($this->any())->method(
'queryF');
218 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(
array(
223 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
224 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
225 $repo->expects($this->any())->method(
'save')->with($expected_relation);
233 $other_buddylist->reset();
234 $other_buddylist->setRepository($repo);
235 $other_buddylist->link($expected_relation);
245 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
246 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
249 $expected_relation->getBuddyUserId() => $expected_relation
252 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
253 $db->expects($this->once())->method(
'queryF');
254 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue(
array(
259 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
260 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
261 $repo->expects($this->exactly(1))->method(
'save')->with($expected_relation);
267 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
278 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
279 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
282 $expected_relation->getBuddyUserId() => $expected_relation
285 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
286 $db->expects($this->any())->method(
'queryF');
287 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(
array(
292 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
293 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
294 $repo->expects($this->any())->method(
'save')->with($expected_relation);
302 $other_buddylist->reset();
303 $other_buddylist->setRepository($repo);
304 $other_buddylist->ignore($expected_relation);
314 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
315 $expected_relation->setBuddyUserId(ANONYMOUS_USER_ID);
317 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
318 $repo->expects($this->never())->method(
'getAll')->willReturn(
array());
319 $repo->expects($this->never())->method(
'save');
334 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
335 $expected_relation->setBuddyUserId(-3);
337 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
338 $db->expects($this->once())->method(
'queryF');
339 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue(null));
342 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
343 $repo->expects($this->never())->method(
'getAll')->willReturn(
array());
344 $repo->expects($this->never())->method(
'save');
357 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
358 $repo->expects($this->once())->method(
'destroy');
371 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
372 $repo->expects($this->once())->method(
'getAll')->willReturn(
array());
377 $this->assertInstanceOf(
'ilBuddySystemUnlinkedRelationState',
$buddylist->getRelationByUserId(-3)->getState());
387 $buddylist->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
388 $this->assertEquals(self::BUDDY_LIST_BUDDY_ID,
$buddylist->getOwnerId());
390 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
391 $repo->expects($this->never())->method(
'getAll')->willReturn(
array());
393 $this->assertEquals($repo,
$buddylist->getRepository());
410 $relations =
array();
413 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
414 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
415 $relations[self::BUDDY_LIST_BUDDY_ID] = $relation;
418 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 1);
419 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
420 $relations[self::BUDDY_LIST_BUDDY_ID + 1] = $relation;
423 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 2);
424 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
425 $relations[self::BUDDY_LIST_BUDDY_ID + 2] = $relation;
428 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 3);
429 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
430 $relations[self::BUDDY_LIST_BUDDY_ID + 3] = $relation;
433 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
434 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 4);
435 $relations[self::BUDDY_LIST_BUDDY_ID + 4] = $relation;
438 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 5);
439 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
440 $relations[self::BUDDY_LIST_BUDDY_ID + 5] = $relation;
443 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
444 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 6);
445 $relations[self::BUDDY_LIST_BUDDY_ID + 6] = $relation;
448 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
449 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 7);
450 $relations[self::BUDDY_LIST_BUDDY_ID + 7] = $relation;
452 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
453 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
456 $this->assertCount(3,
$buddylist->getLinkedRelations());
457 $this->assertCount(1,
$buddylist->getRequestRelationsForOwner());
458 $this->assertCount(1,
$buddylist->getRequestRelationsByOwner());
459 $this->assertCount(1,
$buddylist->getIgnoredRelationsForOwner());
460 $this->assertCount(2,
$buddylist->getIgnoredRelationsByOwner());
461 $this->assertEquals(array_keys($relations),
$buddylist->getRelationUserIds());
488 $object =
new ReflectionObject($relation);
489 $property = $object->getProperty(
'prior_state');
490 $property->setAccessible(
true);
492 $property->setValue($relation, $state);
500 $this->
assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
507 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
508 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
520 $this->
assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
527 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
528 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
540 $this->
assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
547 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
548 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
560 $this->
assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
567 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
568 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
572 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
573 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(
array(
586 $this->
assertException(ilBuddySystemRelationStateTransitionException::class);
593 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
594 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
Class ilBuddySystemIgnoredRequestRelationState.
testRelationCannotBeRequestedForAnonymous()
ilBuddySystemException
const BUDDY_LIST_OWNER_ID
testInstanceCanBeCreatedByGlobalUserObject()
static getInstanceByGlobalUser()
testValuesCanBeFetchedByGettersWhenSetBySetters()
assertException($exception_class)
testListIsInitiallyEmpty()
testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored()
ilBuddySystemRelationStateAlreadyGivenException
Class ilBuddySystemUnlinkedRelationState.
testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAUknownBuddyId()
testInstanceCannotBeCreatedByAnonymousGlobalUserObject()
ilBuddySystemException
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
testRelationRequestCannotBeIgnoredByTheRelationOwner()
ilBuddySystemException
testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked()
ilBuddySystemRelationStateAlreadyGivenException
testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed()
testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested()
ilBuddySystemRelationStateAlreadyGivenException
Class ilBuddySystemLinkedState.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
const BUDDY_LIST_BUDDY_ID
testRelationRequestCannotBeApprovedByTheRelationOwner()
ilBuddySystemException
static getInstanceByUserId($usr_id)
setGlobalVariable($name, $value)
testRelationCannotBeRequestedForUnknownUserAccounts()
ilBuddySystemException
testInstanceByBeCreatedBySingletonMethod()
testExceptionIsThrownWhenRelationIsRequestedForANonNumericUserId()
InvalidArgumentException
Class ilBuddySystemRequestedRelationState.
Create styles array
The data for the language used.
testExceptionIsThrownWhenNonNumericOwnerIdIsPassed()
InvalidArgumentException
testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly()
Class ilBuddySystemRelation.
testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly()
testDifferentRelationStatesCanBeRetrieved()
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
testRelationRequestCanBeIgnoredByTheRelationTarget()
testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()
ilBuddySystemRelationStateTransitionException
Interface ilBuddySystemRelationState.
testRelationRequestCanBeApprovedByTheRelationTarget()
testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()
ilBuddySystemRelationStateAlreadyGivenException