Skip to content

Commit 0b88b8b

Browse files
committed
Leverage assertEqualHTML in tests and add IMG to more test cases
1 parent 0208a08 commit 0b88b8b

1 file changed

Lines changed: 33 additions & 16 deletions

File tree

tests/phpunit/tests/block-supports/block-visibility.php

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function test_block_visibility_support_shows_block_when_support_not_opted
9393
array( 'visibility' => false )
9494
);
9595

96-
$block_content = '<p>This is a test block.</p>';
96+
$block_content = '<div>Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
9797
$block = array(
9898
'blockName' => 'test/visibility-block',
9999
'attrs' => array(
@@ -122,7 +122,7 @@ public function test_block_visibility_support_no_visibility_attribute() {
122122
'attrs' => array(),
123123
);
124124

125-
$block_content = '<div>Test content</div>';
125+
$block_content = '<div>Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
126126
$result = wp_render_block_visibility_support( $block_content, $block );
127127

128128
$this->assertSame( $block_content, $result, 'Block content should remain unchanged when no visibility attribute is present.' );
@@ -150,7 +150,7 @@ public function test_block_visibility_support_generated_css_with_mobile_viewport
150150
),
151151
);
152152

153-
$block_content = '<div>Test content</div>';
153+
$block_content = '<div>Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
154154
$result = wp_render_block_visibility_support( $block_content, $block );
155155

156156
$this->assertStringContainsString( 'wp-block-hidden-mobile', $result, 'Block should have the visibility class for the mobile breakpoint.' );
@@ -186,10 +186,15 @@ public function test_block_visibility_support_generated_css_with_tablet_viewport
186186
),
187187
);
188188

189-
$block_content = '<div class="existing-class">Test content</div>';
189+
$block_content = '<div class="existing-class">Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
190190
$result = wp_render_block_visibility_support( $block_content, $block );
191191

192-
$this->assertStringContainsString( 'class="existing-class wp-block-hidden-tablet"', $result, 'Block should have the existing class and the visibility class for the tablet breakpoint in the class attribute.' );
192+
$this->assertEqualHTML(
193+
'<div class="existing-class wp-block-hidden-tablet">Test content <img fetchpriority="auto" src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>',
194+
$result,
195+
'<body>',
196+
'Block should have the existing class and the visibility class for the tablet breakpoint in the class attribute.'
197+
);
193198

194199
$actual_stylesheet = wp_style_engine_get_stylesheet_from_context( 'block-supports', array( 'prettify' => false ) );
195200

@@ -222,10 +227,15 @@ public function test_block_visibility_support_generated_css_with_desktop_breakpo
222227
),
223228
);
224229

225-
$block_content = '<div>Test content</div>';
230+
$block_content = '<div class="existing-class">Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
226231
$result = wp_render_block_visibility_support( $block_content, $block );
227232

228-
$this->assertStringContainsString( 'class="wp-block-hidden-desktop"', $result, 'Block should have the visibility class for the desktop breakpoint in the class attribute.' );
233+
$this->assertEqualHTML(
234+
'<div class="existing-class wp-block-hidden-desktop">Test content <img fetchpriority="auto" src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>',
235+
$result,
236+
'<body>',
237+
'Block should have the visibility class for the desktop breakpoint in the class attribute.'
238+
);
229239

230240
$actual_stylesheet = wp_style_engine_get_stylesheet_from_context( 'block-supports', array( 'prettify' => false ) );
231241

@@ -279,10 +289,11 @@ public function test_block_visibility_support_generated_css_with_two_viewport_si
279289
);
280290
}
281291

282-
/*
292+
/**
283293
* @ticket 64414
294+
* @ticket 64823
284295
*/
285-
public function test_block_visibility_support_generated_css_with_all_viewport_sizes_visible() {
296+
public function test_block_visibility_support_generated_css_with_all_viewport_sizes_visible(): void {
286297
$this->register_visibility_block_with_support(
287298
'test/viewport-all-visible',
288299
array( 'visibility' => true )
@@ -303,16 +314,17 @@ public function test_block_visibility_support_generated_css_with_all_viewport_si
303314
),
304315
);
305316

306-
$block_content = '<div>Test content</div>';
317+
$block_content = '<div>Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
307318
$result = wp_render_block_visibility_support( $block_content, $block );
308319

309320
$this->assertSame( $block_content, $result, 'Block content should remain unchanged when all breakpoints are visible.' );
310321
}
311322

312-
/*
323+
/**
313324
* @ticket 64414
325+
* @ticket 64823
314326
*/
315-
public function test_block_visibility_support_generated_css_with_all_viewport_sizes_hidden() {
327+
public function test_block_visibility_support_generated_css_with_all_viewport_sizes_hidden(): void {
316328
$this->register_visibility_block_with_support(
317329
'test/viewport-all-hidden',
318330
array( 'visibility' => true )
@@ -333,10 +345,15 @@ public function test_block_visibility_support_generated_css_with_all_viewport_si
333345
),
334346
);
335347

336-
$block_content = '<div>Test content</div>';
348+
$block_content = '<div>Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
337349
$result = wp_render_block_visibility_support( $block_content, $block );
338350

339-
$this->assertSame( '<div class="wp-block-hidden-desktop wp-block-hidden-mobile wp-block-hidden-tablet">Test content</div>', $result, 'Block content should have the visibility classes for all viewport sizes in the class attribute.' );
351+
$this->assertEqualHTML(
352+
'<div class="wp-block-hidden-desktop wp-block-hidden-mobile wp-block-hidden-tablet">Test content <img fetchpriority="auto" src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>',
353+
$result,
354+
'<body>',
355+
'Block content should have the visibility classes for all viewport sizes in the class attribute, and an IMG should get fetchpriority=auto.'
356+
);
340357
}
341358

342359
/*
@@ -357,7 +374,7 @@ public function test_block_visibility_support_generated_css_with_empty_object()
357374
),
358375
);
359376

360-
$block_content = '<div>Test content</div>';
377+
$block_content = '<div>Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
361378
$result = wp_render_block_visibility_support( $block_content, $block );
362379

363380
$this->assertSame( $block_content, $result, 'Block content should remain unchanged when blockVisibility is an empty array.' );
@@ -387,7 +404,7 @@ public function test_block_visibility_support_generated_css_with_unknown_viewpor
387404
),
388405
);
389406

390-
$block_content = '<div>Test content</div>';
407+
$block_content = '<div>Test content <img src="https://example.com/image.jpg" width="1000" height="1000" alt=""></div>';
391408
$result = wp_render_block_visibility_support( $block_content, $block );
392409

393410
$this->assertStringContainsString(

0 commit comments

Comments
 (0)