ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilBuddyListTest Class Reference

Class ilBuddyListTest. More...

+ Inheritance diagram for ilBuddyListTest:
+ Collaboration diagram for ilBuddyListTest:

Public Member Functions

 setUp ()
 
 testInstanceCanBeCreatedByGlobalUserObject ()
 
 testInstanceCannotBeCreatedByAnonymousGlobalUserObject ()
 @expectedException ilBuddySystemException More...
 
 testInstanceByBeCreatedBySingletonMethod ()
 
 testListIsInitiallyEmpty ()
 
 testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly ()
 
 testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly ()
 
 testRelationRequestCannotBeApprovedByTheRelationOwner ()
 @expectedException ilBuddySystemException More...
 
 testRelationRequestCanBeApprovedByTheRelationTarget ()
 
 testRelationRequestCannotBeIgnoredByTheRelationOwner ()
 @expectedException ilBuddySystemException More...
 
 testRelationRequestCanBeIgnoredByTheRelationTarget ()
 
 testRelationCannotBeRequestedForAnonymous ()
 @expectedException ilBuddySystemException More...
 
 testRelationCannotBeRequestedForUnknownUserAccounts ()
 @expectedException ilBuddySystemException More...
 
 testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed ()
 
 testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAUknownBuddyId ()
 
 testValuesCanBeFetchedByGettersWhenSetBySetters ()
 
 testDifferentRelationStatesCanBeRetrieved ()
 
 testExceptionIsThrownWhenNonNumericOwnerIdIsPassed ()
 @expectedException InvalidArgumentException More...
 
 testExceptionIsThrownWhenRelationIsRequestedForANonNumericUserId ()
 @expectedException InvalidArgumentException More...
 
 testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked ()
 @expectedException ilBuddySystemRelationStateAlreadyGivenException More...
 
 testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored ()
 @expectedException ilBuddySystemRelationStateAlreadyGivenException More...
 
 testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked ()
 @expectedException ilBuddySystemRelationStateAlreadyGivenException More...
 
 testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested ()
 @expectedException ilBuddySystemRelationStateAlreadyGivenException More...
 
 testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored ()
 @expectedException ilBuddySystemRelationStateTransitionException More...
 

Data Fields

const BUDDY_LIST_OWNER_ID = -1
 
const BUDDY_LIST_BUDDY_ID = -2
 

Protected Attributes

 $buddylist
 

