ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MetaDataTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use PHPUnit\Framework\TestCase;
27
28require_once('./vendor/composer/vendor/autoload.php');
29
35class MetaDataTest extends TestCase
36{
38
39 protected function setUp(): void
40 {
41 parent::setUp();
42 $this->meta_content = new MetaContent('1.0');
43 }
44
45 public function testAddMetaDatum(): void
46 {
47 $html = "test_html";
48 $html_meta_data = $this->getMockedTag($html);
49 $this->meta_content->addMetaDatum($html_meta_data);
50 $collection = $this->meta_content->getMetaData();
51
52 $first_item = $collection[0];
53 $this->assertInstanceOf(Tag::class, $first_item);
54 $this->assertSame($html, $first_item->toHtml());
55 }
56
57 public function testAddMetaDatumWithDuplicate(): void
58 {
59 $meta_datum_key = 'key';
60 $meta_datum_1_value = 'value_1';
61 $meta_datum_2_value = 'value_2';
62 $meta_datum_1 = new UserDefined($meta_datum_key, $meta_datum_1_value);
63 $meta_datum_2 = new UserDefined($meta_datum_key, $meta_datum_2_value);
64
65 $this->meta_content->addMetaDatum($meta_datum_1);
66 $first_item = $this->meta_content->getMetaData()[$meta_datum_key];
67
68 $this->assertInstanceOf(UserDefined::class, $first_item);
69 $this->assertSame($meta_datum_1_value, $first_item->getValue());
70
71 $this->meta_content->addMetaDatum($meta_datum_2);
72 $first_item = $this->meta_content->getMetaData()[$meta_datum_key];
73
74 $this->assertInstanceOf(UserDefined::class, $first_item);
75 $this->assertNotSame($meta_datum_1_value, $first_item->getValue());
76 $this->assertSame($meta_datum_2_value, $first_item->getValue());
77 }
78
79 public function getMockedTag(string $html): Tag
80 {
81 return new class ($html) extends Tag {
82 public function __construct(
83 protected string $html
84 ) {
85 }
86
87 public function toHtml(): string
88 {
89 return $this->html;
90 }
91 };
92 }
93}
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
@noinspection PhpIncompatibleReturnTypeInspection