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