Private Member Functions

 setPriorRelationState (ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
 

Additional Inherited Members

- Protected Member Functions inherited from ilBuddySystemBaseTest
 setGlobalVariable ($name, $value)
 
 assertException ($exception_class)
 

Detailed Description

Class ilBuddyListTest.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 11 of file ilBuddyListTest.php.

Member Function Documentation

◆ setPriorRelationState()

ilBuddyListTest::setPriorRelationState ( ilBuddySystemRelation  $relation,
ilBuddySystemRelationState  $state 
)
finalprivate

Definition at line 470 of file ilBuddyListTest.php.

471 {
472 $object = new ReflectionObject($relation);
473 $property = $object->getProperty('prior_state');
474 $property->setAccessible(true);
475
476 $property->setValue($relation, $state);
477 }
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10

References $state.

Referenced by testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked(), testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored(), testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked(), testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested(), and testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored().

+ Here is the caller graph for this function:

◆ setUp()

ilBuddyListTest::setUp ( )

Definition at line 24 of file ilBuddyListTest.php.

25 {
26 $this->setGlobalVariable(
27 'ilAppEventHandler',
28 $this->getMockBuilder('ilAppEventHandler')->disableOriginalConstructor()->setMethods(array('raise'))->getMock()
29 );
30 $this->setGlobalVariable('ilDB', $this->getMockBuilder('ilDBInterface')->getMock());
31 $this->setGlobalVariable(
32 'lng',
33 $this->getMockBuilder('ilLanguage')
34 ->disableOriginalConstructor()
35 ->setMethods(array('txt', 'loadLanguageModule'))
36 ->getMock()
37 );
38 }

References ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked ( )

@expectedException ilBuddySystemRelationStateAlreadyGivenException

Definition at line 482 of file ilBuddyListTest.php.

483 {
484 $this->assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
485 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
486 $buddylist->reset();
487
489
490 $relation = new ilBuddySystemRelation($state);
491 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
492 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
493
494 $this->setPriorRelationState($relation, $state);
495
496 $buddylist->link($relation);
497 }
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
static getInstanceByUserId($usr_id)
assertException($exception_class)
Class ilBuddySystemRelation.

References $buddylist, $state, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByUserId(), and setPriorRelationState().

+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored ( )

@expectedException ilBuddySystemRelationStateAlreadyGivenException

Definition at line 502 of file ilBuddyListTest.php.

503 {
504 $this->assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
505 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
506 $buddylist->reset();
507
509
510 $relation = new ilBuddySystemRelation($state);
511 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
512 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
513
514 $this->setPriorRelationState($relation, $state);
515
516 $buddylist->ignore($relation);
517 }

References $buddylist, $state, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByUserId(), and setPriorRelationState().

+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked ( )

@expectedException ilBuddySystemRelationStateAlreadyGivenException

Definition at line 522 of file ilBuddyListTest.php.

523 {
524 $this->assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
525 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
526 $buddylist->reset();
527
529
530 $relation = new ilBuddySystemRelation($state);
531 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
532 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
533
534 $this->setPriorRelationState($relation, $state);
535
536 $buddylist->unlink($relation);
537 }

References $buddylist, $state, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByUserId(), and setPriorRelationState().

+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested ( )

@expectedException ilBuddySystemRelationStateAlreadyGivenException

Definition at line 542 of file ilBuddyListTest.php.

543 {
544 $this->assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
545 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
546 $buddylist->reset();
547
549
550 $relation = new ilBuddySystemRelation($state);
551 $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
552 $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
553
554 $this->setPriorRelationState($relation, $state);
555
556 $db = $this->getMockBuilder('ilDBInterface')->getMock();
557 $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue(array(
558 'login' => 'phpunit'
559 )));
560 $this->setGlobalVariable('ilDB', $db);
561
562 $buddylist->request($relation);
563 }

References $buddylist, $state, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByUserId(), ilBuddySystemBaseTest\setGlobalVariable(), and setPriorRelationState().

+ Here is the call graph for this function:

◆ testDifferentRelationStatesCanBeRetrieved()

ilBuddyListTest::testDifferentRelationStatesCanBeRetrieved ( )

Definition at line 389 of file ilBuddyListTest.php.

390 {
391 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
392 $buddylist->reset();
393
394 $relations = array();
395
397 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
398 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
399 $relations[self::BUDDY_LIST_BUDDY_ID] = $relation;
400
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;
405
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;
410
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;
415
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;
420
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;
425
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;
430
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;
435
436 $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
437 $repo->expects($this->any())->method('getAll')->willReturn($relations);
438 $buddylist->setRepository($repo);
439
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());
446 }

References $buddylist, BUDDY_LIST_BUDDY_ID, and ilBuddyList\getInstanceByUserId().

+ Here is the call graph for this function:

◆ testExceptionIsThrownWhenNonNumericOwnerIdIsPassed()

ilBuddyListTest::testExceptionIsThrownWhenNonNumericOwnerIdIsPassed ( )

@expectedException InvalidArgumentException

Definition at line 451 of file ilBuddyListTest.php.

452 {
453 $this->assertException(InvalidArgumentException::class);
454 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
455 $buddylist->reset();
456 $buddylist->setOwnerId("phpunit");
457 }

References $buddylist, ilBuddySystemBaseTest\assertException(), and ilBuddyList\getInstanceByUserId().

+ Here is the call graph for this function:

◆ testExceptionIsThrownWhenRelationIsRequestedForANonNumericUserId()

ilBuddyListTest::testExceptionIsThrownWhenRelationIsRequestedForANonNumericUserId ( )

@expectedException InvalidArgumentException

Definition at line 462 of file ilBuddyListTest.php.

463 {
464 $this->assertException(InvalidArgumentException::class);
465 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
466 $buddylist->reset();
467 $buddylist->getRelationByUserId("phpunit");
468 }

References $buddylist, ilBuddySystemBaseTest\assertException(), and ilBuddyList\getInstanceByUserId().

+ Here is the call graph for this function:

◆ testInstanceByBeCreatedBySingletonMethod()

