55 * @package ActivityPub
66 */
77
8- namespace ActivityPub ;
8+ namespace Activitypub \ Tests ;
99
10- use PHPUnit \ Framework \ TestCase ;
10+ use Activitypub \ Embed ;
1111
1212/**
1313 * Test the Embed class.
14+ *
15+ * @coversDefaultClass \ActivityPub\Embed
1416 */
15- class Test_Embed extends TestCase {
17+ class Test_Embed extends \WP_UnitTestCase {
1618 /**
1719 * Test the has_real_oembed method with a URL that has a real oEmbed.
20+ *
21+ * @covers ::has_real_oembed
1822 */
1923 public function test_has_real_oembed_with_real_oembed () {
2024 // Define the filter function.
@@ -36,6 +40,8 @@ public function test_has_real_oembed_with_real_oembed() {
3640
3741 /**
3842 * Test the has_real_oembed method with a URL that doesn't have a real oEmbed.
43+ *
44+ * @covers ::has_real_oembed
3945 */
4046 public function test_has_real_oembed_without_real_oembed () {
4147 // Add our filter.
@@ -52,6 +58,8 @@ public function test_has_real_oembed_without_real_oembed() {
5258
5359 /**
5460 * Test the maybe_use_activitypub_embed method when a result is already provided.
61+ *
62+ * @covers ::maybe_use_activitypub_embed
5563 */
5664 public function test_maybe_use_activitypub_embed_with_result () {
5765 // Call the method with a non-null result.
@@ -62,6 +70,8 @@ public function test_maybe_use_activitypub_embed_with_result() {
6270
6371 /**
6472 * Test the maybe_use_activitypub_embed method when no result is provided but a real oEmbed is found.
73+ *
74+ * @covers ::maybe_use_activitypub_embed
6575 */
6676 public function test_maybe_use_activitypub_embed_with_real_oembed () {
6777 // Create a test double for Embed that returns true for has_real_oembed.
@@ -80,6 +90,8 @@ public function test_maybe_use_activitypub_embed_with_real_oembed() {
8090
8191 /**
8292 * Test the handle_filtered_oembed_result method when HTML is already provided.
93+ *
94+ * @covers ::handle_filtered_oembed_result
8395 */
8496 public function test_handle_filtered_oembed_result_with_html () {
8597 // Call the method with HTML already provided.
@@ -90,6 +102,8 @@ public function test_handle_filtered_oembed_result_with_html() {
90102
91103 /**
92104 * Test the handle_filtered_oembed_result method when the data type is not rich or video.
105+ *
106+ * @covers ::handle_filtered_oembed_result
93107 */
94108 public function test_handle_filtered_oembed_result_with_non_rich_data () {
95109 // Call the method with a non-rich data type.
@@ -106,6 +120,8 @@ public function test_handle_filtered_oembed_result_with_non_rich_data() {
106120
107121 /**
108122 * Test the handle_filtered_oembed_result method when there's no HTML in the data.
123+ *
124+ * @covers ::handle_filtered_oembed_result
109125 */
110126 public function test_handle_filtered_oembed_result_without_html () {
111127 // Call the method with no HTML in the data.
@@ -119,4 +135,36 @@ public function test_handle_filtered_oembed_result_without_html() {
119135
120136 $ this ->assertEquals ( '' , $ result );
121137 }
138+
139+ /**
140+ * Test the get_html_for_object method.
141+ *
142+ * @covers ::get_html_for_object
143+ */
144+ public function test_get_html_for_object () {
145+ // Create a test object.
146+ $ object = array (
147+ 'id ' => 'https://example.com/post ' ,
148+ 'url ' => 'https://example.com/post ' ,
149+ 'content ' => 'This is a test post. ' ,
150+ 'attachment ' => array (
151+ array (
152+ 'type ' => 'Document ' ,
153+ 'url ' => 'https://example.com/image1.jpg ' ,
154+ 'mediaType ' => 'image/jpeg ' ,
155+ ),
156+ array (
157+ 'type ' => 'Image ' ,
158+ 'url ' => 'https://example.com/image2.jpg ' ,
159+ 'mediaType ' => 'image/jpeg ' ,
160+ ),
161+ ),
162+ );
163+
164+ // Call the method.
165+ $ result = Embed::get_html_for_object ( $ object );
166+
167+ $ this ->assertStringContainsString ( 'https://example.com/image1.jpg ' , $ result );
168+ $ this ->assertStringContainsString ( 'https://example.com/image2.jpg ' , $ result );
169+ }
122170}
0 commit comments