| | 607 | /** |
| | 608 | * @ticket 43826 |
| | 609 | */ |
| | 610 | function test_block_post_galleries() { |
| | 611 | // Set up an unattached image. |
| | 612 | $this->factory->attachment->create_object( array( |
| | 613 | 'file' => 'test.jpg', |
| | 614 | 'post_parent' => 0, |
| | 615 | 'post_mime_type' => 'image/jpeg', |
| | 616 | 'post_type' => 'attachment' |
| | 617 | ) ); |
| | 618 | |
| | 619 | $post_id = $this->factory->post->create( array( |
| | 620 | 'post_content' => '<!-- wp:gallery -->', |
| | 621 | ) ); |
| | 622 | |
| | 623 | $galleries = get_post_galleries( $post_id, false ); |
| | 624 | |
| | 625 | $this->assertTrue( is_array( $galleries ) ); |
| | 626 | $this->assertEmpty( $galleries[0]['src'] ); |
| | 627 | } |
| | 628 | |
| | 629 | /** |
| | 630 | * @ticket 43826 |
| | 631 | */ |
| | 632 | function test_block_post_gallery_images() { |
| | 633 | // Similar to test_post_gallery_images but with blocks instead of shortcodes |
| | 634 | $ids1 = array(); |
| | 635 | $imgs1 = array(); |
| | 636 | $ids1_srcs = array(); |
| | 637 | foreach ( range( 1, 3 ) as $i ) { |
| | 638 | $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", 0, array( |
| | 639 | 'post_mime_type' => 'image/jpeg', |
| | 640 | 'post_type' => 'attachment' |
| | 641 | ) ); |
| | 642 | $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta ); |
| | 643 | wp_update_attachment_metadata( $attachment_id, $metadata ); |
| | 644 | $ids1[] = $attachment_id; |
| | 645 | $url = $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 646 | $imgs1[] = '<figure><img src="' . $url . '" data-id="' . $i . '" /></figure>'; |
| | 647 | |
| | 648 | } |
| | 649 | |
| | 650 | $ids2 = array(); |
| | 651 | $imgs2 = array(); |
| | 652 | $ids2_srcs = array(); |
| | 653 | foreach ( range( 4, 6 ) as $i ) { |
| | 654 | $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", 0, array( |
| | 655 | 'post_mime_type' => 'image/jpeg', |
| | 656 | 'post_type' => 'attachment' |
| | 657 | ) ); |
| | 658 | $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta ); |
| | 659 | wp_update_attachment_metadata( $attachment_id, $metadata ); |
| | 660 | $ids2[] = $attachment_id; |
| | 661 | $url = $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 662 | $imgs2[] = '<figure><img src="' . $url . '" data-id="' . $i . '" /></figure>'; |
| | 663 | } |
| | 664 | |
| | 665 | $imgs1_joined = join( "\n", $imgs1 ); |
| | 666 | $imgs2_joined = join( "\n", $imgs2 ); |
| | 667 | |
| | 668 | $blob =<<<BLOB |
| | 669 | <!-- wp:gallery --> |
| | 670 | $imgs1_joined |
| | 671 | <!-- /wp:gallery --> |
| | 672 | |
| | 673 | <!-- wp:gallery --> |
| | 674 | $imgs2_joined |
| | 675 | <!-- /wp:gallery --> |
| | 676 | BLOB; |
| | 677 | $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); |
| | 678 | $srcs = get_post_gallery_images( $post_id ); |
| | 679 | $this->assertEquals( $srcs, $ids1_srcs ); |
| | 680 | } |
| | 681 | |
| | 682 | /** |
| | 683 | * @ticket 43826 |
| | 684 | */ |
| | 685 | function test_block_inner_post_gallery_images() { |
| | 686 | // Make sure get_post_gallery_images() works with gallery blocks that are nested inside something else |
| | 687 | $ids1 = array(); |
| | 688 | $imgs1 = array(); |
| | 689 | $ids1_srcs = array(); |
| | 690 | foreach ( range( 1, 3 ) as $i ) { |
| | 691 | $attachment_id = self::factory()->attachment->create_object( "image$i.jpg", 0, array( |
| | 692 | 'post_mime_type' => 'image/jpeg', |
| | 693 | 'post_type' => 'attachment' |
| | 694 | ) ); |
| | 695 | $metadata = array_merge( array( "file" => "image$i.jpg" ), $this->img_meta ); |
| | 696 | wp_update_attachment_metadata( $attachment_id, $metadata ); |
| | 697 | $ids1[] = $attachment_id; |
| | 698 | $url = $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 699 | $imgs1[] = '<figure><img src="' . $url . '" data-id="' . $i . '" /></figure>'; |
| | 700 | |
| | 701 | } |
| | 702 | |
| | 703 | $imgs1_joined = join( "\n", $imgs1 ); |
| | 704 | |
| | 705 | $blob =<<<BLOB |
| | 706 | <!-- wp:columns --> |
| | 707 | <!-- wp:column --> |
| | 708 | <!-- wp:gallery --> |
| | 709 | $imgs1_joined |
| | 710 | <!-- /wp:gallery --> |
| | 711 | <!-- /wp:column --> |
| | 712 | <!-- /wp:columns --> |
| | 713 | BLOB; |
| | 714 | $post_id = self::factory()->post->create( array( 'post_content' => $blob ) ); |
| | 715 | $srcs = get_post_gallery_images( $post_id ); |
| | 716 | $this->assertEquals( $srcs, $ids1_srcs ); |
| | 717 | } |
| | 718 | |