ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBuddyListTest Class Reference

Class ilBuddyListTest. More...

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

Public Member Functions

 setUp ()
 
 testInstanceCanBeCreatedByGlobalUserObject ()
 
 testInstanceCannotBeCreatedByAnonymousGlobalUserObject ()
 
 testInstanceByBeCreatedBySingletonMethod ()
 
 testListIsInitiallyEmpty ()
 
 testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly ()
 
 testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly ()
 
 testRelationRequestCannotBeApprovedByTheRelationOwner ()
 
 testRelationRequestCanBeApprovedByTheRelationTarget ()
 
 testRelationRequestCannotBeIgnoredByTheRelationOwner ()
 
 testRelationRequestCanBeIgnoredByTheRelationTarget ()
 
 testRelationCannotBeRequestedForAnonymous ()
 
 testRelationCannotBeRequestedForUnknownUserAccounts ()
 
 testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed ()
 
 testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAnUnknownBuddyId ()
 
 testValuesCanBeFetchedByGettersWhenSetBySetters ()
 
 testDifferentRelationStatesCanBeRetrieved ()
 
 testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked ()
 
 testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored ()
 
 testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked ()
 
 testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested ()
 
 testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored ()
 

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 (string $name, $value)
 

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 
)
private
Parameters
ilBuddySystemRelation$relation
ilBuddySystemRelationState$state
Exceptions
ReflectionException

Definition at line 451 of file ilBuddyListTest.php.

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

454  : void {
455  $object = new ReflectionObject($relation);
456  $property = $object->getProperty('priorState');
457  $property->setAccessible(true);
458 
459  $property->setValue($relation, $state);
460  }
+ Here is the caller graph for this function:

◆ setUp()

ilBuddyListTest::setUp ( )

Definition at line 22 of file ilBuddyListTest.php.

References ilBuddySystemBaseTest\setGlobalVariable().

22  : void
23  {
24  $this->setGlobalVariable(
25  'ilAppEventHandler',
26  $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->onlyMethods(['raise'])->getMock()
27  );
28  $this->setGlobalVariable('ilDB', $this->getMockBuilder(ilDBInterface::class)->getMock());
29  $this->setGlobalVariable(
30  'lng',
31  $this->getMockBuilder(ilLanguage::class)
32  ->disableOriginalConstructor()
33  ->onlyMethods(['txt', 'loadLanguageModule'])
34  ->getMock()
35  );
36  }
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked ( )

Definition at line 465 of file ilBuddyListTest.php.

References $buddyList, ilBuddyList\getInstanceByUserId(), and setPriorRelationState().

465  : void
466  {
467  $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
468  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
469  $buddyList->reset();
470 
471  $state = new ilBuddySystemLinkedRelationState();
472 
473  $relation = new ilBuddySystemRelation($state);
474  $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
475  $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
476 
477  $this->setPriorRelationState($relation, $state);
478 
479  $buddyList->link($relation);
480  }
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored ( )

Definition at line 485 of file ilBuddyListTest.php.

References $buddyList, ilBuddyList\getInstanceByUserId(), and setPriorRelationState().

485  : void
486  {
487  $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
488  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
489  $buddyList->reset();
490 
492 
493  $relation = new ilBuddySystemRelation($state);
494  $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID);
495  $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
496 
497  $this->setPriorRelationState($relation, $state);
498 
499  $buddyList->ignore($relation);
500  }
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked ( )

Definition at line 505 of file ilBuddyListTest.php.

References $buddyList, ilBuddyList\getInstanceByUserId(), and setPriorRelationState().

505  : void
506  {
507  $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
508  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
509  $buddyList->reset();
510 
511  $state = new ilBuddySystemUnlinkedRelationState();
512 
513  $relation = new ilBuddySystemRelation($state);
514  $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
515  $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
516 
517  $this->setPriorRelationState($relation, $state);
518 
519  $buddyList->unlink($relation);
520  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested()

ilBuddyListTest::testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested ( )

Definition at line 525 of file ilBuddyListTest.php.

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

525  : void
526  {
527  $this->expectException(ilBuddySystemRelationStateAlreadyGivenException::class);
528  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
529  $buddyList->reset();
530 
532 
533  $relation = new ilBuddySystemRelation($state);
534  $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID);
535  $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
536 
537  $this->setPriorRelationState($relation, $state);
538 
539  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
540  $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue([
541  'login' => 'phpunit'
542  ]));
543  $this->setGlobalVariable('ilDB', $db);
544 
545  $buddyList->request($relation);
546  }
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRequestedRelationState.
Class ilBuddySystemRelation.
setGlobalVariable(string $name, $value)
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testDifferentRelationStatesCanBeRetrieved()

