24 $GLOBALS[
'ilAppEventHandler'] = $this->getMockBuilder(
'ilAppEventHandler')->disableOriginalConstructor()->setMethods(array(
'raise'))->getMock();
32 $user = $this->getMockBuilder(
'ilObjUser')->disableOriginalConstructor()->setMethods(array(
'getId'))->getMock();
33 $user->expects($this->once())->method(
'getId')->will($this->returnValue(self::BUDDY_LIST_OWNER_ID));
36 ilBuddyList::getInstanceByGlobalUser();
44 $user = $this->getMockBuilder(
'ilObjUser')->disableOriginalConstructor()->setMethods(array(
'getId'))->getMock();
45 $user->expects($this->once())->method(
'getId')->will($this->returnValue(ANONYMOUS_USER_ID));
48 ilBuddyList::getInstanceByGlobalUser();
66 $this->assertEquals(
$buddylist, $other_buddylist);
74 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
75 $repo->expects($this->exactly(1))->method(
'getAll')->willReturn(array());
81 $this->assertEmpty(
$buddylist->getRelations());
94 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
95 $repo->expects($this->exactly(1))->method(
'getAll')->willReturn($relations);
111 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
112 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
115 $expected_relation->getBuddyUserId() => $expected_relation
118 $db = $this->getMockBuilder(
'ilDBMySQL')->disableOriginalConstructor()->setMethods(array(
'queryF',
'fetchAssoc'))->getMock();
119 $db->expects($this->exactly(2))->method(
'queryF');
120 $db->expects($this->exactly(2))->method(
'fetchAssoc')->will($this->returnValue(array(
125 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
126 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
127 $repo->expects($this->exactly(3))->method(
'save')->with($expected_relation);
133 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
144 $this->assertException(ilBuddySystemException::class);
146 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
147 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
150 $expected_relation->getBuddyUserId() => $expected_relation
153 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
154 $db->expects($this->once())->method(
'queryF');
155 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue(array(
158 $this->setGlobalVariable(
'ilDB', $db);
160 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
161 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
162 $repo->expects($this->exactly(1))->method(
'save')->with($expected_relation);
168 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
179 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
180 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
183 $expected_relation->getBuddyUserId() => $expected_relation
186 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
187 $db->expects($this->any())->method(
'queryF');
188 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(array(
191 $this->setGlobalVariable(
'ilDB', $db);
193 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
194 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
195 $repo->expects($this->any())->method(
'save')->with($expected_relation);
203 $other_buddylist->reset();
204 $other_buddylist->setRepository($repo);
205 $other_buddylist->link($expected_relation);
214 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
215 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
218 $expected_relation->getBuddyUserId() => $expected_relation
221 $db = $this->getMockBuilder(
'ilDBMySQL')->disableOriginalConstructor()->setMethods(array(
'queryF',
'fetchAssoc'))->getMock();
222 $db->expects($this->once())->method(
'queryF');
223 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue(array(
228 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
229 $repo->expects($this->once())->method(
'getAll')->willReturn($relations);
230 $repo->expects($this->exactly(1))->method(
'save')->with($expected_relation);
236 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
247 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
248 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
251 $expected_relation->getBuddyUserId() => $expected_relation
254 $db = $this->getMockBuilder(
'ilDBMySQL')->disableOriginalConstructor()->setMethods(array(
'queryF',
'fetchAssoc'))->getMock();
255 $db->expects($this->any())->method(
'queryF');
256 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(array(
261 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
262 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
263 $repo->expects($this->any())->method(
'save')->with($expected_relation);
271 $other_buddylist->reset();
272 $other_buddylist->setRepository($repo);
273 $other_buddylist->ignore($expected_relation);
282 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
283 $expected_relation->setBuddyUserId(ANONYMOUS_USER_ID);
285 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
286 $repo->expects($this->never())->method(
'getAll')->willReturn(array());
287 $repo->expects($this->never())->method(
'save');
301 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
302 $expected_relation->setBuddyUserId(-3);
304 $db = $this->getMockBuilder(
'ilDBMySQL')->disableOriginalConstructor()->setMethods(array(
'queryF',
'fetchAssoc'))->getMock();
305 $db->expects($this->once())->method(
'queryF');
306 $db->expects($this->once())->method(
'fetchAssoc')->will($this->returnValue(null));
309 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
310 $repo->expects($this->never())->method(
'getAll')->willReturn(array());
311 $repo->expects($this->never())->method(
'save');
324 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
325 $repo->expects($this->once())->method(
'destroy');
338 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
339 $repo->expects($this->once())->method(
'getAll')->willReturn(array());
344 $this->assertInstanceOf(
'ilBuddySystemUnlinkedRelationState',
$buddylist->getRelationByUserId(-3)->getState());
354 $buddylist->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
355 $this->assertEquals(self::BUDDY_LIST_BUDDY_ID,
$buddylist->getOwnerId());
357 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
358 $repo->expects($this->never())->method(
'getAll')->willReturn(array());
360 $this->assertEquals($repo,
$buddylist->getRepository());
377 $relations = array();
380 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
381 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
382 $relations[self::BUDDY_LIST_BUDDY_ID] = $relation;
385 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 1);
386 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
387 $relations[self::BUDDY_LIST_BUDDY_ID + 1] = $relation;
390 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 2);
391 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
392 $relations[self::BUDDY_LIST_BUDDY_ID + 2] = $relation;
395 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 3);
396 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
397 $relations[self::BUDDY_LIST_BUDDY_ID + 3] = $relation;
400 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
401 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 4);
402 $relations[self::BUDDY_LIST_BUDDY_ID + 4] = $relation;
405 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 5);
406 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
407 $relations[self::BUDDY_LIST_BUDDY_ID + 5] = $relation;
410 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
411 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 6);
412 $relations[self::BUDDY_LIST_BUDDY_ID + 6] = $relation;
415 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
416 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 7);
417 $relations[self::BUDDY_LIST_BUDDY_ID + 7] = $relation;
419 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
420 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
423 $this->assertCount(3,
$buddylist->getLinkedRelations());
424 $this->assertCount(1,
$buddylist->getRequestRelationsForOwner());
425 $this->assertCount(1,
$buddylist->getRequestRelationsByOwner());
426 $this->assertCount(1,
$buddylist->getIgnoredRelationsForOwner());
427 $this->assertCount(2,
$buddylist->getIgnoredRelationsByOwner());
428 $this->assertEquals(array_keys($relations),
$buddylist->getRelationUserIds());
453 $object =
new ReflectionObject($relation);
454 $property = $object->getProperty(
'prior_state');
455 $property->setAccessible(
true);
457 $property->setValue($relation, $state);
471 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
472 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
490 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
491 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
509 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
510 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
528 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
529 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
533 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
534 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(array(
547 $this->assertException(ilBuddySystemRelationStateTransitionException::class);
554 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
555 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
Class ilBuddySystemIgnoredRequestRelationState.
testRelationCannotBeRequestedForAnonymous()
ilBuddySystemException
const BUDDY_LIST_OWNER_ID
testInstanceCanBeCreatedByGlobalUserObject()
testValuesCanBeFetchedByGettersWhenSetBySetters()
testListIsInitiallyEmpty()
testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored()
ilBuddySystemRelationStateAlreadyGivenException
Class ilBuddySystemUnlinkedRelationState.
testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAUknownBuddyId()
testInstanceCannotBeCreatedByAnonymousGlobalUserObject()
ilBuddySystemException
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)
testRelationCannotBeRequestedForUnknownUserAccounts()
ilBuddySystemException
testInstanceByBeCreatedBySingletonMethod()
testExceptionIsThrownWhenRelationIsRequestedForANonNumericUserId()
InvalidArgumentException
Class ilBuddySystemRequestedRelationState.
testExceptionIsThrownWhenNonNumericOwnerIdIsPassed()
InvalidArgumentException
testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly()
Class ilBuddySystemRelation.
testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly()
testDifferentRelationStatesCanBeRetrieved()
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
testRelationRequestCanBeIgnoredByTheRelationTarget()
testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()
ilBuddySystemRelationStateTransitionException
Interface ilBuddySystemRelationState.
testRelationRequestCanBeApprovedByTheRelationTarget()
testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()
ilBuddySystemRelationStateAlreadyGivenException