4 require_once
'Services/Contact/BuddySystem/test/ilBuddySystemBaseTest.php';
28 $this->getMockBuilder(
'ilAppEventHandler')->disableOriginalConstructor()->setMethods(array(
'raise'))->getMock()
30 $this->
setGlobalVariable(
'ilDB', $this->getMockBuilder(
'ilDBInterface')->getMock());
33 $this->getMockBuilder(
'ilLanguage')
34 ->disableOriginalConstructor()
35 ->setMethods(array(
'txt',
'loadLanguageModule'))
45 $user = $this->getMockBuilder(
'ilObjUser')->disableOriginalConstructor()->setMethods(array(
'getId'))->getMock();
46 $user->expects($this->
once())->method(
'getId')->will($this->returnValue(self::BUDDY_LIST_OWNER_ID));
58 $user = $this->getMockBuilder(
'ilObjUser')->disableOriginalConstructor()->setMethods(array(
'getId'))->getMock();
59 $user->expects($this->
once())->method(
'getId')->will($this->returnValue(ANONYMOUS_USER_ID));
80 $this->assertEquals(
$buddylist, $other_buddylist);
88 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
89 $repo->expects($this->exactly(1))->method(
'getAll')->willReturn(array());
95 $this->assertEmpty(
$buddylist->getRelations());
108 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
109 $repo->expects($this->exactly(1))->method(
'getAll')->willReturn($relations);
125 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
126 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
129 $expected_relation->getBuddyUserId() => $expected_relation
132 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
133 $db->expects($this->exactly(2))->method(
'queryF');
134 $db->expects($this->exactly(2))->method(
'fetchAssoc')->will($this->returnValue(array(
139 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
140 $repo->expects($this->
once())->method(
'getAll')->willReturn($relations);
141 $repo->expects($this->exactly(3))->method(
'save')->with($expected_relation);
147 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
160 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
161 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
164 $expected_relation->getBuddyUserId() => $expected_relation
167 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
168 $db->expects($this->
once())->method(
'queryF');
169 $db->expects($this->
once())->method(
'fetchAssoc')->will($this->returnValue(array(
174 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
175 $repo->expects($this->
once())->method(
'getAll')->willReturn($relations);
176 $repo->expects($this->exactly(1))->method(
'save')->with($expected_relation);
182 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
193 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
194 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
197 $expected_relation->getBuddyUserId() => $expected_relation
200 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
201 $db->expects($this->any())->method(
'queryF');
202 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(array(
207 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
208 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
209 $repo->expects($this->any())->method(
'save')->with($expected_relation);
217 $other_buddylist->reset();
218 $other_buddylist->setRepository($repo);
219 $other_buddylist->link($expected_relation);
229 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
230 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
233 $expected_relation->getBuddyUserId() => $expected_relation
236 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
237 $db->expects($this->
once())->method(
'queryF');
238 $db->expects($this->
once())->method(
'fetchAssoc')->will($this->returnValue(array(
243 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
244 $repo->expects($this->
once())->method(
'getAll')->willReturn($relations);
245 $repo->expects($this->exactly(1))->method(
'save')->with($expected_relation);
251 $relation =
$buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
262 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
263 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
266 $expected_relation->getBuddyUserId() => $expected_relation
269 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
270 $db->expects($this->any())->method(
'queryF');
271 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(array(
276 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
277 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
278 $repo->expects($this->any())->method(
'save')->with($expected_relation);
286 $other_buddylist->reset();
287 $other_buddylist->setRepository($repo);
288 $other_buddylist->ignore($expected_relation);
298 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
299 $expected_relation->setBuddyUserId(ANONYMOUS_USER_ID);
301 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
302 $repo->expects($this->never())->method(
'getAll')->willReturn(array());
303 $repo->expects($this->never())->method(
'save');
318 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
319 $expected_relation->setBuddyUserId(-3);
321 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
322 $db->expects($this->
once())->method(
'queryF');
323 $db->expects($this->
once())->method(
'fetchAssoc')->will($this->returnValue(null));
326 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
327 $repo->expects($this->never())->method(
'getAll')->willReturn(array());
328 $repo->expects($this->never())->method(
'save');
341 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
342 $repo->expects($this->
once())->method(
'destroy');
355 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
356 $repo->expects($this->
once())->method(
'getAll')->willReturn(array());
361 $this->assertInstanceOf(
'ilBuddySystemUnlinkedRelationState',
$buddylist->getRelationByUserId(-3)->getState());
371 $buddylist->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
372 $this->assertEquals(self::BUDDY_LIST_BUDDY_ID,
$buddylist->getOwnerId());
374 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
375 $repo->expects($this->never())->method(
'getAll')->willReturn(array());
377 $this->assertEquals($repo,
$buddylist->getRepository());
394 $relations = array();
397 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
398 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
399 $relations[self::BUDDY_LIST_BUDDY_ID] = $relation;
402 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 1);
403 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
404 $relations[self::BUDDY_LIST_BUDDY_ID + 1] = $relation;
407 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 2);
408 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
409 $relations[self::BUDDY_LIST_BUDDY_ID + 2] = $relation;
412 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 3);
413 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
414 $relations[self::BUDDY_LIST_BUDDY_ID + 3] = $relation;
417 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
418 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 4);
419 $relations[self::BUDDY_LIST_BUDDY_ID + 4] = $relation;
422 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID + 5);
423 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
424 $relations[self::BUDDY_LIST_BUDDY_ID + 5] = $relation;
427 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
428 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 6);
429 $relations[self::BUDDY_LIST_BUDDY_ID + 6] = $relation;
432 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
433 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID + 7);
434 $relations[self::BUDDY_LIST_BUDDY_ID + 7] = $relation;
436 $repo = $this->getMockBuilder(
'ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
437 $repo->expects($this->any())->method(
'getAll')->willReturn($relations);
440 $this->assertCount(3,
$buddylist->getLinkedRelations());
441 $this->assertCount(1,
$buddylist->getRequestRelationsForOwner());
442 $this->assertCount(1,
$buddylist->getRequestRelationsByOwner());
443 $this->assertCount(1,
$buddylist->getIgnoredRelationsForOwner());
444 $this->assertCount(2,
$buddylist->getIgnoredRelationsByOwner());
445 $this->assertEquals(array_keys($relations),
$buddylist->getRelationUserIds());
472 $object =
new ReflectionObject($relation);
473 $property = $object->getProperty(
'prior_state');
474 $property->setAccessible(
true);
476 $property->setValue($relation, $state);
484 $this->
assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
491 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
492 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
504 $this->
assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
511 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
512 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
524 $this->
assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
531 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
532 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
544 $this->
assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
551 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
552 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
556 $db = $this->getMockBuilder(
'ilDBInterface')->getMock();
557 $db->expects($this->any())->method(
'fetchAssoc')->will($this->returnValue(array(
570 $this->
assertException(ilBuddySystemRelationStateTransitionException::class);
577 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
578 $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
testRelationRequestCannotBeIgnoredByTheRelationOwner()
ilBuddySystemException
testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked()
ilBuddySystemRelationStateAlreadyGivenException
testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed()
testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested()
ilBuddySystemRelationStateAlreadyGivenException
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
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.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
testExceptionIsThrownWhenNonNumericOwnerIdIsPassed()
InvalidArgumentException
testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly()
Class ilBuddySystemRelation.
testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly()
setGlobalVariable($name, $value)
testDifferentRelationStatesCanBeRetrieved()
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
testRelationRequestCanBeIgnoredByTheRelationTarget()
testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()
ilBuddySystemRelationStateTransitionException
Interface ilBuddySystemRelationState.
testRelationRequestCanBeApprovedByTheRelationTarget()
testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()
ilBuddySystemRelationStateAlreadyGivenException