ilBuddyListTest::testInstanceByBeCreatedBySingletonMethod ( )

Definition at line 68 of file ilBuddyListTest.php.

69 {
70 $relations = array(
73 );
74
75 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
76 $buddylist->setRelations(new ilBuddySystemRelationCollection($relations));
77 $other_buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
78 $other_buddylist->setRelations(new ilBuddySystemRelationCollection());
79
80 $this->assertEquals($buddylist, $other_buddylist);
81 }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list.

References $buddylist, and ilBuddyList\getInstanceByUserId().

+ Here is the call graph for this function:

◆ testInstanceCanBeCreatedByGlobalUserObject()

ilBuddyListTest::testInstanceCanBeCreatedByGlobalUserObject ( )

Definition at line 43 of file ilBuddyListTest.php.

44 {
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));
47 $this->setGlobalVariable('ilUser', $user);
48
50 }
static getInstanceByGlobalUser()
$user
Definition: migrateto20.php:57
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.

References $user, ilBuddyList\getInstanceByGlobalUser(), Sabre\Event\once(), and ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testInstanceCannotBeCreatedByAnonymousGlobalUserObject()

ilBuddyListTest::testInstanceCannotBeCreatedByAnonymousGlobalUserObject ( )

@expectedException ilBuddySystemException

Definition at line 55 of file ilBuddyListTest.php.

56 {
57 $this->assertException(ilBuddySystemException::class);
58 $user = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->setMethods(array('getId'))->getMock();
59 $user->expects($this->once())->method('getId')->will($this->returnValue(ANONYMOUS_USER_ID));
60 $this->setGlobalVariable('ilUser', $user);
61
63 }

References $user, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByGlobalUser(), Sabre\Event\once(), and ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testListIsInitiallyEmpty()

ilBuddyListTest::testListIsInitiallyEmpty ( )

Definition at line 86 of file ilBuddyListTest.php.

87 {
88 $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
89 $repo->expects($this->exactly(1))->method('getAll')->willReturn(array());
90
91 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
92 $buddylist->reset();
93 $buddylist->setRepository($repo);
94
95 $this->assertEmpty($buddylist->getRelations());
96 }

References $buddylist, and ilBuddyList\getInstanceByUserId().

+ Here is the call graph for this function:

◆ testRelationCannotBeRequestedForAnonymous()

ilBuddyListTest::testRelationCannotBeRequestedForAnonymous ( )

@expectedException ilBuddySystemException

Definition at line 294 of file ilBuddyListTest.php.

295 {
296 $this->assertException(ilBuddySystemException::class);
297 $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
298 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
299 $expected_relation->setBuddyUserId(ANONYMOUS_USER_ID);
300
301 $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
302 $repo->expects($this->never())->method('getAll')->willReturn(array());
303 $repo->expects($this->never())->method('save');
304
305 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
306 $buddylist->reset();
307 $buddylist->setRepository($repo);
308 $buddylist->request($expected_relation);
309 }

References $buddylist, ilBuddySystemBaseTest\assertException(), and ilBuddyList\getInstanceByUserId().

+ Here is the call graph for this function:

◆ testRelationCannotBeRequestedForUnknownUserAccounts()

ilBuddyListTest::testRelationCannotBeRequestedForUnknownUserAccounts ( )

@expectedException ilBuddySystemException

Definition at line 314 of file ilBuddyListTest.php.

315 {
316 $this->assertException(ilBuddySystemException::class);
317 $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
318 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
319 $expected_relation->setBuddyUserId(-3);
320
321 $db = $this->getMockBuilder('ilDBInterface')->getMock();
322 $db->expects($this->once())->method('queryF');
323 $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue(null));
324 $this->setGlobalVariable('ilDB', $db);
325
326 $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
327 $repo->expects($this->never())->method('getAll')->willReturn(array());
328 $repo->expects($this->never())->method('save');
329
330 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
331 $buddylist->reset();
332 $buddylist->setRepository($repo);
333 $buddylist->request($expected_relation);
334 }

References $buddylist, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByUserId(), Sabre\Event\once(), and ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testRelationRequestCanBeApprovedByTheRelationTarget()

ilBuddyListTest::testRelationRequestCanBeApprovedByTheRelationTarget ( )

