Make WordPress Core

Changeset 60971


Ignore:
Timestamp:
10/19/2025 12:10:22 AM (10 months ago)
Author:
dmsnell
Message:

HTML API: Rely on assertEqualHTML in media tests.

As part of ongoing work to improve the reliability of HTML parsing code in WordPress, this patch replaces strict string-equality tests with semantic tests using assertEqualHTML() to more direct assert intended behaviors.

Developed in https://github.com/WordPress/wordpress-develop/pull/9264
Discussed in https://core.trac.wordpress.org/ticket/63694

Props dmsnell, jonsurrell.
See #63694

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r60911 r60971  
    223223
    224224        public function test_new_img_caption_shortcode_with_html_caption() {
     225                $mark = "\u{203B}";
     226
     227                $this->assertStringNotContainsString(
     228                        self::HTML_CONTENT,
     229                        $mark,
     230                        'Test caption content should not contain the mark surround it: check test setup.'
     231                );
     232
    225233                $result = img_caption_shortcode(
    226234                        array(
    227235                                'width'   => 20,
    228                                 'caption' => self::HTML_CONTENT,
     236                                'caption' => $mark . self::HTML_CONTENT . $mark,
    229237                        )
    230238                );
    231239
    232                 $this->assertSame( 1, substr_count( $result, self::HTML_CONTENT ) );
     240                $result_chunks = explode( $mark, $result );
     241                $this->assertSame(
     242                        3,
     243                        count( $result_chunks ),
     244                        'Expected to find embedded caption inside marks, but failed to do so.'
     245                );
     246
     247                $this->assertEqualHTML(
     248                        self::HTML_CONTENT,
     249                        $result_chunks[1],
     250                        '<body>',
     251                        'Should have embedded the caption inside the image output.'
     252                );
    233253        }
    234254
Note: See TracChangeset for help on using the changeset viewer.