ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBuddyListTest Class Reference

Class ilBuddyListTest. More...

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

Public Member Functions

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

Data Fields

const BUDDY_LIST_OWNER_ID = -1
 
const BUDDY_LIST_BUDDY_ID = -2
 

Protected Member Functions

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

Protected Attributes

 $buddylist
 

Private Member Functions

 setPriorRelationState (ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
 

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

◆ setGlobalVariable()

ilBuddyListTest::setGlobalVariable (   $name,
  $value 
)
protected
Parameters
string$name
mixed$value

Definition at line 25 of file ilBuddyListTest.php.

References $DIC, and $GLOBALS.

Referenced by setUp(), testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested(), testInstanceCanBeCreatedByGlobalUserObject(), testInstanceCannotBeCreatedByAnonymousGlobalUserObject(), testRelationCannotBeRequestedForUnknownUserAccounts(), testRelationRequestCanBeApprovedByTheRelationTarget(), testRelationRequestCanBeIgnoredByTheRelationTarget(), testRelationRequestCannotBeApprovedByTheRelationOwner(), testRelationRequestCannotBeIgnoredByTheRelationOwner(), and testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly().

26  {
27  global $DIC;
28 
29  $GLOBALS[$name] = $value;
30 
31  unset($DIC[$name]);
32  $DIC[$name] = function ($c) use ($name) {
33  return $GLOBALS[$name];
34  };
35  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $DIC
+ Here is the caller graph for this function:

◆ setPriorRelationState()

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

Definition at line 486 of file ilBuddyListTest.php.

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

487  {
488  $object = new ReflectionObject($relation);
489  $property = $object->getProperty('prior_state');
490  $property->setAccessible(true);
491 
492  $property->setValue($relation, $state);
493  }
+ Here is the caller graph for this function:

◆ setUp()

ilBuddyListTest::setUp ( )

Definition at line 40 of file ilBuddyListTest.php.

References array, and setGlobalVariable().

41  {
42  $this->setGlobalVariable(
43  'ilAppEventHandler',
44  $this->getMockBuilder('ilAppEventHandler')->disableOriginalConstructor()->setMethods(array('raise'))->getMock()
45  );
46  $this->setGlobalVariable('ilDB', $this->getMockBuilder('ilDBInterface')->getMock());
47  $this->setGlobalVariable(
48  'lng',
49  $this->getMockBuilder('ilLanguage')
50  ->disableOriginalConstructor()
51  ->setMethods(array('txt', 'loadLanguageModule'))
52  ->getMock()
53  );
54  }
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked ( )

ilBuddySystemRelationStateAlreadyGivenException

Definition at line 498 of file ilBuddyListTest.php.

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

499  {
500  $this->assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
501  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
502  $buddylist->reset();
503 
504  $state = new ilBuddySystemLinkedRelationState();
505 
506  $relation = new ilBuddySystemRelation($state);
507  $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
508  $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
509 
510  $this->setPriorRelationState($relation, $state);
511 
512  $buddylist->link($relation);
513  }
assertException($exception_class)
static getInstanceByUserId($usr_id)
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored ( )

ilBuddySystemRelationStateAlreadyGivenException

Definition at line 518 of file ilBuddyListTest.php.

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

519  {
520  $this->assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
521  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
522  $buddylist->reset();
523 
525 
526  $relation = new ilBuddySystemRelation($state);
527  $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
528  $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
529 
530  $this->setPriorRelationState($relation, $state);
531 
532  $buddylist->ignore($relation);
533  }
assertException($exception_class)
static getInstanceByUserId($usr_id)
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked ( )

ilBuddySystemRelationStateAlreadyGivenException

Definition at line 538 of file ilBuddyListTest.php.

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

539  {
540  $this->assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
541  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
542  $buddylist->reset();
543 
544  $state = new ilBuddySystemUnlinkedRelationState();
545 
546  $relation = new ilBuddySystemRelation($state);
547  $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
548  $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
549 
550  $this->setPriorRelationState($relation, $state);
551 
552  $buddylist->unlink($relation);
553  }
assertException($exception_class)
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId($usr_id)
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested ( )

ilBuddySystemRelationStateAlreadyGivenException

Definition at line 558 of file ilBuddyListTest.php.

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

559  {
560  $this->assertException(ilBuddySystemRelationStateAlreadyGivenException::class);
561  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
562  $buddylist->reset();
563 
565 
566  $relation = new ilBuddySystemRelation($state);
567  $relation->setUserId(self::BUDDY_LIST_BUDDY_ID);
568  $relation->setBuddyUserId(self::BUDDY_LIST_OWNER_ID);
569 
570  $this->setPriorRelationState($relation, $state);
571 
572  $db = $this->getMockBuilder('ilDBInterface')->getMock();
573  $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue(array(
574  'login' => 'phpunit'
575  )));
576  $this->setGlobalVariable('ilDB', $db);
577 
578  $buddylist->request($relation);
579  }
assertException($exception_class)
static getInstanceByUserId($usr_id)
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testDifferentRelationStatesCanBeRetrieved()

ilBuddyListTest::testDifferentRelationStatesCanBeRetrieved ( )

Definition at line 405 of file ilBuddyListTest.php.

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

406  {
407  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
408  $buddylist->reset();
409 
410  $relations = array();
411 
413  $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
414  $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
415  $relations[self::BUDDY_LIST_BUDDY_ID] = $relation;
416 
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;
421 
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;
426 
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;
431 
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;
436 
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;
441 
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;
446 
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;
451 
452  $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
453  $repo->expects($this->any())->method('getAll')->willReturn($relations);
454  $buddylist->setRepository($repo);
455 
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());
462  }
static getInstanceByUserId($usr_id)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testExceptionIsThrownWhenNonNumericOwnerIdIsPassed()