Definition at line 190 of file ilBuddyListTest.php.

191 {
192 $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
193 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
194 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
195
196 $relations = array(
197 $expected_relation->getBuddyUserId() => $expected_relation
198 );
199
200 $db = $this->getMockBuilder('ilDBInterface')->getMock();
201 $db->expects($this->any())->method('queryF');
202 $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue(array(
203 'login' => 'phpunit'
204 )));
205 $this->setGlobalVariable('ilDB', $db);
206
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);
210
211 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
212 $buddylist->reset();
213 $buddylist->setRepository($repo);
214 $buddylist->request($expected_relation);
215
216 $other_buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_BUDDY_ID);
217 $other_buddylist->reset();
218 $other_buddylist->setRepository($repo);
219 $other_buddylist->link($expected_relation);
220 }

References $buddylist, ilBuddyList\getInstanceByUserId(), and ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testRelationRequestCanBeIgnoredByTheRelationTarget()

ilBuddyListTest::testRelationRequestCanBeIgnoredByTheRelationTarget ( )

Definition at line 259 of file ilBuddyListTest.php.

260 {
261 $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
262 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
263 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
264
265 $relations = array(
266 $expected_relation->getBuddyUserId() => $expected_relation
267 );
268
269 $db = $this->getMockBuilder('ilDBInterface')->getMock();
270 $db->expects($this->any())->method('queryF');
271 $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue(array(
272 'login' => 'phpunit'
273 )));
274 $this->setGlobalVariable('ilDB', $db);
275
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);
279
280 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
281 $buddylist->reset();
282 $buddylist->setRepository($repo);
283 $buddylist->request($expected_relation);
284
285 $other_buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_BUDDY_ID);
286 $other_buddylist->reset();
287 $other_buddylist->setRepository($repo);
288 $other_buddylist->ignore($expected_relation);
289 }

References $buddylist, ilBuddyList\getInstanceByUserId(), and ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testRelationRequestCannotBeApprovedByTheRelationOwner()

ilBuddyListTest::testRelationRequestCannotBeApprovedByTheRelationOwner ( )

@expectedException ilBuddySystemException

Definition at line 156 of file ilBuddyListTest.php.

157 {
158 $this->assertException(ilBuddySystemException::class);
159 $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
160 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
161 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
162
163 $relations = array(
164 $expected_relation->getBuddyUserId() => $expected_relation
165 );
166
167 $db = $this->getMockBuilder('ilDBInterface')->getMock();
168 $db->expects($this->once())->method('queryF');
169 $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue(array(
170 'login' => 'phpunit'
171 )));
172 $this->setGlobalVariable('ilDB', $db);
173
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);
177
178 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
179 $buddylist->reset();
180 $buddylist->setRepository($repo);
181
182 $relation = $buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
183 $buddylist->request($relation);
184 $buddylist->link($relation);
185 }

References $buddylist, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByUserId(), Sabre\Event\once(), and ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testRelationRequestCannotBeIgnoredByTheRelationOwner()

ilBuddyListTest::testRelationRequestCannotBeIgnoredByTheRelationOwner ( )

@expectedException ilBuddySystemException

Definition at line 225 of file ilBuddyListTest.php.

226 {
227 $this->assertException(ilBuddySystemException::class);
228 $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
229 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
230 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
231
232 $relations = array(
233 $expected_relation->getBuddyUserId() => $expected_relation
234 );
235
236 $db = $this->getMockBuilder('ilDBInterface')->getMock();
237 $db->expects($this->once())->method('queryF');
238 $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue(array(
239 'login' => 'phpunit'
240 )));
241 $this->setGlobalVariable('ilDB', $db);
242
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);
246
247 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
248 $buddylist->reset();
249 $buddylist->setRepository($repo);
250
251 $relation = $buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
252 $buddylist->request($relation);
253 $buddylist->ignore($relation);
254 }

References $buddylist, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByUserId(), Sabre\Event\once(), and ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly()

ilBuddyListTest::testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly ( )

Definition at line 122 of file ilBuddyListTest.php.

