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

Class ilBuddySystemRelationCollectionTest. More...

+ Inheritance diagram for ilBuddySystemRelationCollectionTest:
+ Collaboration diagram for ilBuddySystemRelationCollectionTest:

Public Member Functions

 setUp ()
 
 testElementsCanBeInitiallyAdded ($elements)
 provideElements More...
 
 testElementsCanBeAddedAndRemoved ($elements)
 provideElements More...
 
 testIterator ($elements)
 provideElements More...
 
 testRemovingAnNonExistingElementRaisesAnException ()
 InvalidArgumentException More...
 
 testRemovingAnNonExistingElementByKeyRaisesAnException ()
 InvalidArgumentException More...
 
 testElementsCanBeSliced ()
 
 testElementsCanBeFiltered ()
 
 provideElements ()
 

Protected Attributes

 $backupGlobals = false
 

Additional Inherited Members

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

Detailed Description

Member Function Documentation

◆ provideElements()

ilBuddySystemRelationCollectionTest::provideElements ( )
Returns
array

Definition at line 165 of file ilBuddySystemRelationCollectionTest.php.

166  {
167  $relation_1 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
168  $relation_2 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
169  $relation_3 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
170  $relation_4 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
171  $relation_5 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
172 
173  return array(
174  'indexed' => array(array(0, 1, 2, 3, 4, 5)),
175  'associative' => array(array('A' => 'a', 'B' => 'b', 'C' => 'c')),
176  'mixed' => array(array(0, 'A' => 'a', 1, 'B' => 'b', 2, 3)),
177  'relations' => array(array($relation_1, $relation_2, $relation_3, $relation_4, $relation_5))
178  );
179  }

◆ setUp()

ilBuddySystemRelationCollectionTest::setUp ( )

Definition at line 21 of file ilBuddySystemRelationCollectionTest.php.

22  {
23  }

◆ testElementsCanBeAddedAndRemoved()

ilBuddySystemRelationCollectionTest::testElementsCanBeAddedAndRemoved (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 49 of file ilBuddySystemRelationCollectionTest.php.

References $data, and $key.

50  {
51  $collection = new ilBuddySystemRelationCollection();
52  $this->assertTrue($collection->isEmpty());
53 
54  foreach ($elements as $elm) {
55  $collection->add($elm);
56  $this->assertTrue($collection->contains($elm));
57  }
58 
59  foreach ($elements as $elm) {
60  $collection->removeElement($elm);
61  $this->assertFalse($collection->contains($elm));
62  }
63 
64  $this->assertTrue($collection->isEmpty());
65 
66  foreach ($elements as $elm) {
67  $collection->add($elm);
68  $this->assertTrue($collection->contains($elm));
69  }
70 
71  foreach ($elements as $elm) {
72  $key = $collection->getKey($elm);
73  $collection->remove($key);
74  $this->assertFalse($collection->contains($elm));
75  }
76 
77  $this->assertTrue($collection->isEmpty());
78 
79  foreach ($elements as $key => $elm) {
80  $collection[$key] = $elm;
81  $this->assertTrue($collection->contains($elm));
82  }
83 
84  foreach ($elements as $key => $elm) {
85  unset($collection[$key]);
86  $this->assertFalse($collection->contains($elm));
87  }
88 
89  $this->assertTrue($collection->isEmpty());
90 
91  $collection[] = 5;
92 
93  $data = $collection->toArray();
94  $this->assertSame(5, reset($data));
95  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
$key
Definition: croninfo.php:18
$data
Definition: bench.php:6

◆ testElementsCanBeFiltered()

ilBuddySystemRelationCollectionTest::testElementsCanBeFiltered ( )

Definition at line 151 of file ilBuddySystemRelationCollectionTest.php.

152  {
153  $collection = new ilBuddySystemRelationCollection();
154  $collection->add(1);
155  $collection->add(2);
156  $collection->add(3);
157  $collection->add(4);
158 
159  $this->assertSame(array(3), $collection->slice(2, 1)->getValues());
160  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...

◆ testElementsCanBeInitiallyAdded()

ilBuddySystemRelationCollectionTest::testElementsCanBeInitiallyAdded (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 29 of file ilBuddySystemRelationCollectionTest.php.

References $key.

30  {
31  $collection = new ilBuddySystemRelationCollection($elements);
32 
33  $this->assertFalse($collection->isEmpty());
34  $this->assertSame($elements, $collection->toArray());
35  $this->assertSame(array_values($elements), $collection->getValues());
36  $this->assertSame(array_keys($elements), $collection->getKeys());
37 
38  foreach ($elements as $key => $elm) {
39  $this->assertArrayHasKey($collection->getKey($elm), $elements);
40  $this->assertTrue(isset($collection[$key]));
41  $this->assertEquals($collection[$key], $elm);
42  }
43  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
$key
Definition: croninfo.php:18

◆ testElementsCanBeSliced()

ilBuddySystemRelationCollectionTest::testElementsCanBeSliced ( )

Definition at line 135 of file ilBuddySystemRelationCollectionTest.php.

References ILIAS\UI\Implementation\Component\toArray().

136  {
137  $collection = new ilBuddySystemRelationCollection();
138  $collection->add(1);
139  $collection->add(2);
140  $collection->add(3);
141  $collection->add(4);
142 
143  $this->assertCount(2, $collection->filter(function ($elm) {
144  return $elm % 2 === 0;
145  })->toArray());
146  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
toArray($value)
Wrap the given value in an array if it is no array.
+ Here is the call graph for this function:

◆ testIterator()

ilBuddySystemRelationCollectionTest::testIterator (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 101 of file ilBuddySystemRelationCollectionTest.php.

References $key.

102  {
103  $collection = new ilBuddySystemRelationCollection($elements);
104  $iterations = 0;
105  foreach ($collection->getIterator() as $key => $item) {
106  $this->assertSame($elements[$key], $item, "Item {$key} not match");
107  $iterations++;
108  }
109  $this->assertCount($iterations, $elements, "Number of iterations not match");
110  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
$key
Definition: croninfo.php:18

◆ testRemovingAnNonExistingElementByKeyRaisesAnException()

ilBuddySystemRelationCollectionTest::testRemovingAnNonExistingElementByKeyRaisesAnException ( )

InvalidArgumentException

Definition at line 125 of file ilBuddySystemRelationCollectionTest.php.

References ilBuddySystemBaseTest\assertException().

126  {
127  $this->assertException(InvalidArgumentException::class);
128  $collection = new ilBuddySystemRelationCollection();
129  $collection->remove("phpunit");
130  }
assertException($exception_class)
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
+ Here is the call graph for this function:

◆ testRemovingAnNonExistingElementRaisesAnException()

ilBuddySystemRelationCollectionTest::testRemovingAnNonExistingElementRaisesAnException ( )

InvalidArgumentException

Definition at line 115 of file ilBuddySystemRelationCollectionTest.php.

References ilBuddySystemBaseTest\assertException().

116  {
117  $this->assertException(InvalidArgumentException::class);
118  $collection = new ilBuddySystemRelationCollection();
119  $collection->removeElement(5);
120  }
assertException($exception_class)
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
+ Here is the call graph for this function:

Field Documentation

◆ $backupGlobals

ilBuddySystemRelationCollectionTest::$backupGlobals = false
protected

Definition at line 16 of file ilBuddySystemRelationCollectionTest.php.


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