Changeset 52797
- Timestamp:
- 02/25/2022 12:42:10 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r52725 r52797 4781 4781 } 4782 4782 4783 // All blocks nested inside non-Gallery blocks should be in the root array. 4784 if ( $has_inner_blocks && 'core/gallery' !== $block['blockName'] ) { 4785 array_push( $post_blocks, ...$block['innerBlocks'] ); 4783 // Skip non-Gallery blocks. 4784 if ( 'core/gallery' !== $block['blockName'] ) { 4785 // Move inner blocks into the root array before skipping. 4786 if ( $has_inner_blocks ) { 4787 array_push( $post_blocks, ...$block['innerBlocks'] ); 4788 } 4786 4789 continue; 4787 4790 } -
trunk/tests/phpunit/tests/media/getPostGalleries.php
r52190 r52797 40 40 $galleries = get_post_galleries( $post_id, false ); 41 41 $this->assertEmpty( $galleries ); 42 } 43 44 /** 45 * Test that only galleries are returned. 46 * 47 * @dataProvider data_returns_only_galleries 48 * 49 * @ticket 55203 50 * 51 * @param string $content The content of the post. 52 * @param string $needle The content of a non-gallery block. 53 */ 54 public function test_returns_only_galleries( $content, $needle ) { 55 $image_id = $this->factory->attachment->create_object( 56 array( 57 'file' => 'test.jpg', 58 'post_parent' => 0, 59 'post_mime_type' => 'image/jpeg', 60 'post_type' => 'attachment', 61 ) 62 ); 63 64 $image_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg'; 65 66 $content = str_replace( 67 array( 'IMAGE_ID', 'IMAGE_URL' ), 68 array( $image_id, $image_url ), 69 $content 70 ); 71 72 $post_id = $this->factory->post->create( 73 array( 74 'post_content' => $content, 75 ) 76 ); 77 78 $galleries = get_post_galleries( $post_id ); 79 $actual = implode( '', $galleries ); 80 81 $this->assertStringNotContainsString( $needle, $actual ); 82 } 83 84 /** 85 * Data provider. 86 * 87 * @return array 88 */ 89 public function data_returns_only_galleries() { 90 $gallery = ' 91 <!-- wp:gallery {"linkTo":"none","className":"columns-2"} --> 92 <figure 93 class="wp-block-gallery has-nested-images columns-default is-cropped columns-2" 94 > 95 <!-- wp:image {"id":IMAGE_ID,"sizeSlug":"large","linkDestination":"none"} --> 96 <figure class="wp-block-image size-large"> 97 <img 98 src="IMAGE_URL" 99 alt="Image gallery image" 100 class="wp-image-IMAGE_ID" 101 /> 102 </figure> 103 <!-- /wp:image --> 104 </figure> 105 <!-- /wp:gallery --> 106 '; 107 108 return array( 109 'a paragraph before a gallery' => array( 110 'content' => '<!-- wp:paragraph --><p>A paragraph before a gallery.</p><!-- /wp:paragraph -->' . $gallery, 111 'needle' => 'A paragraph before a gallery.', 112 ), 113 'a paragraph after a gallery' => array( 114 'content' => $gallery . '<!-- wp:paragraph --><p>A paragraph after a gallery.</p><!-- /wp:paragraph -->', 115 'needle' => 'A paragraph after a gallery.', 116 ), 117 ); 42 118 } 43 119
Note: See TracChangeset
for help on using the changeset viewer.