ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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
 

Detailed Description

Member Function Documentation

◆ provideElements()

ilBuddySystemRelationCollectionTest::provideElements ( )
Returns
array

Definition at line 169 of file ilBuddySystemRelationCollectionTest.php.

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

◆ setUp()

ilBuddySystemRelationCollectionTest::setUp ( )

Definition at line 19 of file ilBuddySystemRelationCollectionTest.php.

20  {
21  }

◆ testElementsCanBeAddedAndRemoved()

ilBuddySystemRelationCollectionTest::testElementsCanBeAddedAndRemoved (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 48 of file ilBuddySystemRelationCollectionTest.php.

References $data.

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

◆ testElementsCanBeFiltered()

ilBuddySystemRelationCollectionTest::testElementsCanBeFiltered ( )

Definition at line 155 of file ilBuddySystemRelationCollectionTest.php.

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

◆ testElementsCanBeInitiallyAdded()

ilBuddySystemRelationCollectionTest::testElementsCanBeInitiallyAdded (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 27 of file ilBuddySystemRelationCollectionTest.php.

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

◆ testElementsCanBeSliced()

ilBuddySystemRelationCollectionTest::testElementsCanBeSliced ( )

Definition at line 139 of file ilBuddySystemRelationCollectionTest.php.

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

◆ testIterator()

ilBuddySystemRelationCollectionTest::testIterator (   $elements)

provideElements

Parameters
$elementsarray

Definition at line 106 of file ilBuddySystemRelationCollectionTest.php.

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

◆ testRemovingAnNonExistingElementByKeyRaisesAnException()

ilBuddySystemRelationCollectionTest::testRemovingAnNonExistingElementByKeyRaisesAnException ( )

InvalidArgumentException

Definition at line 130 of file ilBuddySystemRelationCollectionTest.php.

131  {
132  $collection = new ilBuddySystemRelationCollection();
133  $collection->remove("phpunit");
134  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...

◆ testRemovingAnNonExistingElementRaisesAnException()

ilBuddySystemRelationCollectionTest::testRemovingAnNonExistingElementRaisesAnException ( )

InvalidArgumentException

Definition at line 121 of file ilBuddySystemRelationCollectionTest.php.

122  {
123  $collection = new ilBuddySystemRelationCollection();
124  $collection->removeElement(5);
125  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...

Field Documentation

◆ $backupGlobals

ilBuddySystemRelationCollectionTest::$backupGlobals = false
protected

Definition at line 14 of file ilBuddySystemRelationCollectionTest.php.


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