ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Export\ImportHandler\Parser\NodeInfo\Attribute\Collection as ilXMLFileNodeInfoAttributeCollection;
24 use ILIAS\Export\ImportHandler\Parser\NodeInfo\Attribute\Handler as ilXMLFileNodeInfoAttributePair;
26 use ilLogger;
28 
29 class ilCollectionTest extends TestCase
30 {
31  public function testNodeInfoAttributeCollection(): void
32  {
33  $logger = $this->createMock(ilLogger::class);
34  $node_info = $this->createMock(ilXMLFileNodeInfoDOMNodeHandler::class);
35  $node_info->expects($this->any())->method('getValueOfAttribute')->will($this->returnValueMap([
36  ['key1', 'val1'],
37  ['key2', 'val2'],
38  ['key3', 'val3'],
39  ]));
40  $node_info->expects($this->any())->method('hasAttribute')->will($this->returnValueMap([
41  ['key1', true],
42  ['key2', true],
43  ['key3', true],
44  ['key4', false]
45  ]));
46  $pair1 = $this->createMock(ilXMLFileNodeInfoAttributePair::class);
47  $pair1->expects($this->any())->method('getKey')->willReturn('key1');
48  $pair1->expects($this->any())->method('getValue')->willReturn('val1');
49  $pair2 = $this->createMock(ilXMLFileNodeInfoAttributePair::class);
50  $pair2->expects($this->any())->method('getKey')->willReturn('key2');
51  $pair2->expects($this->any())->method('getValue')->willReturn('val2');
52  $pair3 = $this->createMock(ilXMLFileNodeInfoAttributePair::class);
53  $pair3->expects($this->any())->method('getKey')->willReturn('key3');
54  $pair3->expects($this->any())->method('getValue')->willReturn('val3');
55  $pair4 = $this->createMock(ilXMLFileNodeInfoAttributePair::class);
56  $pair4->expects($this->any())->method('getKey')->willReturn('key4');
57  $pair4->expects($this->any())->method('getValue')->willReturn('val4');
58 
59  $collection = (new ilXMLFileNodeInfoAttributeCollection($logger))
60  ->withElement($pair1)
61  ->withElement($pair2)
62  ->withElement($pair3);
63  $collection2 = $collection
64  ->withElement($pair4);
65 
66  $this->assertTrue($collection->matches($node_info));
67  $this->assertFalse($collection2->matches($node_info));
68  }
69 }