ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilWebResourceItemTest Class Reference

Unit tests for ilWebLinkItem. More...

+ Inheritance diagram for ilWebResourceItemTest:
+ Collaboration diagram for ilWebResourceItemTest:

Public Member Functions

 testToXML ()
 

Detailed Description

Unit tests for ilWebLinkItem.

Author
Tim Schmitz schmi.nosp@m.tz@l.nosp@m.eifos.nosp@m..com

Definition at line 27 of file ilWebResourceItemTest.php.

Member Function Documentation

◆ testToXML()

ilWebResourceItemTest::testToXML ( )

Definition at line 29 of file ilWebResourceItemTest.php.

29 : void
30 {
31 $writer = $this->getMockBuilder(ilXmlWriter::class)
32 ->disableOriginalConstructor()
33 ->onlyMethods(['xmlStartTag', 'xmlElement', 'xmlEndTag'])
34 ->getMock();
35 $writer->expects($this->once())
36 ->method('xmlStartTag')
37 ->with('WebLink', [
38 'id' => 13,
39 'active' => 1,
40 'position' => 7,
41 'internal' => 0
42 ]);
43 /*
44 * willReturnCallback is a workaround to replace withConsecutive.
45 * The return value is irrelevant here, but if an unexpected parameter
46 * is passed, an exception will be thrown (instead of an assumption being
47 * broken as before).
48 * These tests should be rewritten to rely much less on PHPUnit for mocking.
49 */
50 $writer->expects($this->exactly(3))
51 ->method('xmlElement')
52 ->willReturnCallback(fn($tag, $attrs, $data) => match([$tag, $attrs, $data]) {
53 ['Title', [], 'title'] => 1,
54 ['Description', [], 'description'] => 2,
55 ['Target', [], 'target'] => 3
56 });
57 $writer->expects($this->once())
58 ->method('xmlEndTag')
59 ->with('WebLink');
60
61 $param1 = $this->getMockBuilder(ilWebLinkParameter::class)
62 ->disableOriginalConstructor()
63 ->onlyMethods(['toXML'])
64 ->getMock();
65 $param1->expects($this->once())
66 ->method('toXML')
67 ->with($writer);
68 $param2 = $this->getMockBuilder(ilWebLinkParameter::class)
69 ->disableOriginalConstructor()
70 ->onlyMethods(['toXML'])
71 ->getMock();
72 $param2->expects($this->once())
73 ->method('toXML')
74 ->with($writer);
75
76 $item_stub = new class (
77 1,
78 13,
79 'title',
80 'description',
81 'target',
82 true,
83 new DateTimeImmutable(),
84 new DateTimeImmutable(),
85 [$param1, $param2]
86 ) extends ilWebLinkItem {
87 public function getResolvedLink(bool $with_parameters = true): string
88 {
89 return '';
90 }
91
92 public function isInternal(): bool
93 {
94 return false;
95 }
96 };
97 $item_stub->toXML($writer, 7);
98 }
Immutable class for Web Link items.

References $data.


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