5
5
* @package ActivityPub
6
6
*/
7
7
8
- namespace ActivityPub ;
8
+ namespace Activitypub \ Tests ;
9
9
10
- use PHPUnit \ Framework \ TestCase ;
10
+ use Activitypub \ Embed ;
11
11
12
12
/**
13
13
* Test the Embed class.
14
+ *
15
+ * @coversDefaultClass \ActivityPub\Embed
14
16
*/
15
- class Test_Embed extends TestCase {
17
+ class Test_Embed extends \WP_UnitTestCase {
16
18
/**
17
19
* Test the has_real_oembed method with a URL that has a real oEmbed.
20
+ *
21
+ * @covers ::has_real_oembed
18
22
*/
19
23
public function test_has_real_oembed_with_real_oembed () {
20
24
// Define the filter function.
@@ -36,6 +40,8 @@ public function test_has_real_oembed_with_real_oembed() {
36
40
37
41
/**
38
42
* Test the has_real_oembed method with a URL that doesn't have a real oEmbed.
43
+ *
44
+ * @covers ::has_real_oembed
39
45
*/
40
46
public function test_has_real_oembed_without_real_oembed () {
41
47
// Add our filter.
@@ -52,6 +58,8 @@ public function test_has_real_oembed_without_real_oembed() {
52
58
53
59
/**
54
60
* Test the maybe_use_activitypub_embed method when a result is already provided.
61
+ *
62
+ * @covers ::maybe_use_activitypub_embed
55
63
*/
56
64
public function test_maybe_use_activitypub_embed_with_result () {
57
65
// Call the method with a non-null result.
@@ -62,6 +70,8 @@ public function test_maybe_use_activitypub_embed_with_result() {
62
70
63
71
/**
64
72
* 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
65
75
*/
66
76
public function test_maybe_use_activitypub_embed_with_real_oembed () {
67
77
// 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() {
80
90
81
91
/**
82
92
* Test the handle_filtered_oembed_result method when HTML is already provided.
93
+ *
94
+ * @covers ::handle_filtered_oembed_result
83
95
*/
84
96
public function test_handle_filtered_oembed_result_with_html () {
85
97
// Call the method with HTML already provided.
@@ -90,6 +102,8 @@ public function test_handle_filtered_oembed_result_with_html() {
90
102
91
103
/**
92
104
* Test the handle_filtered_oembed_result method when the data type is not rich or video.
105
+ *
106
+ * @covers ::handle_filtered_oembed_result
93
107
*/
94
108
public function test_handle_filtered_oembed_result_with_non_rich_data () {
95
109
// Call the method with a non-rich data type.
@@ -106,6 +120,8 @@ public function test_handle_filtered_oembed_result_with_non_rich_data() {
106
120
107
121
/**
108
122
* Test the handle_filtered_oembed_result method when there's no HTML in the data.
123
+ *
124
+ * @covers ::handle_filtered_oembed_result
109
125
*/
110
126
public function test_handle_filtered_oembed_result_without_html () {
111
127
// Call the method with no HTML in the data.
@@ -119,4 +135,36 @@ public function test_handle_filtered_oembed_result_without_html() {
119
135
120
136
$ this ->assertEquals ( '' , $ result );
121
137
}
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
+ }
122
170
}
0 commit comments