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