ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
HtmlMetadataTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
27
31class HtmlMetadataTest extends TestCase
32{
33 protected Factory $factory;
34
35 protected function setUp(): void
36 {
37 $this->factory = new Factory();
38 }
39
40 public function testNullTag(): void
41 {
42 $null_tag = $this->factory->nullTag();
43
44 $this->assertInstanceOf(NullTag::class, $null_tag);
45 $this->assertEmpty($null_tag->toHtml());
46 }
47
48 public function testTagCollection(): void
49 {
50 $test_tag_1_html = 'test_tag_1_html';
51 $test_tag_1 = $this->getMockedTag($test_tag_1_html);
52
53 $test_tag_2_html = 'test_tag_2_html';
54 $test_tag_2 = $this->getMockedTag($test_tag_2_html);
55
56 $expected_html = $test_tag_1_html . PHP_EOL . $test_tag_2_html . PHP_EOL;
57
58 $tag_collection = $this->factory->collection([$test_tag_1, $test_tag_2]);
59
60 $this->assertCount(2, iterator_to_array($tag_collection->getTags()));
61 $this->assertEquals($expected_html, $tag_collection->toHtml());
62 }
63
64 public function testEmptyTagCollection(): void
65 {
66 $tag_collection = $this->factory->collection([]);
67
68 $this->assertEmpty(iterator_to_array($tag_collection->getTags()));
69 $this->assertEmpty($tag_collection->toHtml());
70 }
71
72 public function testNestedTagCollection(): void
73 {
74 $test_tag_1_html = 'test_tag_1_html';
75 $test_tag_1 = $this->getMockedTag($test_tag_1_html);
76
77 $test_tag_2_html = 'test_tag_2_html';
78 $test_tag_2 = $this->getMockedTag($test_tag_2_html);
79
80 $test_tag_3_html = 'test_tag_3_html';
81 $test_tag_3 = $this->getMockedTag($test_tag_3_html);
82
83 $expected_html = $test_tag_1_html . PHP_EOL . $test_tag_2_html . PHP_EOL . $test_tag_3_html . PHP_EOL;
84
85 $tag_collection = $this->factory->collection([
86 $this->factory->collection([$test_tag_1, $test_tag_2]),
87 $test_tag_3,
88 ]);
89
90 $this->assertCount(3, iterator_to_array($tag_collection->getTags()));
91 $this->assertEquals($expected_html, $tag_collection->toHtml());
92 }
93
94 public function testUserDefinedTag(): void
95 {
96 $key = 'expected_key';
97 $val = 'expected_value';
98
99 $user_defined_tag = $this->factory->userDefined($key, $val);
100
101 $this->assertInstanceOf(UserDefined::class, $user_defined_tag);
102 $this->assertEquals(
103 "<meta name=\"$key\" content=\"$val\" />",
104 $user_defined_tag->toHtml()
105 );
106 }
107
108 public function getMockedTag(string $html): Tag
109 {
110 return new class ($html) extends Tag {
111 public function __construct(
112 protected string $html
113 ) {
114 }
115
116 public function toHtml(): string
117 {
118 return $this->html;
119 }
120 };
121 }
122}
factory()
getMockedTag(string $html)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc