Changeset 48237 for trunk/tests/phpunit/tests/media.php
- Timestamp:
- 06/30/2020 07:28:07 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/media.php
r48190 r48237 1964 1964 /** 1965 1965 * @ticket 33641 1966 * @ticket 50367 1967 */ 1968 function test_wp_filter_content_tags() { 1966 */ 1967 function test_wp_filter_content_tags_srcset_sizes() { 1969 1968 $image_meta = wp_get_attachment_metadata( self::$large_id ); 1970 1969 $size_array = $this->_get_image_size_array_from_meta( $image_meta, 'medium' ); … … 1975 1974 // Function used to build HTML for the editor. 1976 1975 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); 1977 $img = wp_img_tag_add_loading_attr( $img, 'test' );1978 1976 $img_no_size_in_class = str_replace( 'size-', '', $img ); 1979 1977 $img_no_width_height = str_replace( ' width="' . $size_array[0] . '"', '', $img ); … … 1984 1982 $img_html5 = str_replace( ' />', '>', $img ); 1985 1983 1986 $hwstring = image_hwstring( $size_array[0], $size_array[1] );1987 1988 1984 // Manually add srcset and sizes to the markup from get_image_tag(). 1989 1985 $respimg = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img ); 1990 1986 $respimg_no_size_in_class = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size_in_class ); 1991 $respimg_no_width_height = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $ hwstring . $srcset . ' ' . $sizes . ' />', $img_no_width_height );1987 $respimg_no_width_height = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height ); 1992 1988 $respimg_with_sizes_attr = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr ); 1993 1989 $respimg_xhtml = preg_replace( '|<img ([^>]+)/>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_xhtml ); … … 2001 1997 %2$s 2002 1998 2003 <p>Image, no width and height attributes. Should have width, height,srcset and sizes (from matching the file name).</p>1999 <p>Image, no width and height attributes. Should have srcset and sizes (from matching the file name).</p> 2004 2000 %3$s 2005 2001 … … 2019 2015 $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 ); 2020 2016 2017 // Do not add width, height, and loading. 2018 add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); 2019 add_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); 2020 2021 2021 $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) ); 2022 2023 remove_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); 2024 remove_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); 2022 2025 } 2023 2026 … … 2033 2036 * @ticket 33641 2034 2037 */ 2035 function test_wp_filter_content_tags_ wrong() {2038 function test_wp_filter_content_tags_srcset_sizes_wrong() { 2036 2039 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); 2037 2040 $img = wp_img_tag_add_loading_attr( $img, 'test' ); … … 2046 2049 * @ticket 33641 2047 2050 */ 2048 function test_wp_filter_content_tags_ with_preexisting_srcset() {2051 function test_wp_filter_content_tags_srcset_sizes_with_preexisting_srcset() { 2049 2052 // Generate HTML and add a dummy srcset attribute. 2050 2053 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); … … 2533 2536 2534 2537 /** 2538 * @ticket 50367 2539 */ 2540 function test_wp_filter_content_tags_width_height() { 2541 $image_meta = wp_get_attachment_metadata( self::$large_id ); 2542 $size_array = $this->_get_image_size_array_from_meta( $image_meta, 'medium' ); 2543 2544 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); 2545 $img_no_width_height = str_replace( ' width="' . $size_array[0] . '"', '', $img ); 2546 $img_no_width_height = str_replace( ' height="' . $size_array[1] . '"', '', $img_no_width_height ); 2547 $img_no_width = str_replace( ' width="' . $size_array[0] . '"', '', $img ); 2548 $img_no_height = str_replace( ' height="' . $size_array[1] . '"', '', $img ); 2549 2550 $hwstring = image_hwstring( $size_array[0], $size_array[1] ); 2551 2552 // Manually add width and height to the markup from get_image_tag(). 2553 $respimg_no_width_height = str_replace( '<img ', '<img ' . $hwstring, $img_no_width_height ); 2554 2555 $content = ' 2556 <p>Image, with width and height. Should NOT be modified.</p> 2557 %1$s 2558 2559 <p>Image, no width and height attributes. Should have width, height, srcset and sizes (from matching the file name).</p> 2560 %2$s 2561 2562 <p>Image, no width but height attribute. Should NOT be modified.</p> 2563 %3$s 2564 2565 <p>Image, no height but width attribute. Should NOT be modified.</p> 2566 %4$s'; 2567 2568 $content_unfiltered = sprintf( $content, $img, $img_no_width_height, $img_no_width, $img_no_height ); 2569 $content_filtered = sprintf( $content, $img, $respimg_no_width_height, $img_no_width, $img_no_height ); 2570 2571 // Do not add loading, srcset, and sizes. 2572 add_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); 2573 add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 2574 2575 $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) ); 2576 2577 remove_filter( 'wp_img_tag_add_loading_attr', '__return_false' ); 2578 remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 2579 } 2580 2581 /** 2535 2582 * @ticket 44427 2536 2583 * @ticket 50367 2537 2584 */ 2538 function test_wp_ lazy_load_content_media() {2585 function test_wp_filter_content_tags_loading_lazy() { 2539 2586 $image_meta = wp_get_attachment_metadata( self::$large_id ); 2540 2587 $size_array = $this->_get_image_size_array_from_meta( $image_meta, 'medium' ); … … 2571 2618 $content_filtered = sprintf( $content, $lazy_img, $lazy_img_xhtml, $lazy_img_html5, $img_eager, $img_no_width_height, $iframe ); 2572 2619 2573 // Do not add srcset and sizes. 2620 // Do not add width, height, srcset, and sizes. 2621 add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); 2574 2622 add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 2575 2623 2576 2624 $this->assertSame( $content_filtered, wp_filter_content_tags( $content_unfiltered ) ); 2577 2625 2626 remove_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); 2578 2627 remove_filter( 'wp_img_tag_add_srcset_and_sizes_attr', '__return_false' ); 2579 2628 } … … 2582 2631 * @ticket 44427 2583 2632 */ 2584 function test_wp_ lazy_load_content_media_opted_in() {2633 function test_wp_filter_content_tags_loading_lazy_opted_in() { 2585 2634 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); 2586 2635 $lazy_img = wp_img_tag_add_loading_attr( $img, 'test' ); … … 2607 2656 * @ticket 44427 2608 2657 */ 2609 function test_wp_ lazy_load_content_media_opted_out() {2658 function test_wp_filter_content_tags_loading_lazy_opted_out() { 2610 2659 $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); 2611 2660 … … 2627 2676 2628 2677 /** 2629 * @ticket 444272630 */ 2631 function test_wp_img_tag_add_loading_attr_ single_quote() {2632 $img = "<img src='example.png' alt='' width='300' height='225' />";2678 * @ticket 50367 2679 */ 2680 function test_wp_img_tag_add_loading_attr_without_src() { 2681 $img = '<img alt=" width="300" height="225" />'; 2633 2682 $img = wp_img_tag_add_loading_attr( $img, 'test' ); 2634 2683 2635 $this->assert Contains( " loading='lazy'", $img );2684 $this->assertNotContains( ' loading="lazy"', $img ); 2636 2685 } 2637 2686 }
Note: See TracChangeset
for help on using the changeset viewer.