From 51f47a3fd3f8e3d9fd85447e3e5a07362eec417b Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 29 Oct 2021 16:05:09 +1300 Subject: [PATCH 1/7] Update get_post_galleries to cope with both versions of gallery block --- src/wp-includes/media.php | 72 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 6e7f66760f608..d9bbf82de336a 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -4711,7 +4711,7 @@ function get_post_galleries( $post, $html = true ) { return array(); } - if ( ! has_shortcode( $post->post_content, 'gallery' ) ) { + if ( ! has_shortcode( $post->post_content, 'gallery' ) && ! has_block( 'gallery', $post->post_content ) ) { return array(); } @@ -4753,6 +4753,76 @@ function get_post_galleries( $post, $html = true ) { } } + if ( has_block( 'gallery', $post->post_content ) ) { + $post_blocks = parse_blocks( $post->post_content ); + // Use while/array_shift instead of foreach so we can modify the array from within the loop + while ( $block = array_shift( $post_blocks ) ) { + if ( 'core/gallery' === $block['blockName'] ) { + // If a Gallery block has innerBlocks it is the new format and needs to be handled separately to the old + // format with nested tags. + if ( ! empty( $block['innerBlocks'] ) ) { + $gallery_srcs = array(); + $ids = array(); + $block_html = array(); + foreach ( $block['innerBlocks'] as $image ) { + if ( $html ) { + $block_html[] = $image['innerHTML']; + } else { + $gallery_srcs[] = wp_get_attachment_url( $image ['attrs']['id'] ); + $ids[] = $image ['attrs']['id']; + } + } + if ( $html ) { + $galleries[] = '
' . implode( ' ', $block_html ) . '
'; + } else { + $galleries[] = array( + // array_filter will eliminate any empty entries that came from unknown or invalid IDs + 'src' => array_values( array_filter( array_unique( $gallery_srcs ) ) ), + // Only explicitly include the ids attribute. In future this could be changed to include all attributes, similar to $shortcode_attrs above. + 'ids' => implode( ',', $ids ), + ); + } + } else { + // Now handle the v1 gallery block format. + if ( $html ) { + $galleries[] = $block['innerHTML']; + } elseif ( ! empty( $block['attrs']['ids'] ) ) { + // Use the image IDs from the json blob as canonical if present + $gallery_srcs = array(); + foreach ( $block['attrs']['ids'] as $gallery_img_id ) { + $gallery_srcs[] = wp_get_attachment_url( $gallery_img_id ); + } + $galleries[] = array( + // array_filter will eliminate any empty entries that came from unknown or invalid IDs + 'src' => array_values( array_filter( array_unique( $gallery_srcs ) ) ), + // Only explicitly include the ids attribute. In future this could be changed to include all attributes, similar to $shortcode_attrs above. + 'ids' => implode( ',', $block['attrs']['ids'] ), + ); + } else { + // Otherwise extract srcs from the innerHTML + $srcs = array(); + preg_match_all( '#src=([\'"])(.+?)\1#is', $block['innerHTML'], $src, PREG_SET_ORDER ); + if ( ! empty( $src ) ) { + foreach ( $src as $s ) { + $srcs[] = $s[2]; + } + } + + $galleries[] = array( + // Note that unlike shortcodes, all we are returning here is the src list + 'src' => array_values( array_unique( $srcs ) ), + ); + } + } + } elseif ( ! empty( $block['innerBlocks'] ) ) { + // If we have nested blocks then gradually flatten it by moving those onto the end of the root array for traversal + while ( $inner = array_pop( $block['innerBlocks'] ) ) { + array_push( $post_blocks, $inner ); + } + } + } + } + /** * Filters the list of all found galleries in the given post. * From 6f6bda164abf61c4776447857b9d241ab30b5808 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 1 Nov 2021 10:26:55 +1300 Subject: [PATCH 2/7] Remove errant space --- src/wp-includes/media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index d9bbf82de336a..9832c8a2cf005 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -4769,7 +4769,7 @@ function get_post_galleries( $post, $html = true ) { $block_html[] = $image['innerHTML']; } else { $gallery_srcs[] = wp_get_attachment_url( $image ['attrs']['id'] ); - $ids[] = $image ['attrs']['id']; + $ids[] = $image['attrs']['id']; } } if ( $html ) { From d60bf411a7c925a599a2d8926ab5e0d6661ef9a9 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 2 Nov 2021 17:17:13 +1300 Subject: [PATCH 3/7] Add initial unit tests --- tests/phpunit/tests/media.php | 334 +++++++++++++++++++++++++++++++--- 1 file changed, 309 insertions(+), 25 deletions(-) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 1be2526ff47d9..1fe8f0b9168f8 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -510,9 +510,9 @@ function test_get_attached_images() { * @ticket 22960 */ function test_post_galleries_images() { - $ids1 = array(); - $ids1_srcs = array(); - foreach ( range( 1, 3 ) as $i ) { + $ids = array(); + $ids_srcs = array(); + foreach ( range( 1, 6 ) as $i ) { $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", 0, @@ -523,29 +523,12 @@ function test_post_galleries_images() { ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata ); - $ids1[] = $attachment_id; - $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids[] = $attachment_id; + $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; } - $ids2 = array(); - $ids2_srcs = array(); - foreach ( range( 4, 6 ) as $i ) { - $attachment_id = self::factory()->attachment->create_object( - "image$i.jpg", - 0, - array( - 'post_mime_type' => 'image/jpeg', - 'post_type' => 'attachment', - ) - ); - $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); - wp_update_attachment_metadata( $attachment_id, $metadata ); - $ids2[] = $attachment_id; - $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; - } - - $ids1_joined = implode( ',', $ids1 ); - $ids2_joined = implode( ',', $ids2 ); + $ids1_joined = join( ',', array_slice( $ids, 0, 3 ) ); + $ids2_joined = join( ',', array_slice( $ids, 3, 3 ) ); $blob = <<post->create( array( 'post_content' => $blob ) ); $srcs = get_post_galleries_images( $post_id ); - $this->assertSame( $srcs, array( $ids1_srcs, $ids2_srcs ) ); + $this->assertEquals( $srcs, array( array_slice( $ids_srcs, 0, 3 ), array_slice( $ids_srcs, 3, 3 ) ) ); } /** @@ -707,6 +690,307 @@ function test_post_gallery_images() { $this->assertSame( $srcs, $ids1_srcs ); } + /** + * @ticket 43826 + * @group blocks + */ + function test_block_post_galleries() { + // Set up an unattached image. + $this->factory->attachment->create_object( + array( + 'file' => 'test.jpg', + 'post_parent' => 0, + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment', + ), + ); + + $post_id = $this->factory->post->create( + array( + 'post_content' => '', + ) + ); + + $galleries = get_post_galleries( $post_id, false ); + + $this->assertTrue( is_array( $galleries ) ); + $this->assertEmpty( $galleries[0]['src'] ); + } + + /** + * @ticket 43826 + * @group blocks + */ + function test_block_post_gallery_images() { + // Similar to test_post_gallery_images but with blocks instead of shortcodes + $ids = array(); + $imgs = array(); + $ids_srcs = array(); + foreach ( range( 1, 6 ) as $i ) { + $attachment_id = self::factory()->attachment->create_object( + "image$i.jpg", + 0, + ); + $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); + wp_update_attachment_metadata( $attachment_id, $metadata ); + $ids1[] = $attachment_id; + $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids[] = $attachment_id; + $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $imgs[] = '
'; + + } + + foreach ( range( 4, 6 ) as $i ) { + $imgs1_joined = join( "\n", array_slice( $imgs, 0, 3 ) ); + $imgs2_joined = join( "\n", array_slice( $imgs, 3, 3 ) ); + } + $blob = << +$imgs1_joined + + +$imgs2_joined + +BLOB; + $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); + $srcs = get_post_gallery_images( $post_id ); + $this->assertEquals( $srcs, array_slice( $ids_srcs, 0, 3 ) ); + } + + /** + * @ticket 43826 + * @group blocks + */ + function test_block_post_gallery_images_json() { + // Similar to test_block_post_gallery_images, with IDs in the json blob + $ids = array(); + $imgs = array(); + $ids_srcs = array(); + foreach ( range( 1, 6 ) as $i ) { + $attachment_id = self::factory()->attachment->create_object( + "image$i.jpg", + 0, + ); + $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); + wp_update_attachment_metadata( $attachment_id, $metadata ); + $ids[] = $attachment_id; + $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $imgs[] = '
'; + + } + + $ids1_joined = join( ',', array_slice( $ids, 0, 3 ) ); + $ids2_joined = join( ',', array_slice( $ids, 3, 3 ) ); + + $blob = << + + + + +BLOB; + $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); + $srcs = get_post_gallery_images( $post_id ); + $this->assertEquals( $srcs, array_slice( $ids_srcs, 0, 3 ) ); + } + + /** + * @ticket 43826 + * @group blocks + */ + function test_mixed_post_gallery_images() { + // Similar to test_post_gallery_images but with a shortcode and a block in the same post + $ids = array(); + $imgs = array(); + $ids_srcs = array(); + foreach ( range( 1, 6 ) as $i ) { + $attachment_id = self::factory()->attachment->create_object( + "image$i.jpg", + 0, + array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment', + ) + ); + $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); + wp_update_attachment_metadata( $attachment_id, $metadata ); + $ids[] = $attachment_id; + $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $imgs[] = '
'; + } + + $ids1_joined = join( "\n", array_slice( $ids, 0, 3 ) ); + $ids2_joined = join( "\n", array_slice( $ids, 3, 3 ) ); + $imgs2_joined = join( "\n", array_slice( $imgs, 3, 3 ) ); + + $blob = << +$imgs2_joined + +BLOB; + $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); + $srcs = get_post_gallery_images( $post_id ); + $this->assertEquals( $srcs, array_slice( $ids_srcs, 0, 3 ) ); + } + + /** + * @ticket 43826 + * @group blocks + */ + function test_mixed_post_galleries() { + // Test the get_post_galleries() function in $html=false mode, with both shortcode and block galleries + $ids = array(); + $imgs = array(); + $ids_srcs = array(); + foreach ( range( 1, 6 ) as $i ) { + $attachment_id = self::factory()->attachment->create_object( + "image$i.jpg", + 0, + array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment', + ) + ); + $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); + wp_update_attachment_metadata( $attachment_id, $metadata ); + $ids[] = $attachment_id; + $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $imgs[] = '
'; + + } + + $ids1_joined = join( ',', array_slice( $ids, 0, 3 ) ); + $ids2_joined = join( ',', array_slice( $ids, 3, 3 ) ); + + $blob = << + +BLOB; + + $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); + + $galleries = get_post_galleries( $post_id, false ); + $this->assertEquals( + $galleries, + array( + array( + 'ids' => $ids1_joined, + 'src' => array_slice( $ids_srcs, 0, 3 ), + ), + array( + 'ids' => $ids2_joined, + 'src' => array_slice( $ids_srcs, 3, 3 ), + ), + ) + ); + + } + + /** + * @ticket 43826 + * @group blocks + */ + function test_mixed_post_galleries_data() { + // Test attributes returned by get_post_galleries() function in $html=false mode, with both shortcode and block galleries + $ids = array(); + $imgs = array(); + $ids_srcs = array(); + foreach ( range( 1, 6 ) as $i ) { + $attachment_id = self::factory()->attachment->create_object( + "image$i.jpg", + 0, + array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment', + ) + ); + $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); + wp_update_attachment_metadata( $attachment_id, $metadata ); + $ids[] = $attachment_id; + $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $imgs[] = '
'; + + } + + $ids1_joined = join( ',', array_slice( $ids, 0, 3 ) ); + $ids2_joined = join( ',', array_slice( $ids, 3, 3 ) ); + $blob = << + +BLOB; + + $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); + + $galleries = get_post_galleries( $post_id, false ); + $this->assertEquals( + $galleries, + array( + array( + 'ids' => $ids1_joined, + 'src' => array_slice( $ids_srcs, 0, 3 ), + 'type' => 'type', + 'foo' => 'bar', // The shortcode code passes arbitrary attributes + ), + array( + 'ids' => $ids2_joined, + 'src' => array_slice( $ids_srcs, 3, 3 ), + // The block only passes ids, no other attributes + ), + ) + ); + + } + + /** + * @ticket 43826 + * @group blocks + */ + function test_block_inner_post_gallery_images() { + // Make sure get_post_gallery_images() works with gallery blocks that are nested inside something else + $ids = array(); + $imgs = array(); + $ids_srcs = array(); + foreach ( range( 1, 3 ) as $i ) { + $attachment_id = self::factory()->attachment->create_object( + "image$i.jpg", + 0, + array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment', + ) + ); + $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); + wp_update_attachment_metadata( $attachment_id, $metadata ); + $ids[] = $attachment_id; + $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $imgs[] = '
'; + + } + + $imgs_joined = join( "\n", $imgs ); + + $blob = << + + +$imgs_joined + + + +BLOB; + $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); + $srcs = get_post_gallery_images( $post_id ); + $this->assertEquals( $srcs, $ids_srcs ); + } + function test_get_media_embedded_in_content() { $object = << From 6c9458eab452d949332ec50b4b4e913e171d527d Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 3 Nov 2021 10:10:58 +1300 Subject: [PATCH 4/7] Add test for new nested image blocks gallery format --- tests/phpunit/tests/media.php | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 1fe8f0b9168f8..da718a30c15ad 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -991,6 +991,46 @@ function test_block_inner_post_gallery_images() { $this->assertEquals( $srcs, $ids_srcs ); } + /** + * @ticket 43826 + * @group blocks + */ + function test_block_post_gallery_innerblock_images() { + // Make sure get_post_gallery_images() works with new version of gallery block with nested image blocks. + $ids = array(); + $imgs = array(); + $ids_srcs = array(); + foreach ( range( 1, 3 ) as $i ) { + $attachment_id = self::factory()->attachment->create_object( + "image$i.jpg", + 0, + array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment', + ) + ); + $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); + wp_update_attachment_metadata( $attachment_id, $metadata ); + $ids[] = $attachment_id; + $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $imgs[] = '
'; + + } + + $imgs_joined = join( "\n", $imgs ); + + $blob = << + + +BLOB; + $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); + $srcs = get_post_gallery_images( $post_id ); + $this->assertEquals( $srcs, $ids_srcs ); + } + function test_get_media_embedded_in_content() { $object = << From 3dedd53fadc4a32bccf1d72802fd526fc9972508 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 3 Nov 2021 10:41:50 +1300 Subject: [PATCH 5/7] Fix linting issues --- tests/phpunit/tests/media.php | 47 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index da718a30c15ad..45de6a83eb1c0 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -736,7 +736,8 @@ function test_block_post_gallery_images() { $ids1[] = $attachment_id; $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; $ids[] = $attachment_id; - $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids_srcs[] = $url; $imgs[] = '
'; } @@ -774,9 +775,10 @@ function test_block_post_gallery_images_json() { ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata ); - $ids[] = $attachment_id; - $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; - $imgs[] = '
'; + $ids[] = $attachment_id; + $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids_srcs[] = $url; + $imgs[] = '
'; } @@ -815,9 +817,10 @@ function test_mixed_post_gallery_images() { ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata ); - $ids[] = $attachment_id; - $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; - $imgs[] = '
'; + $ids[] = $attachment_id; + $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids_srcs[] = $url; + $imgs[] = '
'; } $ids1_joined = join( "\n", array_slice( $ids, 0, 3 ) ); @@ -857,9 +860,10 @@ function test_mixed_post_galleries() { ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata ); - $ids[] = $attachment_id; - $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; - $imgs[] = '
'; + $ids[] = $attachment_id; + $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids_srcs[] = $url; + $imgs[] = '
'; } @@ -912,15 +916,16 @@ function test_mixed_post_galleries_data() { ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata ); - $ids[] = $attachment_id; - $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; - $imgs[] = '
'; + $ids[] = $attachment_id; + $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids_srcs[] = $url; + $imgs[] = '
'; } $ids1_joined = join( ',', array_slice( $ids, 0, 3 ) ); $ids2_joined = join( ',', array_slice( $ids, 3, 3 ) ); - $blob = << @@ -969,9 +974,10 @@ function test_block_inner_post_gallery_images() { ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata ); - $ids[] = $attachment_id; - $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; - $imgs[] = '
'; + $ids[] = $attachment_id; + $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids_srcs[] = $url; + $imgs[] = '
'; } @@ -1011,9 +1017,10 @@ function test_block_post_gallery_innerblock_images() { ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata ); - $ids[] = $attachment_id; - $url = $ids_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; - $imgs[] = '
'; + $ids[] = $attachment_id; + $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; + $ids_srcs[] = $url; + $imgs[] = '
'; } From 12697fc3240126e1d79f1983403e0511a204c831 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 3 Nov 2021 11:08:04 +1300 Subject: [PATCH 6/7] Remove extra , --- tests/phpunit/tests/media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 45de6a83eb1c0..e3885a78883cf 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -702,7 +702,7 @@ function test_block_post_galleries() { 'post_parent' => 0, 'post_mime_type' => 'image/jpeg', 'post_type' => 'attachment', - ), + ) ); $post_id = $this->factory->post->create( From c45ef120ef4d7eb00e02330d191853a7095b233b Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 3 Nov 2021 11:21:09 +1300 Subject: [PATCH 7/7] More errant ,s removed --- tests/phpunit/tests/media.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index e3885a78883cf..101019b9646a4 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -729,7 +729,7 @@ function test_block_post_gallery_images() { foreach ( range( 1, 6 ) as $i ) { $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", - 0, + 0 ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata ); @@ -771,7 +771,7 @@ function test_block_post_gallery_images_json() { foreach ( range( 1, 6 ) as $i ) { $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", - 0, + 0 ); $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta ); wp_update_attachment_metadata( $attachment_id, $metadata );