ilBuddyListTest::testDifferentRelationStatesCanBeRetrieved ( )

Definition at line 387 of file ilBuddyListTest.php.

References $buddyList, and ilBuddyList\getInstanceByUserId().

387  : void
388  {
389  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
390  $buddyList->reset();
391 
392  $relations = [];
393 
395  $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
396  $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
397  $relations[self::BUDDY_LIST_BUDDY_ID] = $relation;
398 
400  $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID + 1);
401  $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
402  $relations[self::BUDDY_LIST_BUDDY_ID + 1] = $relation;
403 
405  $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID + 2);
406  $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
407  $relations[self::BUDDY_LIST_BUDDY_ID + 2] = $relation;
408 
410  $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID + 3);
411  $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
412  $relations[self::BUDDY_LIST_BUDDY_ID + 3] = $relation;
413 
415  $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
416  $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID + 4);
417  $relations[self::BUDDY_LIST_BUDDY_ID + 4] = $relation;
418 
420  $relation->setUsrId(self::BUDDY_LIST_BUDDY_ID + 5);
421  $relation->setBuddyUsrId(self::BUDDY_LIST_OWNER_ID);
422  $relations[self::BUDDY_LIST_BUDDY_ID + 5] = $relation;
423 
425  $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
426  $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID + 6);
427  $relations[self::BUDDY_LIST_BUDDY_ID + 6] = $relation;
428 
430  $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
431  $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID + 7);
432  $relations[self::BUDDY_LIST_BUDDY_ID + 7] = $relation;
433 
434  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
435  $repo->expects($this->any())->method('getAll')->willReturn($relations);
436  $buddyList->setRepository($repo);
437 
438  $this->assertCount(3, $buddyList->getLinkedRelations());
439  $this->assertCount(1, $buddyList->getRequestRelationsForOwner());
440  $this->assertCount(1, $buddyList->getRequestRelationsByOwner());
441  $this->assertCount(1, $buddyList->getIgnoredRelationsForOwner());
442  $this->assertCount(2, $buddyList->getIgnoredRelationsByOwner());
443  $this->assertEquals(array_keys($relations), $buddyList->getRelationUserIds());
444  }
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRequestedRelationState.
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testInstanceByBeCreatedBySingletonMethod()

ilBuddyListTest::testInstanceByBeCreatedBySingletonMethod ( )

Definition at line 66 of file ilBuddyListTest.php.

References $buddyList, and ilBuddyList\getInstanceByUserId().