123 {
124 $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
125 $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
126 $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
127
128 $relations = array(
129 $expected_relation->getBuddyUserId() => $expected_relation
130 );
131
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(
135 'login' => 'phpunit'
136 )));
137 $this->setGlobalVariable('ilDB', $db);
138
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);
142
143 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
144 $buddylist->reset();
145 $buddylist->setRepository($repo);
146
147 $relation = $buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
148 $buddylist->request($relation);
149 $buddylist->unlink($relation);
150 $buddylist->request($relation);
151 }

References $buddylist, ilBuddyList\getInstanceByUserId(), Sabre\Event\once(), and ilBuddySystemBaseTest\setGlobalVariable().

+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly()

ilBuddyListTest::testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly ( )

Definition at line 101 of file ilBuddyListTest.php.

102 {
103 $relations = array(
106 );
107
108 $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
109 $repo->expects($this->exactly(1))->method('getAll')->willReturn($relations);
110
111 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
112 $buddylist->reset();
113 $buddylist->setRepository($repo);
114 $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddylist->getRelations());
115 $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddylist->getRelations());
116 $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddylist->getRelations());
117 }

References $buddylist, and ilBuddyList\getInstanceByUserId().

+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed()

ilBuddyListTest::testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed ( )

Definition at line 339 of file ilBuddyListTest.php.

340 {
341 $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
342 $repo->expects($this->once())->method('destroy');
343
344 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
345 $buddylist->reset();
346 $buddylist->setRepository($repo);
347 $buddylist->destroy();
348 }

References $buddylist, ilBuddyList\getInstanceByUserId(), and Sabre\Event\once().

+ Here is the call graph for this function:

◆ testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()

ilBuddyListTest::testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored ( )

@expectedException ilBuddySystemRelationStateTransitionException

Definition at line 568 of file ilBuddyListTest.php.

569 {
570 $this->assertException(ilBuddySystemRelationStateTransitionException::class);
571 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
572 $buddylist->reset();
573
575
576 $relation = new ilBuddySystemRelation($state);
577 $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
578 $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
579
580 $this->setPriorRelationState($relation, $state);
581
582 $buddylist->ignore($relation);
583 }

References $buddylist, $state, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByUserId(), and setPriorRelationState().

+ Here is the call graph for this function:

◆ testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAUknownBuddyId()

ilBuddyListTest::testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAUknownBuddyId ( )

Definition at line 353 of file ilBuddyListTest.php.

354 {
355 $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
356 $repo->expects($this->once())->method('getAll')->willReturn(array());
357
358 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
359 $buddylist->reset();
360 $buddylist->setRepository($repo);
361 $this->assertInstanceOf('ilBuddySystemUnlinkedRelationState', $buddylist->getRelationByUserId(-3)->getState());
362 }

References $buddylist, ilBuddyList\getInstanceByUserId(), and Sabre\Event\once().

+ Here is the call graph for this function:

◆ testValuesCanBeFetchedByGettersWhenSetBySetters()

ilBuddyListTest::testValuesCanBeFetchedByGettersWhenSetBySetters ( )

Definition at line 367 of file ilBuddyListTest.php.

368 {
369 $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
370 $buddylist->reset();
371 $buddylist->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
372 $this->assertEquals(self::BUDDY_LIST_BUDDY_ID, $buddylist->getOwnerId());
373
374 $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
375 $repo->expects($this->never())->method('getAll')->willReturn(array());
376 $buddylist->setRepository($repo);
377 $this->assertEquals($repo, $buddylist->getRepository());
378
379 $relations = array(
380 self::BUDDY_LIST_BUDDY_ID => new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState())
381 );
382 $buddylist->setRelations(new ilBuddySystemRelationCollection($relations));
383 $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddylist->getRelations());
384 }

References $buddylist, and ilBuddyList\getInstanceByUserId().

+ Here is the call graph for this function:

Field Documentation

◆ $buddylist

◆ BUDDY_LIST_BUDDY_ID

const ilBuddyListTest::BUDDY_LIST_BUDDY_ID = -2

Definition at line 14 of file ilBuddyListTest.php.

Referenced by testDifferentRelationStatesCanBeRetrieved().

◆ BUDDY_LIST_OWNER_ID

const ilBuddyListTest::BUDDY_LIST_OWNER_ID = -1

Definition at line 13 of file ilBuddyListTest.php.


The documentation for this class was generated from the following file: