Make WordPress Core

Changeset 64747


Ignore:
Timestamp:
10/26/2026 09:49:27 PM (4 days ago)
Author:
lancewillett
Message:

Tests: Resolve gallery attachment IDs after fixture setup.

Resolve the gallery shortcode's attachment ID during test execution instead of in the data provider, which runs before fixture setup. Add an unrelated attachment and assert that the response includes only the intended caption.

Preserve the existing success and rejection expectations for all three shortcode cases.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14832

Props benitoalba.
See #66211.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/wpAjaxParseMediaShortcode.php

    r64505 r64747  
    3434                        )
    3535                );
     36                $factory->attachment->create_object(
     37                        get_temp_dir() . 'canola.jpg',
     38                        0,
     39                        array(
     40                                'post_mime_type' => 'image/jpeg',
     41                                'post_excerpt'   => 'An unrelated caption',
     42                        )
     43                );
    3644        }
    3745        /**
    … …  
    4048        public function test_parse_shortcode( array $payload, $expected ) {
    4149                add_shortcode( 'test', array( $this, 'shortcode_test' ) );
     50                $payload['shortcode'] = sprintf( $payload['shortcode'], self::$media_id );
    4251
    4352                $_POST = array_merge(
    … …  
    6170                }
    6271                $this->assertSame( $expected['success'], $response['success'] );
     72                if ( $expected['success'] ) {
     73                        $this->assertStringContainsString( 'A sample caption', $body );
     74                        $this->assertStringNotContainsString( 'An unrelated caption', $body );
     75                }
    6376        }
    6477
    … …  
    7083                return array(
    7184                        'gallery_shortcode_is_allowed'         => array(
    72                                 'payload'  => array( 'shortcode' => '[gallery ids=" ' . self::$media_id . '"]' ),
     85                                'payload'  => array( 'shortcode' => '[gallery ids="%d"]' ),
    7386                                'expected' => array( 'success' => true ),
    7487                        ),
    7588                        'gallery_and_custom_test_shortcode_is_not_allowed' => array(
    76                                 'payload'  => array( 'shortcode' => '[gallery ids=" ' . self::$media_id . '"] [test]' ),
     89                                'payload'  => array( 'shortcode' => '[gallery ids="%d"] [test]' ),
    7790                                'expected' => array( 'success' => false ),
    7891                        ),
Note: See TracChangeset for help on using the changeset viewer.