ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
 assertException ($exception_class)
 

Detailed Description

Member Function Documentation

◆ provideElements()

ilBuddySystemRelationCollectionTest::provideElements ( )
Returns
array

Definition at line 173 of file ilBuddySystemRelationCollectionTest.php.

References array.

174  {
175  $relation_1 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
176  $relation_2 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
177  $relation_3 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
178  $relation_4 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
179  $relation_5 = $this->getMockBuilder('ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
180 
181  return array(
182  'indexed' => array(array(0, 1, 2, 3, 4, 5)),
183  'associative' => array(array('A' => 'a', 'B' => 'b', 'C' => 'c')),
184  'mixed' => array(array(0, 'A' => 'a', 1, 'B' => 'b', 2, 3)),
185  'relations' => array(array($relation_1, $relation_2, $relation_3, $relation_4, $relation_5))
186  );
187  }
Create styles array
The data for the language used.

◆ setUp()

ilBuddySystemRelationCollectionTest::setUp ( )

Definition at line 21 of file ilBuddySystemRelationCollectionTest.php.

22  {
23  }

◆ testElementsCanBeAddedAndRemoved()

ilBuddySystemRelationCollectionTest::testElementsCanBeAddedAndRemoved (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 50 of file ilBuddySystemRelationCollectionTest.php.

References $data.

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

◆ testElementsCanBeFiltered()

ilBuddySystemRelationCollectionTest::testElementsCanBeFiltered ( )

Definition at line 159 of file ilBuddySystemRelationCollectionTest.php.

References array.

160  {
161  $collection = new ilBuddySystemRelationCollection();
162  $collection->add(1);
163  $collection->add(2);
164  $collection->add(3);
165  $collection->add(4);
166 
167  $this->assertSame(array(3), $collection->slice(2, 1)->getValues());
168  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Create styles array
The data for the language used.

◆ testElementsCanBeInitiallyAdded()

ilBuddySystemRelationCollectionTest::testElementsCanBeInitiallyAdded (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 29 of file ilBuddySystemRelationCollectionTest.php.

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  {
40  $this->assertArrayHasKey($collection->getKey($elm), $elements);
41  $this->assertTrue(isset($collection[$key]));
42  $this->assertEquals($collection[$key], $elm);
43  }
44  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...

◆ testElementsCanBeSliced()

ilBuddySystemRelationCollectionTest::testElementsCanBeSliced ( )

Definition at line 143 of file ilBuddySystemRelationCollectionTest.php.

144  {
145  $collection = new ilBuddySystemRelationCollection();
146  $collection->add(1);
147  $collection->add(2);
148  $collection->add(3);
149  $collection->add(4);
150 
151  $this->assertCount(2, $collection->filter(function($elm) {
152  return $elm % 2 === 0;
153  })->toArray());
154  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...

◆ testIterator()

ilBuddySystemRelationCollectionTest::testIterator (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 108 of file ilBuddySystemRelationCollectionTest.php.

109  {
110  $collection = new ilBuddySystemRelationCollection($elements);
111  $iterations = 0;
112  foreach($collection->getIterator() as $key => $item)
113  {
114  $this->assertSame($elements[$key], $item, "Item {$key} not match");
115  $iterations++;
116  }
117  $this->assertCount($iterations, $elements, "Number of iterations not match");
118  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...

◆ testRemovingAnNonExistingElementByKeyRaisesAnException()

ilBuddySystemRelationCollectionTest::testRemovingAnNonExistingElementByKeyRaisesAnException ( )

InvalidArgumentException

Definition at line 133 of file ilBuddySystemRelationCollectionTest.php.

References ilBuddySystemBaseTest\assertException().

134  {
135  $this->assertException(InvalidArgumentException::class);
136  $collection = new ilBuddySystemRelationCollection();
137  $collection->remove("phpunit");
138  }
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 123 of file ilBuddySystemRelationCollectionTest.php.

References ilBuddySystemBaseTest\assertException().

124  {
125  $this->assertException(InvalidArgumentException::class);
126  $collection = new ilBuddySystemRelationCollection();
127  $collection->removeElement(5);
128  }
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: