ILIAS
release_9 Revision v9.13-25-g2c18ec4c24f
◀ ilDoc Overview
ilDOMNodeHandlerTest.php
Go to the documentation of this file.
1
<?php
2
19
declare(strict_types=1);
20
21
namespace
Test\ImportHandler\File\XML\Node\Info
;
22
23
use
PHPUnit\Framework\TestCase
;
24
25
class
ilDOMNodeHandlerTest
extends
TestCase
26
{
27
public
function
testXMLFileNodeInfo
(): void
28
{
29
// Problem: a lot of the attributes of domnodes are read only.
30
/*
31
$xml_str = '<Nodes test="super"><Node></Node><Node></Node><Node></Node></Nodes>';
32
33
$attribute_1 = $this->createMock(DOMAttr::class);
34
$attribute_1->name = 'test';
35
$attribute_1->value = 'super';
36
$attribute_iterator_elements = [
37
$attribute_1
38
];
39
$attribute_iterator = new class($attribute_iterator_elements) implements \Iterator {
40
protected array $children;
41
protected int $index;
42
public function __construct(array $children)
43
{
44
$this->children = $children;
45
$this->index = 0;
46
}
47
public function current(): mixed
48
{
49
return $this->children[$this->index];
50
}
51
public function next(): void
52
{
53
$this->index++;
54
}
55
public function key(): mixed
56
{
57
return $this->index;
58
}
59
public function valid(): bool
60
{
61
return 0 <= $this->index && $this->index < count($this->children);
62
}
63
public function rewind(): void
64
{
65
$this->index = 0;
66
}
67
};
68
69
$dom_named_node_map = $this->createMock(DOMNamedNodeMap::class);
70
$dom_named_node_map->expects($this->any())->method('getIterator')->willReturn($attribute_iterator);
71
72
$dom_document = $this->createMock(DOMDocument::class);
73
$dom_document->expects($this->any())->method('saveXML')->willReturn($xml_str);
74
75
$iterator_elements = [
76
$this->createMock(DOMNode::class),
77
$this->createMock(DOMNode::class),
78
$this->createMock(DOMNode::class)
79
];
80
$child_iterator = new class($iterator_elements) implements \Iterator {
81
protected array $children;
82
protected int $index;
83
public function __construct(array $children)
84
{
85
$this->children = $children;
86
$this->index = 0;
87
}
88
public function current(): mixed
89
{
90
return $this->children[$this->index];
91
}
92
public function next(): void
93
{
94
$this->index++;
95
}
96
public function key(): mixed
97
{
98
return $this->index;
99
}
100
public function valid(): bool
101
{
102
return 0 <= $this->index && $this->index < count($this->children);
103
}
104
public function rewind(): void
105
{
106
$this->index = 0;
107
}
108
};
109
110
$child_nodes = $this->createMock(DOMNodeList::class);
111
$child_nodes->expects($this->any())->method('getIterator')->willReturn($child_iterator);
112
113
$parent_node = $this->createMock(DOMNode::class);
114
$parent_node->nodeName = 'testParentName';
115
116
$dom_node = $this->createMock(DOMNode::class);
117
$dom_node->attributes = $dom_named_node_map;
118
$dom_node->ownerDocument = $dom_document;
119
$dom_node->nodeName = 'testName';
120
$dom_node->childNodes = $child_nodes;
121
$dom_node->parentNode = $parent_node;
122
123
$info = $this->createMock(ilFileXMLNodeInfoFactory::class);
124
125
$node_info_handler = new ilFileXMLNodeInfoDOMNodeHandler($info);
126
127
$this->assertTrue($node_info_handler->hasAttribute('test'));
128
$this->assertFalse($node_info_handler->hasAttribute('args'));
129
$this->assertEquals('super', $node_info_handler->getValueOfAttribute('test'));
130
$this->assertEquals($xml_str, $node_info_handler->getXML());
131
$this->assertEquals('testName', $node_info_handler->getNodeName());
132
$this->assertCount(3, $node_info_handler->getChildren());
133
$this->assertEquals('testParentName', $node_info_handler->getParent()->getNodeName());
134
135
node_info_handler->getAttributePath();
136
*/
137
$this->assertTrue(
true
);
138
}
139
}
Test\ImportHandler\File\XML\Node\Info\ilDOMNodeHandlerTest
Definition:
ilDOMNodeHandlerTest.php:25
Test\ImportHandler\File\XML\Node\Info
Test\ImportHandler\File\XML\Node\Info\ilDOMNodeHandlerTest\testXMLFileNodeInfo
testXMLFileNodeInfo()
Definition:
ilDOMNodeHandlerTest.php:27
TestCase
Services
Export
test
ImportHandler
File
XML
Node
Info
ilDOMNodeHandlerTest.php
Generated on Wed Sep 10 2025 14:11:28 for ILIAS by
1.8.13 (using
Doxyfile
)