ilBuddyListTest::testExceptionIsThrownWhenNonNumericOwnerIdIsPassed ( )

InvalidArgumentException

Definition at line 467 of file ilBuddyListTest.php.

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

468  {
469  $this->assertException(InvalidArgumentException::class);
470  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
471  $buddylist->reset();
472  $buddylist->setOwnerId("phpunit");
473  }
assertException($exception_class)
static getInstanceByUserId($usr_id)
+ Here is the call graph for this function:

◆ testExceptionIsThrownWhenRelationIsRequestedForANonNumericUserId()

ilBuddyListTest::testExceptionIsThrownWhenRelationIsRequestedForANonNumericUserId ( )

InvalidArgumentException

Definition at line 478 of file ilBuddyListTest.php.

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

479  {
480  $this->assertException(InvalidArgumentException::class);
481  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
482  $buddylist->reset();
483  $buddylist->getRelationByUserId("phpunit");
484  }
assertException($exception_class)
static getInstanceByUserId($usr_id)
+ Here is the call graph for this function:

◆ testInstanceByBeCreatedBySingletonMethod()

ilBuddyListTest::testInstanceByBeCreatedBySingletonMethod ( )

Definition at line 84 of file ilBuddyListTest.php.

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

85  {
86  $relations = array(
89  );
90 
91  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
92  $buddylist->setRelations(new ilBuddySystemRelationCollection($relations));
93  $other_buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
94  $other_buddylist->setRelations(new ilBuddySystemRelationCollection());
95 
96  $this->assertEquals($buddylist, $other_buddylist);
97  }
Class ilBuddySystemUnlinkedRelationState.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
static getInstanceByUserId($usr_id)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testInstanceCanBeCreatedByGlobalUserObject()

ilBuddyListTest::testInstanceCanBeCreatedByGlobalUserObject ( )

Definition at line 59 of file ilBuddyListTest.php.

References array, ilBuddyList\getInstanceByGlobalUser(), and setGlobalVariable().

60  {
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));
63  $this->setGlobalVariable('ilUser', $user);
64 
66  }
static getInstanceByGlobalUser()
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testInstanceCannotBeCreatedByAnonymousGlobalUserObject()

ilBuddyListTest::testInstanceCannotBeCreatedByAnonymousGlobalUserObject ( )

ilBuddySystemException

Definition at line 71 of file ilBuddyListTest.php.

References array, ilBuddySystemBaseTest\assertException(), ilBuddyList\getInstanceByGlobalUser(), and setGlobalVariable().

72  {
73  $this->assertException(ilBuddySystemException::class);
74  $user = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->setMethods(array('getId'))->getMock();
75  $user->expects($this->once())->method('getId')->will($this->returnValue(ANONYMOUS_USER_ID));
76  $this->setGlobalVariable('ilUser', $user);
77 
79  }
static getInstanceByGlobalUser()
assertException($exception_class)
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testListIsInitiallyEmpty()

ilBuddyListTest::testListIsInitiallyEmpty ( )

Definition at line 102 of file ilBuddyListTest.php.

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

103  {
104  $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
105  $repo->expects($this->exactly(1))->method('getAll')->willReturn(array());
106 
107  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
108  $buddylist->reset();
109  $buddylist->setRepository($repo);
110 
111  $this->assertEmpty($buddylist->getRelations());
112  }
static getInstanceByUserId($usr_id)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testRelationCannotBeRequestedForAnonymous()

ilBuddyListTest::testRelationCannotBeRequestedForAnonymous ( )

ilBuddySystemException

Definition at line 310 of file ilBuddyListTest.php.

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

311  {
312  $this->assertException(ilBuddySystemException::class);
313  $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
314  $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
315  $expected_relation->setBuddyUserId(ANONYMOUS_USER_ID);
316 
317  $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
318  $repo->expects($this->never())->method('getAll')->willReturn(array());
319  $repo->expects($this->never())->method('save');
320 
321  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
322  $buddylist->reset();
323  $buddylist->setRepository($repo);
324  $buddylist->request($expected_relation);
325  }
assertException($exception_class)
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId($usr_id)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRelationCannotBeRequestedForUnknownUserAccounts()

ilBuddyListTest::testRelationCannotBeRequestedForUnknownUserAccounts ( )

ilBuddySystemException

Definition at line 330 of file ilBuddyListTest.php.

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

331  {
332  $this->assertException(ilBuddySystemException::class);
333  $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
334  $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
335  $expected_relation->setBuddyUserId(-3);
336 
337  $db = $this->getMockBuilder('ilDBInterface')->getMock();
338  $db->expects($this->once())->method('queryF');
339  $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue(null));
340  $this->setGlobalVariable('ilDB', $db);
341 
342  $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
343  $repo->expects($this->never())->method('getAll')->willReturn(array());
344  $repo->expects($this->never())->method('save');
345 
346  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
347  $buddylist->reset();
348  $buddylist->setRepository($repo);
349  $buddylist->request($expected_relation);
350  }
assertException($exception_class)
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId($usr_id)
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRelationRequestCanBeApprovedByTheRelationTarget()

ilBuddyListTest::testRelationRequestCanBeApprovedByTheRelationTarget ( )

Definition at line 206 of file ilBuddyListTest.php.

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

207  {
208  $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
209  $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
210  $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
211 
212  $relations = array(
213  $expected_relation->getBuddyUserId() => $expected_relation
214  );
215 
216  $db = $this->getMockBuilder('ilDBInterface')->getMock();
217  $db->expects($this->any())->method('queryF');
218  $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue(array(
219  'login' => 'phpunit'
220  )));
221  $this->setGlobalVariable('ilDB', $db);
222 
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);
226 
227  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
228  $buddylist->reset();
229  $buddylist->setRepository($repo);
230  $buddylist->request($expected_relation);
231 
232  $other_buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_BUDDY_ID);
233  $other_buddylist->reset();
234  $other_buddylist->setRepository($repo);
235  $other_buddylist->link($expected_relation);
236  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId($usr_id)
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRelationRequestCanBeIgnoredByTheRelationTarget()

ilBuddyListTest::testRelationRequestCanBeIgnoredByTheRelationTarget ( )

Definition at line 275 of file ilBuddyListTest.php.

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

276  {
277  $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
278  $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
279  $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
280 
281  $relations = array(
282  $expected_relation->getBuddyUserId() => $expected_relation
283  );
284 
285  $db = $this->getMockBuilder('ilDBInterface')->getMock();
286  $db->expects($this->any())->method('queryF');
287  $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue(array(
288  'login' => 'phpunit'
289  )));
290  $this->setGlobalVariable('ilDB', $db);
291 
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);
295 
296  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
297  $buddylist->reset();
298  $buddylist->setRepository($repo);
299  $buddylist->request($expected_relation);
300 
301  $other_buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_BUDDY_ID);
302  $other_buddylist->reset();
303  $other_buddylist->setRepository($repo);
304  $other_buddylist->ignore($expected_relation);
305  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId($usr_id)
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRelationRequestCannotBeApprovedByTheRelationOwner()

ilBuddyListTest::testRelationRequestCannotBeApprovedByTheRelationOwner ( )

ilBuddySystemException

Definition at line 172 of file ilBuddyListTest.php.

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

173  {
174  $this->assertException(ilBuddySystemException::class);
175  $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
176  $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
177  $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
178 
179  $relations = array(
180  $expected_relation->getBuddyUserId() => $expected_relation
181  );
182 
183  $db = $this->getMockBuilder('ilDBInterface')->getMock();
184  $db->expects($this->once())->method('queryF');
185  $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue(array(
186  'login' => 'phpunit'
187  )));
188  $this->setGlobalVariable('ilDB', $db);
189 
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);
193 
194  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
195  $buddylist->reset();
196  $buddylist->setRepository($repo);
197 
198  $relation = $buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
199  $buddylist->request($relation);
200  $buddylist->link($relation);
201  }
assertException($exception_class)
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId($usr_id)
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRelationRequestCannotBeIgnoredByTheRelationOwner()

ilBuddyListTest::testRelationRequestCannotBeIgnoredByTheRelationOwner ( )

ilBuddySystemException

Definition at line 241 of file ilBuddyListTest.php.

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

