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