Changeset 42343 for trunk/tests/phpunit/tests/media.php
- Timestamp:
- 11/30/2017 11:09:33 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/media.php (modified) (93 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/media.php
r41964 r42343 10 10 11 11 public static function wpSetUpBeforeClass( $factory ) { 12 self::$_sizes = wp_get_additional_image_sizes();12 self::$_sizes = wp_get_additional_image_sizes(); 13 13 $GLOBALS['_wp_additional_image_sizes'] = array(); 14 14 15 $filename = DIR_TESTDATA . '/images/test-image-large.png';15 $filename = DIR_TESTDATA . '/images/test-image-large.png'; 16 16 self::$large_id = $factory->attachment->create_upload_object( $filename ); 17 17 } … … 28 28 function setUp() { 29 29 parent::setUp(); 30 $this->caption = 'A simple caption.';30 $this->caption = 'A simple caption.'; 31 31 $this->alternate_caption = 'Alternate caption.'; 32 $this->html_content = <<<CAP32 $this->html_content = <<<CAP 33 33 A <strong class='classy'>bolded</strong> <em>caption</em> with a <a href="#">link</a>. 34 34 CAP; 35 $this->img_content = <<<CAP35 $this->img_content = <<<CAP 36 36 <img src="pic.jpg" id='anId' alt="pic"/> 37 37 CAP; 38 $this->img_name = 'image.jpg'; 39 $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name; 40 $this->img_html = '<img src="' . $this->img_url . '"/>'; 41 $this->img_meta = array( 'width' => 100, 'height' => 100, 'sizes' => '' ); 38 $this->img_name = 'image.jpg'; 39 $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name; 40 $this->img_html = '<img src="' . $this->img_url . '"/>'; 41 $this->img_meta = array( 42 'width' => 100, 43 'height' => 100, 44 'sizes' => '', 45 ); 42 46 } 43 47 … … 118 122 function test_img_caption_shortcode_with_old_format() { 119 123 $result = img_caption_shortcode( 120 array( 'width' => 20, 'caption' => $this->caption ) 124 array( 125 'width' => 20, 126 'caption' => $this->caption, 127 ) 121 128 ); 122 129 … … 126 133 127 134 if ( current_theme_supports( 'html5', 'caption' ) ) { 128 $this->assertEquals( 1, preg_match_all( "/max-width: 20/", $result, $_r ) );135 $this->assertEquals( 1, preg_match_all( '/max-width: 20/', $result, $_r ) ); 129 136 } else { 130 $this->assertEquals( 1, preg_match_all( "/max-width: 30/", $result, $_r ) );137 $this->assertEquals( 1, preg_match_all( '/max-width: 30/', $result, $_r ) ); 131 138 } 132 139 } … … 135 142 $result = img_caption_shortcode( 136 143 array( 137 'width' => 20,144 'width' => 20, 138 145 'caption' => $this->caption, 139 'id' => '"myId',140 'align' => '&myAlignment'146 'id' => '"myId', 147 'align' => '&myAlignment', 141 148 ) 142 149 ); … … 149 156 $result = img_caption_shortcode( 150 157 array( 151 'width' => 20,152 'class' => 'some-class another-class',158 'width' => 20, 159 'class' => 'some-class another-class', 153 160 'caption' => $this->caption, 154 161 ) … … 159 166 160 167 function test_new_img_caption_shortcode_with_html_caption() { 161 $result = img_caption_shortcode( 162 array( 'width' => 20, 'caption' => $this->html_content ) 168 $result = img_caption_shortcode( 169 array( 170 'width' => 20, 171 'caption' => $this->html_content, 172 ) 163 173 ); 164 174 $our_preg = preg_quote( $this->html_content ); … … 168 178 169 179 function test_new_img_caption_shortcode_new_format() { 170 $result = img_caption_shortcode(180 $result = img_caption_shortcode( 171 181 array( 'width' => 20 ), 172 182 $this->img_content . $this->html_content 173 183 ); 174 $img_preg = preg_quote( $this->img_content );184 $img_preg = preg_quote( $this->img_content ); 175 185 $content_preg = preg_quote( $this->html_content ); 176 186 … … 181 191 function test_new_img_caption_shortcode_new_format_and_linked_image() { 182 192 $linked_image = "<a href='#'>{$this->img_content}</a>"; 183 $result = img_caption_shortcode(193 $result = img_caption_shortcode( 184 194 array( 'width' => 20 ), 185 195 $linked_image . $this->html_content 186 196 ); 187 $img_preg = preg_quote( $linked_image );197 $img_preg = preg_quote( $linked_image ); 188 198 $content_preg = preg_quote( $this->html_content ); 189 199 … … 194 204 function test_new_img_caption_shortcode_new_format_and_linked_image_with_newline() { 195 205 $linked_image = "<a href='#'>{$this->img_content}</a>"; 196 $result = img_caption_shortcode(206 $result = img_caption_shortcode( 197 207 array( 'width' => 20 ), 198 208 $linked_image . "\n\n" . $this->html_content 199 209 ); 200 $img_preg = preg_quote( $linked_image );210 $img_preg = preg_quote( $linked_image ); 201 211 $content_preg = preg_quote( $this->html_content ); 202 212 … … 250 260 // Should embed 251 261 array( 252 'https://w.org',253 '[embed]' 262 'https://w.org', 263 '[embed]', 254 264 ), 255 265 array( 256 'test266 'test 257 267 https://w.org 258 268 test', 259 'test269 'test 260 270 [embed] 261 test' 271 test', 262 272 ), 263 273 array( 264 '<p class="test">https://w.org</p>',265 '<p class="test">[embed]</p>' 274 '<p class="test">https://w.org</p>', 275 '<p class="test">[embed]</p>', 266 276 ), 267 277 array( 268 '<p> https://w.org </p>',269 '<p> [embed] </p>' 278 '<p> https://w.org </p>', 279 '<p> [embed] </p>', 270 280 ), 271 281 array( 272 '<p>test282 '<p>test 273 283 https://w.org 274 284 test</p>', 275 '<p>test285 '<p>test 276 286 [embed] 277 test</p>' 287 test</p>', 278 288 ), 279 289 array( 280 '<p>https://w.org290 '<p>https://w.org 281 291 </p>', 282 '<p>[embed]283 </p>' 292 '<p>[embed] 293 </p>', 284 294 ), 285 295 286 296 // Should NOT embed 287 297 array( 288 'test https://w.org</p>' 298 'test https://w.org</p>', 289 299 ), 290 300 array( 291 '<span>https://w.org</a>' 301 '<span>https://w.org</a>', 292 302 ), 293 303 array( 294 '<pre>https://w.org295 </p>' 304 '<pre>https://w.org 305 </p>', 296 306 ), 297 307 array( 298 '<a href="https://w.org">299 https://w.org</a>' 308 '<a href="https://w.org"> 309 https://w.org</a>', 300 310 ), 301 311 ); … … 313 323 function test_wp_prepare_attachment_for_js() { 314 324 // Attachment without media 315 $id = wp_insert_attachment(array( 316 'post_status' => 'publish', 317 'post_title' => 'Prepare', 318 'post_content_filtered' => 'Prepare', 319 'post_type' => 'post' 320 )); 325 $id = wp_insert_attachment( 326 array( 327 'post_status' => 'publish', 328 'post_title' => 'Prepare', 329 'post_content_filtered' => 'Prepare', 330 'post_type' => 'post', 331 ) 332 ); 321 333 $post = get_post( $id ); 322 334 … … 333 345 // Fake a mime 334 346 $post->post_mime_type = 'image/jpeg'; 335 $prepped = wp_prepare_attachment_for_js( $post );347 $prepped = wp_prepare_attachment_for_js( $post ); 336 348 $this->assertEquals( 'image/jpeg', $prepped['mime'] ); 337 349 $this->assertEquals( 'image', $prepped['type'] ); … … 340 352 // Fake a mime without a slash. See #WP22532 341 353 $post->post_mime_type = 'image'; 342 $prepped = wp_prepare_attachment_for_js( $post );354 $prepped = wp_prepare_attachment_for_js( $post ); 343 355 $this->assertEquals( 'image', $prepped['mime'] ); 344 356 $this->assertEquals( 'image', $prepped['type'] ); … … 350 362 351 363 // Test that if author has HTML entities in display_name, they're decoded correctly. 352 $html_entity_author = self::factory()->user->create( array( 353 'display_name' => 'You & Me', 354 ) ); 355 $post->post_author = $html_entity_author; 356 $prepped = wp_prepare_attachment_for_js( $post ); 364 $html_entity_author = self::factory()->user->create( 365 array( 366 'display_name' => 'You & Me', 367 ) 368 ); 369 $post->post_author = $html_entity_author; 370 $prepped = wp_prepare_attachment_for_js( $post ); 357 371 $this->assertEquals( 'You & Me', $prepped['authorName'] ); 358 372 } … … 363 377 function test_wp_prepare_attachment_for_js_without_image_sizes() { 364 378 // Create the attachement post. 365 $id = wp_insert_attachment( array( 366 'post_title' => 'Attachment Title', 367 'post_type' => 'attachment', 368 'post_parent' => 0, 369 'post_mime_type' => 'image/jpeg', 370 'guid' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-image.jpg', 371 ) ); 379 $id = wp_insert_attachment( 380 array( 381 'post_title' => 'Attachment Title', 382 'post_type' => 'attachment', 383 'post_parent' => 0, 384 'post_mime_type' => 'image/jpeg', 385 'guid' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-image.jpg', 386 ) 387 ); 372 388 373 389 // Add attachment metadata without sizes. 374 wp_update_attachment_metadata( $id, array( 375 'width' => 50, 376 'height' => 50, 377 'file' => 'test-image.jpg', 378 ) ); 390 wp_update_attachment_metadata( 391 $id, array( 392 'width' => 50, 393 'height' => 50, 394 'file' => 'test-image.jpg', 395 ) 396 ); 379 397 380 398 $prepped = wp_prepare_attachment_for_js( get_post( $id ) ); … … 426 444 */ 427 445 function test_get_attached_images() { 428 $post_id = self::factory()->post->create(); 429 $attachment_id = self::factory()->attachment->create_object( $this->img_name, $post_id, array( 430 'post_mime_type' => 'image/jpeg', 431 'post_type' => 'attachment' 432 ) ); 446 $post_id = self::factory()->post->create(); 447 $attachment_id = self::factory()->attachment->create_object( 448 $this->img_name, $post_id, array( 449 'post_mime_type' => 'image/jpeg', 450 'post_type' => 'attachment', 451 ) 452 ); 433 453 434 454 $images = get_attached_media( 'image', $post_id ); … … 440 460 */ 441 461 function test_post_galleries_images() { 442 $ids1 = array();462 $ids1 = array(); 443 463 $ids1_srcs = array(); 444 464 foreach ( range( 1, 3 ) as $i ) { 445 $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", 0, array( 446 'post_mime_type' => 'image/jpeg', 447 'post_type' => 'attachment' 448 ) ); 449 $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta ); 465 $attachment_id = self::factory()->attachment->create_object( 466 "image$i.jpg", 0, array( 467 'post_mime_type' => 'image/jpeg', 468 'post_type' => 'attachment', 469 ) 470 ); 471 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); 450 472 wp_update_attachment_metadata( $attachment_id, $metadata ); 451 $ids1[] = $attachment_id;473 $ids1[] = $attachment_id; 452 474 $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; 453 475 } 454 476 455 $ids2 = array();477 $ids2 = array(); 456 478 $ids2_srcs = array(); 457 479 foreach ( range( 4, 6 ) as $i ) { 458 $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", 0, array( 459 'post_mime_type' => 'image/jpeg', 460 'post_type' => 'attachment' 461 ) ); 462 $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta ); 480 $attachment_id = self::factory()->attachment->create_object( 481 "image$i.jpg", 0, array( 482 'post_mime_type' => 'image/jpeg', 483 'post_type' => 'attachment', 484 ) 485 ); 486 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); 463 487 wp_update_attachment_metadata( $attachment_id, $metadata ); 464 $ids2[] = $attachment_id;488 $ids2[] = $attachment_id; 465 489 $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; 466 490 } … … 469 493 $ids2_joined = join( ',', $ids2 ); 470 494 471 $blob =<<<BLOB495 $blob = <<<BLOB 472 496 [gallery ids="$ids1_joined"] 473 497 … … 475 499 BLOB; 476 500 $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); 477 $srcs = get_post_galleries_images( $post_id );501 $srcs = get_post_galleries_images( $post_id ); 478 502 $this->assertEquals( $srcs, array( $ids1_srcs, $ids2_srcs ) ); 479 503 } … … 484 508 function test_post_galleries_images_without_global_post() { 485 509 // Set up an unattached image. 486 $this->factory->attachment->create_object( array( 487 'file' => 'test.jpg', 488 'post_parent' => 0, 489 'post_mime_type' => 'image/jpeg', 490 'post_type' => 'attachment' 491 ) ); 492 493 $post_id = $this->factory->post->create( array( 494 'post_content' => '[gallery]', 495 ) ); 510 $this->factory->attachment->create_object( 511 array( 512 'file' => 'test.jpg', 513 'post_parent' => 0, 514 'post_mime_type' => 'image/jpeg', 515 'post_type' => 'attachment', 516 ) 517 ); 518 519 $post_id = $this->factory->post->create( 520 array( 521 'post_content' => '[gallery]', 522 ) 523 ); 496 524 497 525 $galleries = get_post_galleries( $post_id, false ); … … 504 532 */ 505 533 function test_post_galleries_ignores_global_post() { 506 $global_post_id = $this->factory->post->create( array( 507 'post_content' => 'Global Post', 508 ) ); 509 $post_id = $this->factory->post->create( array( 510 'post_content' => '[gallery]', 511 ) ); 512 $this->factory->attachment->create_object( array( 513 'file' => 'test.jpg', 514 'post_parent' => $post_id, 515 'post_mime_type' => 'image/jpeg', 516 'post_type' => 'attachment' 517 ) ); 534 $global_post_id = $this->factory->post->create( 535 array( 536 'post_content' => 'Global Post', 537 ) 538 ); 539 $post_id = $this->factory->post->create( 540 array( 541 'post_content' => '[gallery]', 542 ) 543 ); 544 $this->factory->attachment->create_object( 545 array( 546 'file' => 'test.jpg', 547 'post_parent' => $post_id, 548 'post_mime_type' => 'image/jpeg', 549 'post_type' => 'attachment', 550 ) 551 ); 518 552 $expected_srcs = array( 519 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg' 553 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg', 520 554 ); 521 555 … … 533 567 */ 534 568 function test_post_galleries_respects_id_attrs() { 535 $post_id = $this->factory->post->create( array( 536 'post_content' => 'No gallery defined', 537 ) ); 538 $post_id_two = $this->factory->post->create( array( 539 'post_content' => "[gallery id='$post_id']", 540 ) ); 541 $this->factory->attachment->create_object( array( 542 'file' => 'test.jpg', 543 'post_parent' => $post_id, 544 'post_mime_type' => 'image/jpeg', 545 'post_type' => 'attachment' 546 ) ); 569 $post_id = $this->factory->post->create( 570 array( 571 'post_content' => 'No gallery defined', 572 ) 573 ); 574 $post_id_two = $this->factory->post->create( 575 array( 576 'post_content' => "[gallery id='$post_id']", 577 ) 578 ); 579 $this->factory->attachment->create_object( 580 array( 581 'file' => 'test.jpg', 582 'post_parent' => $post_id, 583 'post_mime_type' => 'image/jpeg', 584 'post_type' => 'attachment', 585 ) 586 ); 547 587 $expected_srcs = array( 548 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg' 588 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg', 549 589 ); 550 590 … … 552 592 553 593 // Set the global $post context 554 $GLOBALS['post'] = get_post( $post_id_two );594 $GLOBALS['post'] = get_post( $post_id_two ); 555 595 $galleries_with_global_context = get_post_galleries( $post_id_two, false ); 556 596 … … 566 606 */ 567 607 function test_post_gallery_images() { 568 $ids1 = array();608 $ids1 = array(); 569 609 $ids1_srcs = array(); 570 610 foreach ( range( 1, 3 ) as $i ) { 571 $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", 0, array( 572 'post_mime_type' => 'image/jpeg', 573 'post_type' => 'attachment' 574 ) ); 575 $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta ); 611 $attachment_id = self::factory()->attachment->create_object( 612 "image$i.jpg", 0, array( 613 'post_mime_type' => 'image/jpeg', 614 'post_type' => 'attachment', 615 ) 616 ); 617 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); 576 618 wp_update_attachment_metadata( $attachment_id, $metadata ); 577 $ids1[] = $attachment_id;619 $ids1[] = $attachment_id; 578 620 $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; 579 621 } 580 622 581 $ids2 = array();623 $ids2 = array(); 582 624 $ids2_srcs = array(); 583 625 foreach ( range( 4, 6 ) as $i ) { 584 $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", 0, array( 585 'post_mime_type' => 'image/jpeg', 586 'post_type' => 'attachment' 587 ) ); 588 $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta ); 626 $attachment_id = self::factory()->attachment->create_object( 627 "image$i.jpg", 0, array( 628 'post_mime_type' => 'image/jpeg', 629 'post_type' => 'attachment', 630 ) 631 ); 632 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); 589 633 wp_update_attachment_metadata( $attachment_id, $metadata ); 590 $ids2[] = $attachment_id;634 $ids2[] = $attachment_id; 591 635 $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; 592 636 } … … 595 639 $ids2_joined = join( ',', $ids2 ); 596 640 597 $blob =<<<BLOB641 $blob = <<<BLOB 598 642 [gallery ids="$ids1_joined"] 599 643 … … 601 645 BLOB; 602 646 $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); 603 $srcs = get_post_gallery_images( $post_id );647 $srcs = get_post_gallery_images( $post_id ); 604 648 $this->assertEquals( $srcs, $ids1_srcs ); 605 649 } 606 650 607 651 function test_get_media_embedded_in_content() { 608 $object = <<<OBJ652 $object = <<<OBJ 609 653 <object src="this" data="that"> 610 654 <param name="value"/> 611 655 </object> 612 656 OBJ; 613 $embed =<<<EMBED657 $embed = <<<EMBED 614 658 <embed src="something.mp4"/> 615 659 EMBED; 616 $iframe = <<<IFRAME660 $iframe = <<<IFRAME 617 661 <iframe src="youtube.com" width="7000" /> 618 662 IFRAME; 619 $audio =<<<AUDIO663 $audio = <<<AUDIO 620 664 <audio preload="none"> 621 665 <source /> 622 666 </audio> 623 667 AUDIO; 624 $video =<<<VIDEO668 $video = <<<VIDEO 625 669 <video preload="none"> 626 670 <source /> … … 628 672 VIDEO; 629 673 630 $content = <<<CONTENT674 $content = <<<CONTENT 631 675 This is a comment 632 676 $object … … 647 691 CONTENT; 648 692 649 $types = array( 'object', 'embed', 'iframe', 'audio', 'video' );693 $types = array( 'object', 'embed', 'iframe', 'audio', 'video' ); 650 694 $contents = array_values( compact( $types ) ); 651 695 … … 670 714 671 715 function test_get_media_embedded_in_content_order() { 672 $audio =<<<AUDIO716 $audio = <<<AUDIO 673 717 <audio preload="none"> 674 718 <source /> 675 719 </audio> 676 720 AUDIO; 677 $video =<<<VIDEO721 $video = <<<VIDEO 678 722 <video preload="none"> 679 723 <source /> … … 703 747 $this->assertSame( 704 748 '<a class="wp-embedded-audio" href="https://example.com/foo.php">https://example.com/foo.php</a>', 705 wp_audio_shortcode( array( 706 'src' => 'https://example.com/foo.php', 707 ) ) 749 wp_audio_shortcode( 750 array( 751 'src' => 'https://example.com/foo.php', 752 ) 753 ) 708 754 ); 709 755 } … … 713 759 */ 714 760 function test_wp_audio_shortcode_attributes() { 715 $actual = wp_audio_shortcode( array( 716 'src' => 'https://example.com/foo.mp3', 717 ) ); 761 $actual = wp_audio_shortcode( 762 array( 763 'src' => 'https://example.com/foo.mp3', 764 ) 765 ); 718 766 719 767 $this->assertContains( 'src="https://example.com/foo.mp3', $actual ); … … 724 772 $this->assertContains( 'style="width: 100%;"', $actual ); 725 773 726 $actual = wp_audio_shortcode( array( 727 'src' => 'https://example.com/foo.mp3', 728 'loop' => true, 729 'autoplay' => true, 730 'preload' => true, 731 'class' => 'foobar', 732 'style' => 'padding:0;', 733 ) ); 774 $actual = wp_audio_shortcode( 775 array( 776 'src' => 'https://example.com/foo.mp3', 777 'loop' => true, 778 'autoplay' => true, 779 'preload' => true, 780 'class' => 'foobar', 781 'style' => 'padding:0;', 782 ) 783 ); 734 784 735 785 $this->assertContains( 'src="https://example.com/foo.mp3', $actual ); … … 743 793 /** 744 794 * Test [video] shortcode processing 745 *746 795 */ 747 796 function test_video_shortcode_body() { 748 $width = 720;797 $width = 720; 749 798 $height = 480; 750 799 … … 756 805 $post_id = get_post() ? get_the_ID() : 0; 757 806 758 $video = <<<VIDEO807 $video = <<<VIDEO 759 808 [video width="$width" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"] 760 809 <!-- WebM/VP8 for Firefox4, Opera, and Chrome --> … … 769 818 VIDEO; 770 819 771 772 820 $h = ceil( ( $height * $width ) / $width ); 773 821 … … 803 851 $this->assertSame( 804 852 '<a class="wp-embedded-video" href="https://example.com/foo.php">https://example.com/foo.php</a>', 805 wp_video_shortcode( array( 806 'src' => 'https://example.com/foo.php', 807 ) ) 853 wp_video_shortcode( 854 array( 855 'src' => 'https://example.com/foo.php', 856 ) 857 ) 808 858 ); 809 859 } … … 814 864 */ 815 865 function test_wp_video_shortcode_attributes() { 816 $actual = wp_video_shortcode( array( 817 'src' => 'https://example.com/foo.mp4', 818 ) ); 866 $actual = wp_video_shortcode( 867 array( 868 'src' => 'https://example.com/foo.mp4', 869 ) 870 ); 819 871 820 872 $this->assertContains( 'src="https://example.com/foo.mp4', $actual ); … … 826 878 $this->assertContains( 'class="wp-video-shortcode"', $actual ); 827 879 828 $actual = wp_video_shortcode( array( 829 'src' => 'https://example.com/foo.mp4', 830 'poster' => 'https://example.com/foo.png', 831 'loop' => true, 832 'autoplay' => true, 833 'preload' => true, 834 'width' => 123, 835 'height' => 456, 836 'class' => 'foobar', 837 ) ); 880 $actual = wp_video_shortcode( 881 array( 882 'src' => 'https://example.com/foo.mp4', 883 'poster' => 'https://example.com/foo.png', 884 'loop' => true, 885 'autoplay' => true, 886 'preload' => true, 887 'width' => 123, 888 'height' => 456, 889 'class' => 'foobar', 890 ) 891 ); 838 892 839 893 $this->assertContains( 'src="https://example.com/foo.mp4', $actual ); … … 852 906 */ 853 907 function test_wp_video_shortcode_youtube_remove_feature() { 854 $actual = wp_video_shortcode( array( 855 'src' => 'https://www.youtube.com/watch?v=i_cVJgIz_Cs&feature=youtu.be', 856 ) ); 908 $actual = wp_video_shortcode( 909 array( 910 'src' => 'https://www.youtube.com/watch?v=i_cVJgIz_Cs&feature=youtu.be', 911 ) 912 ); 857 913 858 914 $this->assertNotContains( 'feature=youtu.be', $actual ); … … 864 920 */ 865 921 function test_wp_video_shortcode_youtube_force_ssl() { 866 $actual = wp_video_shortcode( array( 867 'src' => 'http://www.youtube.com/watch?v=i_cVJgIz_Cs', 868 ) ); 922 $actual = wp_video_shortcode( 923 array( 924 'src' => 'http://www.youtube.com/watch?v=i_cVJgIz_Cs', 925 ) 926 ); 869 927 870 928 $this->assertContains( 'src="https://www.youtube.com/watch?v=i_cVJgIz_Cs', $actual ); … … 876 934 */ 877 935 function test_wp_video_shortcode_vimeo_force_ssl_remove_query_args() { 878 $actual = wp_video_shortcode( array( 879 'src' => 'http://vimeo.com/190372437?blah=meh', 880 ) ); 936 $actual = wp_video_shortcode( 937 array( 938 'src' => 'http://vimeo.com/190372437?blah=meh', 939 ) 940 ); 881 941 882 942 $this->assertContains( 'src="https://vimeo.com/190372437', $actual ); … … 889 949 */ 890 950 function test_wp_video_shortcode_vimeo_adds_loop() { 891 $actual = wp_video_shortcode( array( 892 'src' => 'http://vimeo.com/190372437', 893 ) ); 951 $actual = wp_video_shortcode( 952 array( 953 'src' => 'http://vimeo.com/190372437', 954 ) 955 ); 894 956 895 957 $this->assertContains( 'src="https://vimeo.com/190372437?loop=0', $actual ); … … 901 963 */ 902 964 function test_wp_video_shortcode_vimeo_force_adds_loop_true() { 903 $actual = wp_video_shortcode( array( 904 'src' => 'http://vimeo.com/190372437', 905 'loop' => true, 906 ) ); 965 $actual = wp_video_shortcode( 966 array( 967 'src' => 'http://vimeo.com/190372437', 968 'loop' => true, 969 ) 970 ); 907 971 908 972 $this->assertContains( 'src="https://vimeo.com/190372437?loop=1', $actual ); … … 955 1019 */ 956 1020 function test_attachment_url_to_postid() { 957 $image_path = '2014/11/' . $this->img_name; 958 $attachment_id = self::factory()->attachment->create_object( $image_path, 0, array( 959 'post_mime_type' => 'image/jpeg', 960 'post_type' => 'attachment', 961 ) ); 962 963 $image_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path; 1021 $image_path = '2014/11/' . $this->img_name; 1022 $attachment_id = self::factory()->attachment->create_object( 1023 $image_path, 0, array( 1024 'post_mime_type' => 'image/jpeg', 1025 'post_type' => 'attachment', 1026 ) 1027 ); 1028 1029 $image_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path; 964 1030 $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) ); 965 1031 } 966 1032 967 1033 function test_attachment_url_to_postid_schemes() { 968 $image_path = '2014/11/' . $this->img_name; 969 $attachment_id = self::factory()->attachment->create_object( $image_path, 0, array( 970 'post_mime_type' => 'image/jpeg', 971 'post_type' => 'attachment', 972 ) ); 1034 $image_path = '2014/11/' . $this->img_name; 1035 $attachment_id = self::factory()->attachment->create_object( 1036 $image_path, 0, array( 1037 'post_mime_type' => 'image/jpeg', 1038 'post_type' => 'attachment', 1039 ) 1040 ); 973 1041 974 1042 /** 975 1043 * @ticket 33109 Testing protocols not matching 976 1044 */ 977 $image_url = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path;1045 $image_url = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path; 978 1046 $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) ); 979 1047 } 980 1048 981 1049 function test_attachment_url_to_postid_filtered() { 982 $image_path = '2014/11/' . $this->img_name; 983 $attachment_id = self::factory()->attachment->create_object( $image_path, 0, array( 984 'post_mime_type' => 'image/jpeg', 985 'post_type' => 'attachment', 986 ) ); 1050 $image_path = '2014/11/' . $this->img_name; 1051 $attachment_id = self::factory()->attachment->create_object( 1052 $image_path, 0, array( 1053 'post_mime_type' => 'image/jpeg', 1054 'post_type' => 'attachment', 1055 ) 1056 ); 987 1057 988 1058 add_filter( 'upload_dir', array( $this, '_upload_dir' ) ); … … 1022 1092 'type' => 'image/jpeg', 1023 1093 'error' => 0, 1024 'size' => filesize( $iptc_file ) 1025 ); 1026 1027 $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_iptc_upload', 'test_form' => false ) ); 1094 'size' => filesize( $iptc_file ), 1095 ); 1096 1097 $post_id = media_handle_upload( 1098 'upload', 0, array(), array( 1099 'action' => 'test_iptc_upload', 1100 'test_form' => false, 1101 ) 1102 ); 1028 1103 1029 1104 unset( $_FILES['upload'] ); … … 1056 1131 ); 1057 1132 1058 $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) ); 1133 $post_id = media_handle_upload( 1134 'upload', 0, array(), array( 1135 'action' => 'test_upload_titles', 1136 'test_form' => false, 1137 ) 1138 ); 1059 1139 1060 1140 unset( $_FILES['upload'] ); … … 1182 1262 /** 1183 1263 * Tests the default output of `wp_get_attachment_image()`. 1264 * 1184 1265 * @ticket 34635 1185 1266 */ 1186 1267 function test_wp_get_attachment_image_defaults() { 1187 $image = image_downsize( self::$large_id, 'thumbnail' );1268 $image = image_downsize( self::$large_id, 'thumbnail' ); 1188 1269 $expected = sprintf( '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="" />', $image[1], $image[2], $image[0] ); 1189 1270 … … 1193 1274 /** 1194 1275 * Test that `wp_get_attachment_image()` returns a proper alt value. 1276 * 1195 1277 * @ticket 34635 1196 1278 */ … … 1199 1281 update_post_meta( self::$large_id, '_wp_attachment_image_alt', 'Some very clever alt text', true ); 1200 1282 1201 $image = image_downsize( self::$large_id, 'thumbnail' );1283 $image = image_downsize( self::$large_id, 'thumbnail' ); 1202 1284 $expected = sprintf( '<img width="%1$d" height="%2$d" src="%3$s" class="attachment-thumbnail size-thumbnail" alt="Some very clever alt text" />', $image[1], $image[2], $image[0] ); 1203 1285 … … 1214 1296 $this->assertFalse( wp_get_attachment_image_url( 0 ) ); 1215 1297 1216 $post_id = self::factory()->post->create(); 1217 $attachment_id = self::factory()->attachment->create_object( $this->img_name, $post_id, array( 1218 'post_mime_type' => 'image/jpeg', 1219 'post_type' => 'attachment', 1220 ) ); 1298 $post_id = self::factory()->post->create(); 1299 $attachment_id = self::factory()->attachment->create_object( 1300 $this->img_name, $post_id, array( 1301 'post_mime_type' => 'image/jpeg', 1302 'post_type' => 'attachment', 1303 ) 1304 ); 1221 1305 1222 1306 $image = wp_get_attachment_image_src( $attachment_id, 'thumbnail', false ); … … 1233 1317 $caption = 'This is a caption.'; 1234 1318 1235 $post_id = self::factory()->post->create(); 1236 $attachment_id = self::factory()->attachment->create_object( $this->img_name, $post_id, array( 1237 'post_mime_type' => 'image/jpeg', 1238 'post_type' => 'attachment', 1239 'post_excerpt' => $caption, 1240 ) ); 1319 $post_id = self::factory()->post->create(); 1320 $attachment_id = self::factory()->attachment->create_object( 1321 $this->img_name, $post_id, array( 1322 'post_mime_type' => 'image/jpeg', 1323 'post_type' => 'attachment', 1324 'post_excerpt' => $caption, 1325 ) 1326 ); 1241 1327 1242 1328 $this->assertFalse( wp_get_attachment_caption( $post_id ) ); … … 1249 1335 */ 1250 1336 function test_wp_get_attachment_caption_empty() { 1251 $post_id = self::factory()->post->create(); 1252 $attachment_id = self::factory()->attachment->create_object( $this->img_name, $post_id, array( 1253 'post_mime_type' => 'image/jpeg', 1254 'post_type' => 'attachment', 1255 'post_excerpt' => '', 1256 ) ); 1337 $post_id = self::factory()->post->create(); 1338 $attachment_id = self::factory()->attachment->create_object( 1339 $this->img_name, $post_id, array( 1340 'post_mime_type' => 'image/jpeg', 1341 'post_type' => 'attachment', 1342 'post_excerpt' => '', 1343 ) 1344 ); 1257 1345 1258 1346 $this->assertEquals( '', wp_get_attachment_caption( $attachment_id ) ); … … 1280 1368 */ 1281 1369 function _src_first( $srcset, $src_url, $src_width ) { 1282 $src_string = $src_url . ' ' . $src_width . 'w';1370 $src_string = $src_url . ' ' . $src_width . 'w'; 1283 1371 $src_not_first = ', ' . $src_string; 1284 1372 … … 1297 1385 $_wp_additional_image_sizes = wp_get_additional_image_sizes(); 1298 1386 1299 $year_month = date('Y/m');1300 $image_meta = wp_get_attachment_metadata( self::$large_id );1387 $year_month = date( 'Y/m' ); 1388 $image_meta = wp_get_attachment_metadata( self::$large_id ); 1301 1389 $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; 1302 1390 … … 1306 1394 // Add any soft crop intermediate sizes. 1307 1395 foreach ( $_wp_additional_image_sizes as $name => $additional_size ) { 1308 if ( ! $_wp_additional_image_sizes[ $name]['crop'] || 0 === $_wp_additional_image_sizes[$name]['height'] ) {1396 if ( ! $_wp_additional_image_sizes[ $name ]['crop'] || 0 === $_wp_additional_image_sizes[ $name ]['height'] ) { 1309 1397 $intermediates[] = $name; 1310 1398 } … … 1321 1409 1322 1410 // Add the full size width at the end. 1323 $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';1411 $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; 1324 1412 1325 1413 foreach ( $intermediates as $int ) { 1326 $image_url = wp_get_attachment_image_url( self::$large_id, $int );1327 $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int );1414 $image_url = wp_get_attachment_image_url( self::$large_id, $int ); 1415 $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int ); 1328 1416 $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] ); 1329 1417 $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) ); … … 1342 1430 // Make an image. 1343 1431 $filename = DIR_TESTDATA . '/images/test-image-large.png'; 1344 $id = self::factory()->attachment->create_upload_object( $filename );1345 1346 $image_meta = wp_get_attachment_metadata( $id );1432 $id = self::factory()->attachment->create_upload_object( $filename ); 1433 1434 $image_meta = wp_get_attachment_metadata( $id ); 1347 1435 $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; 1348 1436 … … 1351 1439 1352 1440 foreach ( $_wp_additional_image_sizes as $name => $additional_size ) { 1353 if ( ! $_wp_additional_image_sizes[ $name]['crop'] || 0 === $_wp_additional_image_sizes[$name]['height'] ) {1441 if ( ! $_wp_additional_image_sizes[ $name ]['crop'] || 0 === $_wp_additional_image_sizes[ $name ]['height'] ) { 1354 1442 $intermediates[] = $name; 1355 1443 } … … 1366 1454 1367 1455 // Add the full size width at the end. 1368 $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';1456 $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; 1369 1457 1370 1458 foreach ( $intermediates as $int ) { 1371 $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int );1372 $image_url = wp_get_attachment_image_url( $id, $int );1459 $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int ); 1460 $image_url = wp_get_attachment_image_url( $id, $int ); 1373 1461 $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] ); 1374 1462 $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) ); … … 1387 1475 // Start by getting the attachment metadata. 1388 1476 $image_meta = wp_get_attachment_metadata( self::$large_id ); 1389 $image_url = wp_get_attachment_image_url( self::$large_id, 'medium' );1477 $image_url = wp_get_attachment_image_url( self::$large_id, 'medium' ); 1390 1478 $size_array = $this->_get_image_size_array_from_meta( $image_meta, 'medium' ); 1391 1479 1392 1480 // Copy hash generation method used in wp_save_image(). 1393 $hash = 'e' . time() . rand( 100, 999);1481 $hash = 'e' . time() . rand( 100, 999 ); 1394 1482 1395 1483 $filename_base = basename( $image_meta['file'], '.png' ); … … 1399 1487 1400 1488 // Replace file paths for full and medium sizes with hashed versions. 1401 $image_meta['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['file'] );1402 $image_meta['sizes']['medium']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium']['file'] );1489 $image_meta['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['file'] ); 1490 $image_meta['sizes']['medium']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium']['file'] ); 1403 1491 $image_meta['sizes']['medium_large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium_large']['file'] ); 1404 $image_meta['sizes']['large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['large']['file'] );1492 $image_meta['sizes']['large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['large']['file'] ); 1405 1493 1406 1494 // Calculate a srcset array. … … 1419 1507 $_wp_additional_image_sizes = wp_get_additional_image_sizes(); 1420 1508 1421 $year_month = date('Y/m');1422 $image_meta = wp_get_attachment_metadata( self::$large_id );1509 $year_month = date( 'Y/m' ); 1510 $image_meta = wp_get_attachment_metadata( self::$large_id ); 1423 1511 $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; 1424 1512 … … 1428 1516 // Add any soft crop intermediate sizes. 1429 1517 foreach ( $_wp_additional_image_sizes as $name => $additional_size ) { 1430 if ( ! $_wp_additional_image_sizes[ $name]['crop'] || 0 === $_wp_additional_image_sizes[$name]['height'] ) {1518 if ( ! $_wp_additional_image_sizes[ $name ]['crop'] || 0 === $_wp_additional_image_sizes[ $name ]['height'] ) { 1431 1519 $intermediates[] = $name; 1432 1520 } … … 1435 1523 $expected = ''; 1436 1524 1437 foreach ( $image_meta['sizes'] as $name => $size ) {1525 foreach ( $image_meta['sizes'] as $name => $size ) { 1438 1526 // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4. 1439 1527 if ( in_array( $name, $intermediates ) ) { … … 1443 1531 1444 1532 // Add the full size width at the end. 1445 $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';1533 $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; 1446 1534 1447 1535 // Prepend an absolute path to simulate a pre-2.7 upload … … 1449 1537 1450 1538 foreach ( $intermediates as $int ) { 1451 $image_url = wp_get_attachment_image_url( self::$large_id, $int );1452 $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int );1539 $image_url = wp_get_attachment_image_url( self::$large_id, $int ); 1540 $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int ); 1453 1541 $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] ); 1454 1542 $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) ); … … 1470 1558 */ 1471 1559 function test_wp_calculate_image_srcset_no_width() { 1472 $file = get_attached_file( self::$large_id );1473 $image_url = wp_get_attachment_image_url( self::$large_id, 'medium' );1560 $file = get_attached_file( self::$large_id ); 1561 $image_url = wp_get_attachment_image_url( self::$large_id, 'medium' ); 1474 1562 $image_meta = wp_generate_attachment_metadata( self::$large_id, $file ); 1475 1563 1476 $size_array = array( 0, 0);1564 $size_array = array( 0, 0 ); 1477 1565 1478 1566 $srcset = wp_calculate_image_srcset( $size_array, $image_url, $image_meta ); … … 1489 1577 // Mock data for this test. 1490 1578 $size_array = array( 218, 300 ); 1491 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x1055-218x300.png';1579 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x1055-218x300.png'; 1492 1580 $image_meta = array( 1493 'width' => 768,1581 'width' => 768, 1494 1582 'height' => 1055, 1495 'file' => '2015/12/test-768x1055.png',1496 'sizes' => array(1497 'thumbnail' => array(1498 'file' => 'test-768x1055-150x150.png',1499 'width' => 150,1500 'height' => 150,1583 'file' => '2015/12/test-768x1055.png', 1584 'sizes' => array( 1585 'thumbnail' => array( 1586 'file' => 'test-768x1055-150x150.png', 1587 'width' => 150, 1588 'height' => 150, 1501 1589 'mime-type' => 'image/png', 1502 1590 ), 1503 'medium' => array(1504 'file' => 'test-768x1055-218x300.png',1505 'width' => 218,1506 'height' => 300,1591 'medium' => array( 1592 'file' => 'test-768x1055-218x300.png', 1593 'width' => 218, 1594 'height' => 300, 1507 1595 'mime-type' => 'image/png', 1508 1596 ), 1509 'custom-600' => array(1510 'file' => 'test-768x1055-600x824.png',1511 'width' => 600,1512 'height' => 824,1597 'custom-600' => array( 1598 'file' => 'test-768x1055-600x824.png', 1599 'width' => 600, 1600 'height' => 824, 1513 1601 'mime-type' => 'image/png', 1514 1602 ), 1515 1603 'post-thumbnail' => array( 1516 'file' => 'test-768x1055-768x510.png',1517 'width' => 768,1518 'height' => 510,1604 'file' => 'test-768x1055-768x510.png', 1605 'width' => 768, 1606 'height' => 510, 1519 1607 'mime-type' => 'image/png', 1520 1608 ), … … 1534 1622 // Mock data for this test. 1535 1623 $size_array = array( 2000, 1000 ); 1536 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png';1624 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png'; 1537 1625 $image_meta = array( 1538 'width' => 2000,1626 'width' => 2000, 1539 1627 'height' => 1000, 1540 'file' => '2015/12/test.png',1541 'sizes' => array(1542 'thumbnail' => array(1543 'file' => 'test-150x150.png',1544 'width' => 150,1545 'height' => 150,1628 'file' => '2015/12/test.png', 1629 'sizes' => array( 1630 'thumbnail' => array( 1631 'file' => 'test-150x150.png', 1632 'width' => 150, 1633 'height' => 150, 1546 1634 'mime-type' => 'image/png', 1547 1635 ), 1548 'medium' => array(1549 'file' => 'test-300x150.png',1550 'width' => 300,1551 'height' => 150,1636 'medium' => array( 1637 'file' => 'test-300x150.png', 1638 'width' => 300, 1639 'height' => 150, 1552 1640 'mime-type' => 'image/png', 1553 1641 ), 1554 1642 'medium_large' => array( 1555 'file' => 'test-768x384.png',1556 'width' => 768,1557 'height' => 384,1643 'file' => 'test-768x384.png', 1644 'width' => 768, 1645 'height' => 384, 1558 1646 'mime-type' => 'image/png', 1559 1647 ), 1560 'large' => array(1561 'file' => 'test-1024x512.png',1562 'width' => 1024,1563 'height' => 512,1648 'large' => array( 1649 'file' => 'test-1024x512.png', 1650 'width' => 1024, 1651 'height' => 512, 1564 1652 'mime-type' => 'image/png', 1565 1653 ), … … 1577 1665 function test_wp_calculate_image_srcset_corrupted_image_meta() { 1578 1666 $size_array = array( 300, 150 ); 1579 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png';1667 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png'; 1580 1668 $image_meta = array( 1581 'width' => 1600,1669 'width' => 1600, 1582 1670 'height' => 800, 1583 'file' => '2015/12/test.png',1584 'sizes' => array(1585 'thumbnail' => array(1586 'file' => 'test-150x150.png',1587 'width' => 150,1588 'height' => 150,1671 'file' => '2015/12/test.png', 1672 'sizes' => array( 1673 'thumbnail' => array( 1674 'file' => 'test-150x150.png', 1675 'width' => 150, 1676 'height' => 150, 1589 1677 'mime-type' => 'image/png', 1590 1678 ), 1591 'medium' => array(1592 'file' => 'test-300x150.png',1593 'width' => 300,1594 'height' => 150,1679 'medium' => array( 1680 'file' => 'test-300x150.png', 1681 'width' => 300, 1682 'height' => 150, 1595 1683 'mime-type' => 'image/png', 1596 1684 ), 1597 1685 'medium_large' => array( 1598 'file' => 'test-768x384.png',1599 'width' => 768,1600 'height' => 384,1686 'file' => 'test-768x384.png', 1687 'width' => 768, 1688 'height' => 384, 1601 1689 'mime-type' => 'image/png', 1602 1690 ), 1603 'large' => array(1604 'file' => 'test-1024x512.png',1605 'width' => 1024,1606 'height' => 512,1691 'large' => array( 1692 'file' => 'test-1024x512.png', 1693 'width' => 1024, 1694 'height' => 512, 1607 1695 'mime-type' => 'image/png', 1608 1696 ), … … 1623 1711 1624 1712 // Sizes is string instead of array; only full size available means no srcset. 1625 $image_meta2 = $image_meta;1713 $image_meta2 = $image_meta; 1626 1714 $image_meta2['sizes'] = ''; 1627 1715 $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta2 ) ); 1628 1716 1629 1717 // File name is incorrect 1630 $image_meta3 = $image_meta;1718 $image_meta3 = $image_meta; 1631 1719 $image_meta3['file'] = '/'; 1632 1720 $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) ); … … 1638 1726 1639 1727 // Intermediate size is string instead of array. 1640 $image_meta5 = $image_meta;1728 $image_meta5 = $image_meta; 1641 1729 $image_meta5['sizes']['medium_large'] = ''; 1642 1730 unset( $srcset[768] ); … … 1651 1739 function test_wp_calculate_image_srcset_with_spaces_in_filenames() { 1652 1740 // Mock data for this test. 1653 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test image-300x150.png';1741 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test image-300x150.png'; 1654 1742 $image_meta = array( 1655 'width' => 2000,1743 'width' => 2000, 1656 1744 'height' => 1000, 1657 'file' => '2015/12/test image.png',1658 'sizes' => array(1659 'thumbnail' => array(1660 'file' => 'test image-150x150.png',1661 'width' => 150,1662 'height' => 150,1745 'file' => '2015/12/test image.png', 1746 'sizes' => array( 1747 'thumbnail' => array( 1748 'file' => 'test image-150x150.png', 1749 'width' => 150, 1750 'height' => 150, 1663 1751 'mime-type' => 'image/png', 1664 1752 ), 1665 'medium' => array(1666 'file' => 'test image-300x150.png',1667 'width' => 300,1668 'height' => 150,1753 'medium' => array( 1754 'file' => 'test image-300x150.png', 1755 'width' => 300, 1756 'height' => 150, 1669 1757 'mime-type' => 'image/png', 1670 1758 ), 1671 1759 'medium_large' => array( 1672 'file' => 'test image-768x384.png',1673 'width' => 768,1674 'height' => 384,1760 'file' => 'test image-768x384.png', 1761 'width' => 768, 1762 'height' => 384, 1675 1763 'mime-type' => 'image/png', 1676 1764 ), 1677 'large' => array(1678 'file' => 'test image-1024x512.png',1679 'width' => 1024,1680 'height' => 512,1765 'large' => array( 1766 'file' => 'test image-1024x512.png', 1767 'width' => 1024, 1768 'height' => 512, 1681 1769 'mime-type' => 'image/png', 1682 1770 ), … … 1700 1788 $srcset = wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ); 1701 1789 1702 $year_month = date('Y/m');1790 $year_month = date( 'Y/m' ); 1703 1791 $uploads_dir = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/'; 1704 1792 … … 1707 1795 1708 1796 foreach ( $_wp_additional_image_sizes as $name => $additional_size ) { 1709 if ( ! $_wp_additional_image_sizes[ $name]['crop'] || 0 === $_wp_additional_image_sizes[$name]['height'] ) {1797 if ( ! $_wp_additional_image_sizes[ $name ]['crop'] || 0 === $_wp_additional_image_sizes[ $name ]['height'] ) { 1710 1798 $intermediates[] = $name; 1711 1799 } 1712 1800 } 1713 1801 1714 $expected = "";1802 $expected = ''; 1715 1803 1716 1804 foreach ( $image_meta['sizes'] as $name => $size ) { … … 1721 1809 } 1722 1810 1723 $expected .= $uploads_dir . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';1811 $expected .= $uploads_dir . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; 1724 1812 1725 1813 $expected_srcset = $this->_src_first( $expected, $uploads_dir . $image_meta['file'], $size_array[0] ); … … 1747 1835 */ 1748 1836 function test_wp_get_attachment_image_srcset_invalidsize() { 1749 $image_meta = wp_get_attachment_metadata( self::$large_id );1750 $invalid_size = 'nailthumb';1837 $image_meta = wp_get_attachment_metadata( self::$large_id ); 1838 $invalid_size = 'nailthumb'; 1751 1839 $original_size = array( 1600, 1200 ); 1752 1840 … … 1764 1852 function test_wp_get_attachment_image_sizes() { 1765 1853 // Test sizes against the default WP sizes. 1766 $intermediates = array( 'thumbnail', 'medium', 'medium_large', 'large');1854 $intermediates = array( 'thumbnail', 'medium', 'medium_large', 'large' ); 1767 1855 1768 1856 // Make sure themes aren't filtering the sizes array. 1769 1857 remove_all_filters( 'wp_calculate_image_sizes' ); 1770 1858 1771 foreach ( $intermediates as $int_size ) {1859 foreach ( $intermediates as $int_size ) { 1772 1860 $image = wp_get_attachment_image_src( self::$large_id, $int_size ); 1773 1861 1774 1862 $expected = '(max-width: ' . $image[1] . 'px) 100vw, ' . $image[1] . 'px'; 1775 $sizes = wp_get_attachment_image_sizes( self::$large_id, $int_size );1863 $sizes = wp_get_attachment_image_sizes( self::$large_id, $int_size ); 1776 1864 1777 1865 $this->assertSame( $expected, $sizes ); … … 1785 1873 // Test sizes against the default WP sizes. 1786 1874 $intermediates = array( 'thumbnail', 'medium', 'medium_large', 'large' ); 1787 $image_meta = wp_get_attachment_metadata( self::$large_id );1875 $image_meta = wp_get_attachment_metadata( self::$large_id ); 1788 1876 1789 1877 // Make sure themes aren't filtering the sizes array. … … 1791 1879 1792 1880 foreach ( $intermediates as $int_size ) { 1793 $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int_size );1794 $image_src = $image_meta['sizes'][ $int_size ]['file'];1881 $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int_size ); 1882 $image_src = $image_meta['sizes'][ $int_size ]['file']; 1795 1883 list( $width, $height ) = $size_array; 1796 1884 1797 1885 $expected = '(max-width: ' . $width . 'px) 100vw, ' . $width . 'px'; 1798 $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta );1886 $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta ); 1799 1887 1800 1888 $this->assertSame( $expected, $sizes ); … … 1810 1898 1811 1899 $srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ) ); 1812 $sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) );1900 $sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) ); 1813 1901 1814 1902 // Function used to build HTML for the editor. 1815 $img = get_image_tag( self::$large_id, '', '', '', 'medium' );1903 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); 1816 1904 $img_no_size_in_class = str_replace( 'size-', '', $img ); 1817 $img_no_width_height = str_replace( ' width="' . $size_array[0] . '"', '', $img );1818 $img_no_width_height = str_replace( ' height="' . $size_array[1] . '"', '', $img_no_width_height );1819 $img_no_size_id = str_replace( 'wp-image-', 'id-', $img );1820 $img_with_sizes_attr = str_replace( '<img ', '<img sizes="99vw" ', $img );1821 $img_xhtml = str_replace( ' />', '/>', $img );1822 $img_html5 = str_replace( ' />', '>', $img );1905 $img_no_width_height = str_replace( ' width="' . $size_array[0] . '"', '', $img ); 1906 $img_no_width_height = str_replace( ' height="' . $size_array[1] . '"', '', $img_no_width_height ); 1907 $img_no_size_id = str_replace( 'wp-image-', 'id-', $img ); 1908 $img_with_sizes_attr = str_replace( '<img ', '<img sizes="99vw" ', $img ); 1909 $img_xhtml = str_replace( ' />', '/>', $img ); 1910 $img_html5 = str_replace( ' />', '>', $img ); 1823 1911 1824 1912 // Manually add srcset and sizes to the markup from get_image_tag(); 1825 $respimg = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img );1913 $respimg = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img ); 1826 1914 $respimg_no_size_in_class = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size_in_class ); 1827 $respimg_no_width_height = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height );1828 $respimg_with_sizes_attr = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr );1829 $respimg_xhtml = preg_replace( '|<img ([^>]+)/>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_xhtml );1830 $respimg_html5 = preg_replace( '|<img ([^>]+)>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_html5 );1915 $respimg_no_width_height = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height ); 1916 $respimg_with_sizes_attr = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr ); 1917 $respimg_xhtml = preg_replace( '|<img ([^>]+)/>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_xhtml ); 1918 $respimg_html5 = preg_replace( '|<img ([^>]+)>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_html5 ); 1831 1919 1832 1920 $content = ' … … 1853 1941 1854 1942 $content_unfiltered = sprintf( $content, $img, $img_no_size_in_class, $img_no_width_height, $img_no_size_id, $img_with_sizes_attr, $img_xhtml, $img_html5 ); 1855 $content_filtered = sprintf( $content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $respimg_with_sizes_attr, $respimg_xhtml, $respimg_html5 );1943 $content_filtered = sprintf( $content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $respimg_with_sizes_attr, $respimg_xhtml, $respimg_html5 ); 1856 1944 1857 1945 $this->assertSame( $content_filtered, wp_make_content_images_responsive( $content_unfiltered ) ); … … 1884 1972 // Generate HTML and add a dummy srcset attribute. 1885 1973 $image_html = get_image_tag( self::$large_id, '', '', '', 'medium' ); 1886 $image_html = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $image_html );1974 $image_html = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $image_html ); 1887 1975 1888 1976 // The content filter should return the image unchanged. … … 1897 1985 // Mock meta for an animated gif. 1898 1986 $image_meta = array( 1899 'width' => 1200,1987 'width' => 1200, 1900 1988 'height' => 600, 1901 'file' => 'animated.gif',1902 'sizes' => array(1989 'file' => 'animated.gif', 1990 'sizes' => array( 1903 1991 'thumbnail' => array( 1904 'file' => 'animated-150x150.gif',1905 'width' => 150,1906 'height' => 150,1907 'mime-type' => 'image/gif' 1908 ), 1909 'medium' => array(1910 'file' => 'animated-300x150.gif',1911 'width' => 300,1912 'height' => 150,1913 'mime-type' => 'image/gif' 1914 ), 1915 'large' => array(1916 'file' => 'animated-1024x512.gif',1917 'width' => 1024,1918 'height' => 512,1919 'mime-type' => 'image/gif' 1920 ), 1921 ) 1992 'file' => 'animated-150x150.gif', 1993 'width' => 150, 1994 'height' => 150, 1995 'mime-type' => 'image/gif', 1996 ), 1997 'medium' => array( 1998 'file' => 'animated-300x150.gif', 1999 'width' => 300, 2000 'height' => 150, 2001 'mime-type' => 'image/gif', 2002 ), 2003 'large' => array( 2004 'file' => 'animated-1024x512.gif', 2005 'width' => 1024, 2006 'height' => 512, 2007 'mime-type' => 'image/gif', 2008 ), 2009 ), 1922 2010 ); 1923 2011 … … 1926 2014 1927 2015 // Test with soft resized size array. 1928 $size_array = array( 900, 450);2016 $size_array = array( 900, 450 ); 1929 2017 1930 2018 // Full size GIFs should not return a srcset. … … 1998 2086 'height' => 512, 1999 2087 ), 2000 ) 2088 ), 2001 2089 ); 2002 2090 … … 2025 2113 $attachment = wp_get_attachment_image_src( $id, 'medium' ); 2026 2114 2027 $html = '<img src="%1$s" alt="" width="%2$d" height="%3$d" class="align%4$s size-medium wp-image-%5$d" />';2115 $html = '<img src="%1$s" alt="" width="%2$d" height="%3$d" class="align%4$s size-medium wp-image-%5$d" />'; 2028 2116 $expected = sprintf( $html, $attachment[0], $attachment[1], $attachment[2], $align, $id ); 2029 2117 … … 2097 2185 2098 2186 $actual = wp_get_attachment_image( self::$large_id, 'testsize' ); 2099 $year = date( 'Y' );2100 $month = date( 'm' );2187 $year = date( 'Y' ); 2188 $month = date( 'm' ); 2101 2189 2102 2190 $expected = '<img width="999" height="999" src="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-image-testsize-999x999.png"' . … … 2113 2201 function _filter_36246( $data, $attachment_id ) { 2114 2202 $data['sizes']['testsize'] = array( 2115 'file' => 'test-image-testsize-999x999.png',2116 'width' => 999,2117 'height' => 999,2203 'file' => 'test-image-testsize-999x999.png', 2204 'width' => 999, 2205 'height' => 999, 2118 2206 'mime-type' => 'image/png', 2119 2207 ); … … 2165 2253 'comments' => array( 2166 2254 'creation_time' => array( 2167 '2015-12-24T17:40:09Z' 2255 '2015-12-24T17:40:09Z', 2168 2256 ), 2169 2257 ), … … 2268 2356 'type' => 'image/jpeg', 2269 2357 'error' => 0, 2270 'size' => filesize( $iptc_file ) 2358 'size' => filesize( $iptc_file ), 2271 2359 ); 2272 2360 2273 2361 $parent_id = self::factory()->post->create( array( 'post_date' => '2010-01-01' ) ); 2274 2362 2275 $post_id = media_handle_upload( 'upload', $parent_id, array(), array( 'action' => 'test_iptc_upload', 'test_form' => false ) ); 2363 $post_id = media_handle_upload( 2364 'upload', $parent_id, array(), array( 2365 'action' => 'test_iptc_upload', 2366 'test_form' => false, 2367 ) 2368 ); 2276 2369 2277 2370 unset( $_FILES['upload'] ); … … 2302 2395 'type' => 'image/jpeg', 2303 2396 'error' => 0, 2304 'size' => filesize( $iptc_file ) 2305 ); 2306 2307 $parent_id = self::factory()->post->create( array( 'post_date' => '2010-01-01', 'post_type' => 'page' ) ); 2308 $parent = get_post( $parent_id ); 2309 2310 $post_id = media_handle_upload( 'upload', $parent_id, array(), array( 'action' => 'test_iptc_upload', 'test_form' => false ) ); 2397 'size' => filesize( $iptc_file ), 2398 ); 2399 2400 $parent_id = self::factory()->post->create( 2401 array( 2402 'post_date' => '2010-01-01', 2403 'post_type' => 'page', 2404 ) 2405 ); 2406 $parent = get_post( $parent_id ); 2407 2408 $post_id = media_handle_upload( 2409 'upload', $parent_id, array(), array( 2410 'action' => 'test_iptc_upload', 2411 'test_form' => false, 2412 ) 2413 ); 2311 2414 2312 2415 unset( $_FILES['upload'] );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)