66  : void
67  {
68  $relations = [
71  ];
72 
73  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
74  $buddyList->setRelations(new ilBuddySystemRelationCollection($relations));
75  $otherBuddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
76  $otherBuddylist->setRelations(new ilBuddySystemRelationCollection());
77 
78  $this->assertEquals($buddyList, $otherBuddylist);
79  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testInstanceCanBeCreatedByGlobalUserObject()

ilBuddyListTest::testInstanceCanBeCreatedByGlobalUserObject ( )

Definition at line 41 of file ilBuddyListTest.php.

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

41  : void
42  {
43  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(['getId'])->getMock();
44  $user->expects($this->once())->method('getId')->will($this->returnValue(self::BUDDY_LIST_OWNER_ID));
45  $this->setGlobalVariable('ilUser', $user);
46 
48  }
static getInstanceByGlobalUser()
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testInstanceCannotBeCreatedByAnonymousGlobalUserObject()

ilBuddyListTest::testInstanceCannotBeCreatedByAnonymousGlobalUserObject ( )

Definition at line 53 of file ilBuddyListTest.php.

References ANONYMOUS_USER_ID, ilBuddyList\getInstanceByGlobalUser(), and ilBuddySystemBaseTest\setGlobalVariable().

53  : void
54  {
55  $this->expectException(ilBuddySystemException::class);
56  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(['getId'])->getMock();
57  $user->expects($this->once())->method('getId')->will($this->returnValue(ANONYMOUS_USER_ID));
58  $this->setGlobalVariable('ilUser', $user);
59 
61  }
static getInstanceByGlobalUser()
const ANONYMOUS_USER_ID
Definition: constants.php:25
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testListIsInitiallyEmpty()

ilBuddyListTest::testListIsInitiallyEmpty ( )

Definition at line 84 of file ilBuddyListTest.php.

References $buddyList, and ilBuddyList\getInstanceByUserId().

84  : void
85  {
86  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
87  $repo->expects($this->exactly(1))->method('getAll')->willReturn([]);
88 
89  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
90  $buddyList->reset();
91  $buddyList->setRepository($repo);
92 
93  $this->assertEmpty($buddyList->getRelations());
94  }
static getInstanceByUserId(int $usrId)
+ Here is the call graph for this function:

◆ testRelationCannotBeRequestedForAnonymous()

ilBuddyListTest::testRelationCannotBeRequestedForAnonymous ( )

Definition at line 292 of file ilBuddyListTest.php.

References $buddyList, ANONYMOUS_USER_ID, and ilBuddyList\getInstanceByUserId().

292  : void
293  {
294  $this->expectException(ilBuddySystemException::class);
295  $expectedRelation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
296  $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
297  $expectedRelation->setBuddyUsrId(ANONYMOUS_USER_ID);
298 
299  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
300  $repo->expects($this->never())->method('getAll')->willReturn([]);
301  $repo->expects($this->never())->method('save');
302 
303  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
304  $buddyList->reset();
305  $buddyList->setRepository($repo);
306  $buddyList->request($expectedRelation);
307  }
const ANONYMOUS_USER_ID
Definition: constants.php:25
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRelationCannotBeRequestedForUnknownUserAccounts()

ilBuddyListTest::testRelationCannotBeRequestedForUnknownUserAccounts ( )

Definition at line 312 of file ilBuddyListTest.php.

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

312  : void
313  {
314  $this->expectException(ilBuddySystemException::class);
315  $expectedRelation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
316  $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
317  $expectedRelation->setBuddyUsrId(-3);
318 
319  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
320  $db->expects($this->once())->method('queryF');
321  $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue(null));
322  $this->setGlobalVariable('ilDB', $db);
323 
324  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
325  $repo->expects($this->never())->method('getAll')->willReturn([]);
326  $repo->expects($this->never())->method('save');
327 
328  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
329  $buddyList->reset();
330  $buddyList->setRepository($repo);
331  $buddyList->request($expectedRelation);
332  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testRelationRequestCanBeApprovedByTheRelationTarget()

ilBuddyListTest::testRelationRequestCanBeApprovedByTheRelationTarget ( )

Definition at line 188 of file ilBuddyListTest.php.

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

188  : void
189  {
190  $expectedRelation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
191  $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
192  $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
193 
194  $relations = [
195  $expectedRelation->getBuddyUsrId() => $expectedRelation
196  ];
197 
198  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
199  $db->expects($this->any())->method('queryF');
200  $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue([
201  'login' => 'phpunit'
202  ]));
203  $this->setGlobalVariable('ilDB', $db);
204 
205  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
206  $repo->expects($this->any())->method('getAll')->willReturn($relations);
207  $repo->expects($this->any())->method('save')->with($expectedRelation);
208 
209  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
210  $buddyList->reset();
211  $buddyList->setRepository($repo);
212  $buddyList->request($expectedRelation);
213 
214  $other_buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_BUDDY_ID);
215  $other_buddylist->reset();
216  $other_buddylist->setRepository($repo);
217  $other_buddylist->link($expectedRelation);
218  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testRelationRequestCanBeIgnoredByTheRelationTarget()

ilBuddyListTest::testRelationRequestCanBeIgnoredByTheRelationTarget ( )

Definition at line 257 of file ilBuddyListTest.php.

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

