ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
OpenGraphMetadataTest Class Reference
+ Inheritance diagram for OpenGraphMetadataTest:
+ Collaboration diagram for OpenGraphMetadataTest:

Public Member Functions

 testTextTag ()
 
 testLinkTag ()
 
 testAudioTag ()
 
 testImageTag ()
 
 testVideoTag ()
 
 testWebsiteTag ()
 

Protected Member Functions

 setUp ()
 
 getMockedResource (string $html)
 
 getMockedImage (string $html)
 
 getMockedUrl (string $url)
 

Protected Attributes

Factory $factory
 

Detailed Description

Member Function Documentation

◆ getMockedImage()

OpenGraphMetadataTest::getMockedImage ( string  $html)
protected

Definition at line 185 of file OpenGraphMetadataTest.php.

Referenced by testWebsiteTag().

185  : Image
186  {
187  $mock_image = $this->createMock(Image::class);
188  $mock_image->method('toHtml')->willReturn($html);
189  $mock_image->method('getTags')->willReturnCallback(
190  static function () use ($mock_image): Generator {
191  yield $mock_image;
192  }
193  );
194 
195  return $mock_image;
196  }
+ Here is the caller graph for this function:

◆ getMockedResource()

OpenGraphMetadataTest::getMockedResource ( string  $html)
protected

Definition at line 172 of file OpenGraphMetadataTest.php.

Referenced by testWebsiteTag().

172  : Resource
173  {
174  $mock_resource = $this->createMock(Resource::class);
175  $mock_resource->method('toHtml')->willReturn($html);
176  $mock_resource->method('getTags')->willReturnCallback(
177  static function () use ($mock_resource): Generator {
178  yield $mock_resource;
179  }
180  );
181 
182  return $mock_resource;
183  }
+ Here is the caller graph for this function:

◆ getMockedUrl()

OpenGraphMetadataTest::getMockedUrl ( string  $url)
protected

Definition at line 198 of file OpenGraphMetadataTest.php.

Referenced by testAudioTag(), testImageTag(), testLinkTag(), testVideoTag(), and testWebsiteTag().

198  : URI
199  {
200  $mock_url = $this->createMock(URI::class);
201  $mock_url->method('__toString')->willReturn($url);
202 
203  return $mock_url;
204  }
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:18
$url
Definition: ltiregstart.php:35
+ Here is the caller graph for this function:

◆ setUp()

OpenGraphMetadataTest::setUp ( )
protected

Definition at line 35 of file OpenGraphMetadataTest.php.

35  : void
36  {
37  $this->factory = new Factory();
38  }

◆ testAudioTag()

OpenGraphMetadataTest::testAudioTag ( )

Definition at line 66 of file OpenGraphMetadataTest.php.

References getMockedUrl().

66  : void
67  {
68  $expected_url = 'test_url';
69  $expected_mime = 'test_mime_type';
70  $expected_html =
71  "<meta property=\"og:audio\" content=\"$expected_url\" />" . PHP_EOL .
72  "<meta property=\"og:audio:type\" content=\"$expected_mime\" />" . PHP_EOL;
73 
74  $audio_tag = $this->factory->audio($this->getMockedUrl($expected_url), $expected_mime);
75 
76  $this->assertEquals($expected_html, $audio_tag->toHtml());
77  }
+ Here is the call graph for this function:

◆ testImageTag()

OpenGraphMetadataTest::testImageTag ( )

Definition at line 79 of file OpenGraphMetadataTest.php.

References getMockedUrl().

79  : void
80  {
81  $expected_url = 'test_url';
82  $expected_mime = 'test_mime_type';
83  $expected_alt = 'test_aria_label';
84  $expected_width = 200;
85  $expected_height = 100;
86  $expected_html =
87  "<meta property=\"og:image\" content=\"$expected_url\" />" . PHP_EOL .
88  "<meta property=\"og:image:type\" content=\"$expected_mime\" />" . PHP_EOL .
89  "<meta property=\"og:image:alt\" content=\"$expected_alt\" />" . PHP_EOL .
90  "<meta property=\"og:image:width\" content=\"$expected_width\" />" . PHP_EOL .
91  "<meta property=\"og:image:height\" content=\"$expected_height\" />" . PHP_EOL;
92 
93  $image_tag = $this->factory->image(
94  $this->getMockedUrl($expected_url),
95  $expected_mime,
96  $expected_alt,
97  $expected_width,
98  $expected_height
99  );
100 
101  $this->assertEquals($expected_html, $image_tag->toHtml());
102  }
+ Here is the call graph for this function:

◆ testLinkTag()

OpenGraphMetadataTest::testLinkTag ( )

Definition at line 53 of file OpenGraphMetadataTest.php.

References getMockedUrl().

53  : void
54  {
55  $property = 'test_property';
56  $value = 'test_value';
57 
58  $link_tag = new Link($property, $this->getMockedUrl($value));
59 
60  $this->assertEquals(
61  "<meta property=\"$property\" content=\"$value\" />",
62  $link_tag->toHtml()
63  );
64  }
+ Here is the call graph for this function:

◆ testTextTag()

OpenGraphMetadataTest::testTextTag ( )

Definition at line 40 of file OpenGraphMetadataTest.php.

40  : void
41  {
42  $property = 'test_property';
43  $value = 'test_value';
44 
45  $link_tag = new Text($property, $value);
46 
47  $this->assertEquals(
48  "<meta property=\"$property\" content=\"$value\" />",
49  $link_tag->toHtml()
50  );
51  }

◆ testVideoTag()

OpenGraphMetadataTest::testVideoTag ( )

Definition at line 104 of file OpenGraphMetadataTest.php.

References getMockedUrl().

104  : void
105  {
106  $expected_url = 'test_url';
107  $expected_mime = 'test_mime_type';
108  $expected_width = 200;
109  $expected_height = 100;
110  $expected_html =
111  "<meta property=\"og:video\" content=\"$expected_url\" />" . PHP_EOL .
112  "<meta property=\"og:video:type\" content=\"$expected_mime\" />" . PHP_EOL .
113  "<meta property=\"og:video:width\" content=\"$expected_width\" />" . PHP_EOL .
114  "<meta property=\"og:video:height\" content=\"$expected_height\" />" . PHP_EOL;
115 
116  $video_tag = $this->factory->video(
117  $this->getMockedUrl($expected_url),
118  $expected_mime,
119  $expected_width,
120  $expected_height
121  );
122 
123  $this->assertEquals($expected_html, $video_tag->toHtml());
124  }
+ Here is the call graph for this function:

◆ testWebsiteTag()

OpenGraphMetadataTest::testWebsiteTag ( )

Definition at line 126 of file OpenGraphMetadataTest.php.

References getMockedImage(), getMockedResource(), and getMockedUrl().

126  : void
127  {
128  $expected_canonical_url = 'test_canonical_url';
129  $expected_image_html = 'test_image_html';
130  $expected_object_title = 'test_object_title';
131  $expected_website_name = 'test_website_name';
132  $expected_description = 'test_description';
133  $expected_locale = 'test_locale';
134  $expected_locale_alt_1 = 'test_locale_alt_1';
135  $expected_locale_alt_2 = 'test_locale_alt_2';
136  $expected_additional_resource_html_1 = 'test_additional_resource_html_1';
137  $expected_additional_resource_html_2 = 'test_additional_resource_html_2';
138 
139  $expected_html =
140  "<meta property=\"og:type\" content=\"website\" />" . PHP_EOL .
141  "<meta property=\"og:title\" content=\"test_object_title\" />" . PHP_EOL .
142  "<meta property=\"og:url\" content=\"test_canonical_url\" />" . PHP_EOL .
143  $expected_image_html . PHP_EOL .
144  "<meta property=\"og:site_title\" content=\"test_website_name\" />" . PHP_EOL .
145  "<meta property=\"og:description\" content=\"test_description\" />" . PHP_EOL .
146  "<meta property=\"og:locale\" content=\"test_locale\" />" . PHP_EOL .
147  "<meta property=\"og:locale:alternative\" content=\"test_locale_alt_1\" />" . PHP_EOL .
148  "<meta property=\"og:locale:alternative\" content=\"test_locale_alt_2\" />" . PHP_EOL .
149  $expected_additional_resource_html_1 . PHP_EOL .
150  $expected_additional_resource_html_2 . PHP_EOL;
151 
152  $website_tag = $this->factory->website(
153  $this->getMockedUrl($expected_canonical_url),
154  $this->getMockedImage($expected_image_html),
155  $expected_object_title,
156  $expected_website_name,
157  $expected_description,
158  $expected_locale,
159  [
160  $expected_locale_alt_1,
161  $expected_locale_alt_2,
162  ],
163  [
164  $this->getMockedResource($expected_additional_resource_html_1),
165  $this->getMockedResource($expected_additional_resource_html_2),
166  ]
167  );
168 
169  $this->assertEquals($expected_html, $website_tag->toHtml());
170  }
+ Here is the call graph for this function:

Field Documentation

◆ $factory

Factory OpenGraphMetadataTest::$factory
protected

Definition at line 33 of file OpenGraphMetadataTest.php.


The documentation for this class was generated from the following file: