ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ILIAS\Export\ImportHandler\I\File\Namespace\ilCollectionInterface as ilFileNamespaceCollectionInterface;
25 use ILIAS\Export\ImportHandler\File\Namespace\ilHandler as ilFileNamespaceHandler;
26 use ILIAS\Export\ImportHandler\File\Namespace\ilCollection as ilFileNamespaceCollection;
27 
28 class ilCollectionTest extends TestCase
29 {
30  protected function setUp(): void
31  {
32  $namespace_1 = $this->createMock(ilFileNamespaceHandler::class);
33  }
34 
38  protected function checkCollection(
39  ilFileNamespaceCollectionInterface $collection,
40  array $expected_elements
41  ) {
42  $this->assertSameSize($expected_elements, $collection);
43  $collection->rewind();
44  $this->assertEquals(0, $collection->key());
45  for ($i = 0; $i < $collection->count(); $i++) {
46  $current = $collection->current();
47  $this->assertTrue($collection->valid());
48  $this->assertEquals($i, $collection->key());
49  $this->assertEquals($expected_elements[$i], $current);
50  $collection->next();
51  }
52  $collection->rewind();
53  $this->assertEquals(0, $collection->key());
54  }
55 
56  public function testCollection(): void
57  {
58  $namespace_1 = $this->createMock(ilFileNamespaceHandler::class);
59  $namespace_1->expects($this->any())->method('getNamespace')->willReturn('namespace_1');
60  $namespace_1->expects($this->any())->method('getPrefix')->willReturn('prefix_1');
61 
62  $namespace_2 = $this->createMock(ilFileNamespaceHandler::class);
63  $namespace_2->expects($this->any())->method('getNamespace')->willReturn('namespace_2');
64  $namespace_2->expects($this->any())->method('getPrefix')->willReturn('prefix_2');
65 
66  $namespace_3 = $this->createMock(ilFileNamespaceHandler::class);
67  $namespace_3->expects($this->any())->method('getNamespace')->willReturn('namespace_3');
68  $namespace_3->expects($this->any())->method('getPrefix')->willReturn('prefix_3');
69 
70  $collection_one_element = (new ilFileNamespaceCollection())
71  ->withElement($namespace_1);
72  $collection_two_elements = (new ilFileNamespaceCollection())
73  ->withElement($namespace_1)
74  ->withElement($namespace_2);
75  $collection_three_elements = (new ilFileNamespaceCollection())
76  ->withElement($namespace_1)
77  ->withElement($namespace_2)
78  ->withElement($namespace_3);
79  $merged_collection = $collection_three_elements->withMerged($collection_two_elements);
80 
81  $this->checkCollection($collection_one_element, [$namespace_1]);
82  $this->checkCollection($collection_two_elements, [$namespace_1, $namespace_2]);
83  $this->checkCollection($collection_three_elements, [$namespace_1, $namespace_2, $namespace_3]);
84  $this->checkCollection($merged_collection, [$namespace_1, $namespace_2, $namespace_3, $namespace_1, $namespace_2]);
85  }
86 }
checkCollection(ilFileNamespaceCollectionInterface $collection, array $expected_elements)