@@ -26,6 +26,21 @@ public static function set_up_before_class(): void {
2626 self ::$ image_id = self ::factory ()->attachment ->create_upload_object ( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg ' );
2727 }
2828
29+ public function set_up (): void {
30+ parent ::set_up ();
31+
32+ // Disable auto sizes.
33+ remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
34+ }
35+
36+ public function tear_down (): void {
37+ // Clean up specific to the tests within this class.
38+ parent ::tear_down ();
39+
40+ // Enable auto sizes.
41+ add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
42+ }
43+
2944 /**
3045 * Test the image block with different image sizes and full alignment.
3146 *
@@ -36,11 +51,7 @@ public static function set_up_before_class(): void {
3651 public function test_image_block_with_full_alignment ( string $ image_size ): void {
3752 $ block_content = '<!-- wp:image {"id": ' . self ::$ image_id . ',"sizeSlug":" ' . $ image_size . '","linkDestination":"none","align":"full"} --><figure class="wp-block-image size- ' . $ image_size . '"><img src=" ' . wp_get_attachment_image_url ( self ::$ image_id , $ image_size ) . '" alt="" class="wp-image- ' . self ::$ image_id . '"/></figure><!-- /wp:image --> ' ;
3853
39- // Disable auto sizes.
40- remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
4154 $ result = apply_filters ( 'the_content ' , $ block_content );
42- // Enable auto sizes.
43- add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
4455
4556 $ this ->assertStringContainsString ( 'sizes="100vw" ' , $ result );
4657 }
@@ -56,11 +67,7 @@ public function test_cover_block_with_full_alignment(): void {
5667 <!-- /wp:paragraph --></div></div>
5768 <!-- /wp:cover --> ' ;
5869
59- // Disable auto sizes.
60- remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
6170 $ result = apply_filters ( 'the_content ' , $ block_content );
62- // Enable auto sizes.
63- add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
6471
6572 $ this ->assertStringContainsString ( 'sizes="100vw" ' , $ result );
6673 }
@@ -75,11 +82,7 @@ public function test_cover_block_with_full_alignment(): void {
7582 public function test_image_block_with_wide_alignment ( string $ image_size ): void {
7683 $ block_content = '<!-- wp:image {"id": ' . self ::$ image_id . ',"sizeSlug":" ' . $ image_size . '","linkDestination":"none","align":"wide"} --><figure class="wp-block-image size- ' . $ image_size . '"><img src=" ' . wp_get_attachment_image_url ( self ::$ image_id , $ image_size ) . '" alt="" class="wp-image- ' . self ::$ image_id . '"/></figure><!-- /wp:image --> ' ;
7784
78- // Disable auto sizes.
79- remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
8085 $ result = apply_filters ( 'the_content ' , $ block_content );
81- // Enable auto sizes.
82- add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
8386
8487 $ this ->assertStringContainsString ( 'sizes="(max-width: 1280px) 100vw, 1280px" ' , $ result );
8588 }
@@ -117,11 +120,7 @@ public function test_cover_block_with_wide_alignment(): void {
117120 <!-- /wp:paragraph --></div></div>
118121 <!-- /wp:cover --> ' ;
119122
120- // Disable auto sizes.
121- remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
122123 $ result = apply_filters ( 'the_content ' , $ block_content );
123- // Enable auto sizes.
124- add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
125124
126125 $ this ->assertStringContainsString ( 'sizes="(max-width: 1280px) 100vw, 1280px" ' , $ result );
127126 }
@@ -142,11 +141,7 @@ public function test_image_block_with_default_alignment( string $image_size, str
142141 $ block_content = '<!-- wp:image {"id": ' . self ::$ image_id . ',"sizeSlug":" ' . $ image_size . '","linkDestination":"none"} --><figure class="wp-block-image size- ' . $ image_size . '"><img src=" ' . wp_get_attachment_image_url ( self ::$ image_id , $ image_size ) . '" alt="" class="wp-image- ' . self ::$ image_id . '"/></figure><!-- /wp:image --> ' ;
143142 }
144143
145- // Disable auto sizes.
146- remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
147144 $ result = apply_filters ( 'the_content ' , $ block_content );
148- // Enable auto sizes.
149- add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
150145
151146 $ this ->assertStringContainsString ( $ expected , $ result );
152147 }
@@ -208,11 +203,7 @@ public function test_cover_block_with_default_alignment(): void {
208203 <!-- /wp:paragraph --></div></div>
209204 <!-- /wp:cover --> ' ;
210205
211- // Disable auto sizes.
212- remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
213206 $ result = apply_filters ( 'the_content ' , $ block_content );
214- // Enable auto sizes.
215- add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
216207
217208 $ this ->assertStringContainsString ( 'sizes="(max-width: 620px) 100vw, 620px" ' , $ result );
218209 }
@@ -234,11 +225,7 @@ public function test_image_block_with_left_right_center_alignment( string $image
234225 $ block_content = '<!-- wp:image {"id": ' . self ::$ image_id . ',"sizeSlug":" ' . $ image_size . '","linkDestination":"none","align":" ' . $ alignment . '"} --><figure class="wp-block-image size- ' . $ image_size . '"><img src=" ' . wp_get_attachment_image_url ( self ::$ image_id , $ image_size ) . '" alt="" class="wp-image- ' . self ::$ image_id . '"/></figure><!-- /wp:image --> ' ;
235226 }
236227
237- // Disable auto sizes.
238- remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
239228 $ result = apply_filters ( 'the_content ' , $ block_content );
240- // Enable auto sizes.
241- add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
242229
243230 $ this ->assertStringContainsString ( $ expected , $ result );
244231 }
@@ -400,11 +387,7 @@ public function test_cover_block_with_left_right_center_alignment( string $align
400387 <!-- /wp:paragraph --></div></div>
401388 <!-- /wp:cover --> ' ;
402389
403- // Disable auto sizes.
404- remove_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
405390 $ result = apply_filters ( 'the_content ' , $ block_content );
406- // Enable auto sizes.
407- add_filter ( 'wp_content_img_tag ' , 'auto_sizes_update_content_img_tag ' );
408391
409392 $ this ->assertStringContainsString ( 'sizes="(max-width: 1080px) 100vw, 1080px" ' , $ result );
410393 }
0 commit comments