242  {
243  $this->assertException(ilBuddySystemException::class);
244  $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
245  $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
246  $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
247 
248  $relations = array(
249  $expected_relation->getBuddyUserId() => $expected_relation
250  );
251 
252  $db = $this->getMockBuilder('ilDBInterface')->getMock();
253  $db->expects($this->once())->method('queryF');
254  $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue(array(
255  'login' => 'phpunit'
256  )));
257  $this->setGlobalVariable('ilDB', $db);
258 
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);
262 
263  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
264  $buddylist->reset();
265  $buddylist->setRepository($repo);
266 
267  $relation = $buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
268  $buddylist->request($relation);
269  $buddylist->ignore($relation);
270  }
assertException($exception_class)
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId($usr_id)
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly()

ilBuddyListTest::testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly ( )

Definition at line 138 of file ilBuddyListTest.php.

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

139  {
140  $expected_relation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
141  $expected_relation->setUserId(self::BUDDY_LIST_OWNER_ID);
142  $expected_relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
143 
144  $relations = array(
145  $expected_relation->getBuddyUserId() => $expected_relation
146  );
147 
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(
151  'login' => 'phpunit'
152  )));
153  $this->setGlobalVariable('ilDB', $db);
154 
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);
158 
159  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
160  $buddylist->reset();
161  $buddylist->setRepository($repo);
162 
163  $relation = $buddylist->getRelationByUserId($expected_relation->getBuddyUserId());
164  $buddylist->request($relation);
165  $buddylist->unlink($relation);
166  $buddylist->request($relation);
167  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId($usr_id)
setGlobalVariable($name, $value)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly()

ilBuddyListTest::testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly ( )

Definition at line 117 of file ilBuddyListTest.php.

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

118  {
119  $relations = array(
122  );
123 
124  $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
125  $repo->expects($this->exactly(1))->method('getAll')->willReturn($relations);
126 
127  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
128  $buddylist->reset();
129  $buddylist->setRepository($repo);
130  $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddylist->getRelations());
131  $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddylist->getRelations());
132  $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddylist->getRelations());
133  }
Class ilBuddySystemUnlinkedRelationState.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
static getInstanceByUserId($usr_id)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed()

ilBuddyListTest::testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed ( )

Definition at line 355 of file ilBuddyListTest.php.

References $buddylist, and ilBuddyList\getInstanceByUserId().

356  {
357  $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
358  $repo->expects($this->once())->method('destroy');
359 
360  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
361  $buddylist->reset();
362  $buddylist->setRepository($repo);
363  $buddylist->destroy();
364  }
static getInstanceByUserId($usr_id)
+ Here is the call graph for this function:

◆ testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()

ilBuddyListTest::testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored ( )

ilBuddySystemRelationStateTransitionException

Definition at line 584 of file ilBuddyListTest.php.

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

585  {
586  $this->assertException(ilBuddySystemRelationStateTransitionException::class);
587  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
588  $buddylist->reset();
589 
590  $state = new ilBuddySystemLinkedRelationState();
591 
592  $relation = new ilBuddySystemRelation($state);
593  $relation->setUserId(self::BUDDY_LIST_OWNER_ID);
594  $relation->setBuddyUserId(self::BUDDY_LIST_BUDDY_ID);
595 
596  $this->setPriorRelationState($relation, $state);
597 
598  $buddylist->ignore($relation);
599  }
assertException($exception_class)
static getInstanceByUserId($usr_id)
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAUknownBuddyId()

ilBuddyListTest::testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAUknownBuddyId ( )

Definition at line 369 of file ilBuddyListTest.php.

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

370  {
371  $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
372  $repo->expects($this->once())->method('getAll')->willReturn(array());
373 
374  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
375  $buddylist->reset();
376  $buddylist->setRepository($repo);
377  $this->assertInstanceOf('ilBuddySystemUnlinkedRelationState', $buddylist->getRelationByUserId(-3)->getState());
378  }
static getInstanceByUserId($usr_id)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testValuesCanBeFetchedByGettersWhenSetBySetters()

ilBuddyListTest::testValuesCanBeFetchedByGettersWhenSetBySetters ( )

Definition at line 383 of file ilBuddyListTest.php.

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

384  {
385  $buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
386  $buddylist->reset();
387  $buddylist->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
388  $this->assertEquals(self::BUDDY_LIST_BUDDY_ID, $buddylist->getOwnerId());
389 
390  $repo = $this->getMockBuilder('ilBuddySystemRelationRepository')->disableOriginalConstructor()->getMock();
391  $repo->expects($this->never())->method('getAll')->willReturn(array());
392  $buddylist->setRepository($repo);
393  $this->assertEquals($repo, $buddylist->getRepository());
394 
395  $relations = array(
396  self::BUDDY_LIST_BUDDY_ID => new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState())
397  );
398  $buddylist->setRelations(new ilBuddySystemRelationCollection($relations));
399  $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddylist->getRelations());
400  }
Class ilBuddySystemUnlinkedRelationState.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
static getInstanceByUserId($usr_id)
Create styles array
The data for the language used.
Class ilBuddySystemRelation.
+ 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.

◆ 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: