| 201 | | function test_get_attached_image_srcs() { |
| 202 | | $post_id = $this->factory->post->create(); |
| 203 | | $this->factory->attachment->create_object( $this->img_name, $post_id, array( |
| 204 | | 'post_mime_type' => 'image/jpeg', |
| 205 | | 'post_type' => 'attachment' |
| 206 | | ) ); |
| 207 | | |
| 208 | | $images = get_attached_image_srcs( $post_id ); |
| 209 | | $this->assertEquals( $images, array( $this->img_url ) ); |
| 210 | | } |
| 211 | | |
| 212 | | /** |
| 213 | | * @ticket 22960 |
| 214 | | */ |
| 215 | | function test_content_images() { |
| 216 | | $src1 = $this->img_url; |
| 217 | | $html1 = $this->img_html; |
| 218 | | $src2 = str_replace( '.jpg', '2.jpg', $this->img_url ); |
| 219 | | $html2 = str_replace( $src1, $src2, $this->img_html ); |
| 220 | | $src3 = str_replace( '.jpg', '3.jpg', $this->img_url ); |
| 221 | | $html3 = str_replace( $src1, $src3, $this->img_html ); |
| 222 | | |
| 223 | | $blob =<<<BLOB |
| 224 | | This is a sentence that will all of a sudden contain {$html1} and then {$html2} and why not {$html3} |
| 225 | | BLOB; |
| 226 | | |
| 227 | | $images = get_content_images( $blob ); |
| 228 | | $this->assertEquals( $images, array( $html1, $html2, $html3 ) ); |
| 229 | | |
| 230 | | $images = get_content_images( $blob, false ); |
| 231 | | $this->assertEquals( $images, array( $src1, $src2, $src3 ) ); |
| 232 | | |
| 233 | | $images = get_content_images( $blob, true ); |
| 234 | | $this->assertEquals( $images, array( $html1, $html2, $html3 ) ); |
| 235 | | |
| 236 | | $images = get_content_images( $blob, false ); |
| 237 | | $this->assertEquals( $images, array( $src1, $src2, $src3 ) ); |
| 238 | | |
| 239 | | $images = get_content_images( $blob, true, 1 ); |
| 240 | | $this->assertEquals( $images, array( $html1 ) ); |
| 241 | | |
| 242 | | $images = get_content_images( $blob, false, 1 ); |
| 243 | | $this->assertEquals( $images, array( $src1 ) ); |
| 244 | | } |
| 245 | | |
| 246 | | /** |
| 247 | | * @ticket 22960 |
| 248 | | */ |
| 249 | | function test_content_image() { |
| 250 | | $blob =<<<BLOB |
| 251 | | This is a sentence that will all of a sudden contain {$this->img_html} |
| 252 | | BLOB; |
| 253 | | |
| 254 | | $image = get_content_image( $blob ); |
| 255 | | $this->assertEquals( $image, $this->img_html ); |
| 256 | | |
| 257 | | $image = get_content_image( $blob, false ); |
| 258 | | $this->assertEquals( $image, $this->img_url ); |
| 259 | | |
| 260 | | $linked_html = '<a href="http://woo.com">' . $this->img_html . '</a>'; |
| 261 | | $blob = "This is a sentence that will all of a sudden contain $linked_html"; |
| 262 | | $image = get_content_image( $blob ); |
| 263 | | $this->assertEquals( $image, $linked_html ); |
| 264 | | |
| 265 | | $captioned_html = '[caption width="300"]<a href="http://woo.com">' . $this->img_html . '</a> A Caption[/caption]'; |
| 266 | | $blob = "This is a sentence that will all of a sudden contain $captioned_html"; |
| 267 | | $result = '<div class="wp-caption alignnone" style="width: 310px"><a href="http://woo.com"><img src="http://example.org/wp-content/uploads/image.jpg"/></a><p class="wp-caption-text">A Caption</p></div>'; |
| 268 | | $image = get_content_image( $blob ); |
| 269 | | $this->assertEquals( $image, $result ); |
| 270 | | } |
| 271 | | |
| 272 | | /** |
| 273 | | * @ticket 22960 |
| 274 | | */ |
| 275 | | function test_content_galleries() { |
| 276 | | $ids1 = array(); |
| 277 | | $ids1_srcs = array(); |
| 278 | | foreach ( range( 1, 3 ) as $i ) { |
| 279 | | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| 280 | | 'post_mime_type' => 'image/jpeg', |
| 281 | | 'post_type' => 'attachment' |
| 282 | | ) ); |
| 283 | | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| 284 | | $ids1[] = $attachment_id; |
| 285 | | $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| 286 | | } |
| 287 | | |
| 288 | | $ids2 = array(); |
| 289 | | $ids2_srcs = array(); |
| 290 | | foreach ( range( 4, 6 ) as $i ) { |
| 291 | | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| 292 | | 'post_mime_type' => 'image/jpeg', |
| 293 | | 'post_type' => 'attachment' |
| 294 | | ) ); |
| 295 | | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| 296 | | $ids2[] = $attachment_id; |
| 297 | | $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| 298 | | } |
| 299 | | |
| 300 | | $ids1_joined = join( ',', $ids1 ); |
| 301 | | $ids2_joined = join( ',', $ids2 ); |
| 302 | | |
| 303 | | $blob =<<<BLOB |
| 304 | | [gallery ids="$ids1_joined"] |
| 305 | | |
| 306 | | [gallery ids="$ids2_joined"] |
| 307 | | BLOB; |
| 308 | | |
| 309 | | $post_id = $this->factory->post->create( array( 'post_content' => $blob ) ); |
| 310 | | $galleries = get_content_galleries( get_post_field( 'post_content', $post_id ), false ); |
| 311 | | $expected = array( |
| 312 | | array( 'ids' => $ids1_joined, 'src' => $ids1_srcs ), |
| 313 | | array( 'ids' => $ids2_joined, 'src' => $ids2_srcs ) |
| 314 | | ); |
| 315 | | $this->assertEquals( $galleries, $expected ); |
| 316 | | } |
| 317 | | |
| 318 | | /** |
| 319 | | * @ticket 22960 |
| 320 | | */ |
| 359 | | /** |
| 360 | | * @ticket 22960 |
| 361 | | */ |
| 362 | | function test_post_gallery_images() { |
| 363 | | $ids1 = array(); |
| 364 | | $ids1_srcs = array(); |
| 365 | | foreach ( range( 1, 3 ) as $i ) { |
| 366 | | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| 367 | | 'post_mime_type' => 'image/jpeg', |
| 368 | | 'post_type' => 'attachment' |
| 369 | | ) ); |
| 370 | | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| 371 | | $ids1[] = $attachment_id; |
| 372 | | $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| 373 | | } |
| 374 | | |
| 375 | | $ids2 = array(); |
| 376 | | $ids2_srcs = array(); |
| 377 | | foreach ( range( 4, 6 ) as $i ) { |
| 378 | | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| 379 | | 'post_mime_type' => 'image/jpeg', |
| 380 | | 'post_type' => 'attachment' |
| 381 | | ) ); |
| 382 | | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| 383 | | $ids2[] = $attachment_id; |
| 384 | | $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| 385 | | } |
| 386 | | |
| 387 | | $ids1_joined = join( ',', $ids1 ); |
| 388 | | $ids2_joined = join( ',', $ids2 ); |
| 389 | | |
| 390 | | $blob =<<<BLOB |
| 391 | | [gallery ids="$ids1_joined"] |
| 392 | | |
| 393 | | [gallery ids="$ids2_joined"] |
| 394 | | BLOB; |
| 395 | | $post_id = $this->factory->post->create( array( 'post_content' => $blob ) ); |
| 396 | | $srcs = get_post_gallery_images( $post_id ); |
| 397 | | $this->assertEquals( $srcs, $ids1_srcs ); |
| 398 | | } |
| 399 | | |
| 400 | | function test_get_embedded_media() { |
| 401 | | $obj =<<<OBJ |
| 402 | | <object src="this" data="that"> |
| 403 | | <param name="value"/> |
| 404 | | </object> |
| 405 | | OBJ; |
| 406 | | $embed =<<<EMBED |
| 407 | | <embed src="something.mp4"/> |
| 408 | | EMBED; |
| 409 | | $iframe =<<<IFRAME |
| 410 | | <iframe src="youtube.com" width="7000" /> |
| 411 | | IFRAME; |
| 412 | | $audio =<<<AUDIO |
| 413 | | <audio preload="none"> |
| 414 | | <source /> |
| 415 | | </audio> |
| 416 | | AUDIO; |
| 417 | | $video =<<<VIDEO |
| 418 | | <video preload="none"> |
| 419 | | <source /> |
| 420 | | </video> |
| 421 | | VIDEO; |
| 422 | | |
| 423 | | $content =<<<CONTENT |
| 424 | | This is a comment |
| 425 | | $obj |
| 426 | | |
| 427 | | This is a comment |
| 428 | | $embed |
| 429 | | |
| 430 | | This is a comment |
| 431 | | $iframe |
| 432 | | |
| 433 | | This is a comment |
| 434 | | $audio |
| 435 | | |
| 436 | | This is a comment |
| 437 | | $video |
| 438 | | |
| 439 | | This is a comment |
| 440 | | CONTENT; |
| 441 | | |
| 442 | | $audios = array_values( compact( 'audio', 'obj', 'embed', 'iframe' ) ); |
| 443 | | $videos = array_values( compact( 'video', 'obj', 'embed', 'iframe' ) ); |
| 444 | | |
| 445 | | $matches = get_embedded_media( 'audio', $content ); |
| 446 | | $this->assertEquals( $matches, $audios ); |
| 447 | | $matches = get_embedded_media( 'video', $content ); |
| 448 | | $this->assertEquals( $matches, $videos ); |
| 449 | | } |