257  : void
258  {
259  $expectedRelation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
260  $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
261  $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
262 
263  $relations = [
264  $expectedRelation->getBuddyUsrId() => $expectedRelation
265  ];
266 
267  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
268  $db->expects($this->any())->method('queryF');
269  $db->expects($this->any())->method('fetchAssoc')->will($this->returnValue([
270  'login' => 'phpunit'
271  ]));
272  $this->setGlobalVariable('ilDB', $db);
273 
274  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
275  $repo->expects($this->any())->method('getAll')->willReturn($relations);
276  $repo->expects($this->any())->method('save')->with($expectedRelation);
277 
278  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
279  $buddyList->reset();
280  $buddyList->setRepository($repo);
281  $buddyList->request($expectedRelation);
282 
283  $other_buddylist = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_BUDDY_ID);
284  $other_buddylist->reset();
285  $other_buddylist->setRepository($repo);
286  $other_buddylist->ignore($expectedRelation);
287  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testRelationRequestCannotBeApprovedByTheRelationOwner()

ilBuddyListTest::testRelationRequestCannotBeApprovedByTheRelationOwner ( )

Definition at line 154 of file ilBuddyListTest.php.

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

154  : void
155  {
156  $this->expectException(ilBuddySystemException::class);
157  $expectedRelation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
158  $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
159  $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
160 
161  $relations = [
162  $expectedRelation->getBuddyUsrId() => $expectedRelation
163  ];
164 
165  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
166  $db->expects($this->once())->method('queryF');
167  $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue([
168  'login' => 'phpunit'
169  ]));
170  $this->setGlobalVariable('ilDB', $db);
171 
172  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
173  $repo->expects($this->once())->method('getAll')->willReturn($relations);
174  $repo->expects($this->exactly(1))->method('save')->with($expectedRelation);
175 
176  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
177  $buddyList->reset();
178  $buddyList->setRepository($repo);
179 
180  $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
181  $buddyList->request($relation);
182  $buddyList->link($relation);
183  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testRelationRequestCannotBeIgnoredByTheRelationOwner()

ilBuddyListTest::testRelationRequestCannotBeIgnoredByTheRelationOwner ( )

Definition at line 223 of file ilBuddyListTest.php.

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

223  : void
224  {
225  $this->expectException(ilBuddySystemException::class);
226  $expectedRelation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
227  $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
228  $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
229 
230  $relations = [
231  $expectedRelation->getBuddyUsrId() => $expectedRelation
232  ];
233 
234  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
235  $db->expects($this->once())->method('queryF');
236  $db->expects($this->once())->method('fetchAssoc')->will($this->returnValue([
237  'login' => 'phpunit'
238  ]));
239  $this->setGlobalVariable('ilDB', $db);
240 
241  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
242  $repo->expects($this->once())->method('getAll')->willReturn($relations);
243  $repo->expects($this->exactly(1))->method('save')->with($expectedRelation);
244 
245  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
246  $buddyList->reset();
247  $buddyList->setRepository($repo);
248 
249  $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
250  $buddyList->request($relation);
251  $buddyList->ignore($relation);
252  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly()

ilBuddyListTest::testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly ( )

Definition at line 120 of file ilBuddyListTest.php.

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

120  : void
121  {
122  $expectedRelation = new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState());
123  $expectedRelation->setUsrId(self::BUDDY_LIST_OWNER_ID);
124  $expectedRelation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
125 
126  $relations = [
127  $expectedRelation->getBuddyUsrId() => $expectedRelation
128  ];
129 
130  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
131  $db->expects($this->exactly(2))->method('queryF');
132  $db->expects($this->exactly(2))->method('fetchAssoc')->will($this->returnValue([
133  'login' => 'phpunit'
134  ]));
135  $this->setGlobalVariable('ilDB', $db);
136 
137  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
138  $repo->expects($this->once())->method('getAll')->willReturn($relations);
139  $repo->expects($this->exactly(3))->method('save')->with($expectedRelation);
140 
141  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
142  $buddyList->reset();
143  $buddyList->setRepository($repo);
144 
145  $relation = $buddyList->getRelationByUserId($expectedRelation->getBuddyUsrId());
146  $buddyList->request($relation);
147  $buddyList->unlink($relation);
148  $buddyList->request($relation);
149  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly()

ilBuddyListTest::testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly ( )

Definition at line 99 of file ilBuddyListTest.php.

References $buddyList, and ilBuddyList\getInstanceByUserId().

99  : void
100  {
101  $relations = [
104  ];
105 
106  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
107  $repo->expects($this->exactly(1))->method('getAll')->willReturn($relations);
108 
109  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
110  $buddyList->reset();
111  $buddyList->setRepository($repo);
112  $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddyList->getRelations());
113  $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddyList->getRelations());
114  $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddyList->getRelations());
115  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Class ilBuddySystemRelation.
+ Here is the call graph for this function:

◆ testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed()

ilBuddyListTest::testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed ( )

Definition at line 337 of file ilBuddyListTest.php.

References $buddyList, and ilBuddyList\getInstanceByUserId().

337  : void
338  {
339  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
340  $repo->expects($this->once())->method('destroy');
341 
342  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
343  $buddyList->reset();
344  $buddyList->setRepository($repo);
345  $buddyList->destroy();
346  }
static getInstanceByUserId(int $usrId)
+ Here is the call graph for this function:

◆ testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored()

ilBuddyListTest::testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored ( )

Definition at line 551 of file ilBuddyListTest.php.

References $buddyList, ilBuddyList\getInstanceByUserId(), and setPriorRelationState().

551  : void
552  {
553  $this->expectException(ilBuddySystemRelationStateTransitionException::class);
554  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
555  $buddyList->reset();
556 
557  $state = new ilBuddySystemLinkedRelationState();
558 
559  $relation = new ilBuddySystemRelation($state);
560  $relation->setUsrId(self::BUDDY_LIST_OWNER_ID);
561  $relation->setBuddyUsrId(self::BUDDY_LIST_BUDDY_ID);
562 
563  $this->setPriorRelationState($relation, $state);
564 
565  $buddyList->ignore($relation);
566  }
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelation.
setPriorRelationState(ilBuddySystemRelation $relation, ilBuddySystemRelationState $state)
+ Here is the call graph for this function:

◆ testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAnUnknownBuddyId()

ilBuddyListTest::testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAnUnknownBuddyId ( )

Definition at line 351 of file ilBuddyListTest.php.

References $buddyList, and ilBuddyList\getInstanceByUserId().

351  : void
352  {
353  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
354  $repo->expects($this->once())->method('getAll')->willReturn([]);
355 
356  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
357  $buddyList->reset();
358  $buddyList->setRepository($repo);
359  $this->assertInstanceOf('ilBuddySystemUnlinkedRelationState', $buddyList->getRelationByUserId(-3)->getState());
360  }
static getInstanceByUserId(int $usrId)
+ Here is the call graph for this function:

◆ testValuesCanBeFetchedByGettersWhenSetBySetters()

ilBuddyListTest::testValuesCanBeFetchedByGettersWhenSetBySetters ( )

Definition at line 365 of file ilBuddyListTest.php.

References $buddyList, and ilBuddyList\getInstanceByUserId().

365  : void
366  {
367  $buddyList = ilBuddyList::getInstanceByUserId(self::BUDDY_LIST_OWNER_ID);
368  $buddyList->reset();
369  $buddyList->setOwnerId(self::BUDDY_LIST_BUDDY_ID);
370  $this->assertEquals(self::BUDDY_LIST_BUDDY_ID, $buddyList->getOwnerId());
371 
372  $repo = $this->getMockBuilder(ilBuddySystemRelationRepository::class)->disableOriginalConstructor()->getMock();
373  $repo->expects($this->never())->method('getAll')->willReturn([]);
374  $buddyList->setRepository($repo);
375  $this->assertEquals($repo, $buddyList->getRepository());
376 
377  $relations = [
378  self::BUDDY_LIST_BUDDY_ID => new ilBuddySystemRelation(new ilBuddySystemUnlinkedRelationState())
379  ];
380  $buddyList->setRelations(new ilBuddySystemRelationCollection($relations));
381  $this->assertEquals(new ilBuddySystemRelationCollection($relations), $buddyList->getRelations());
382  }
Class ilBuddySystemUnlinkedRelationState.
static getInstanceByUserId(int $usrId)
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
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: