Skip to content

Commit 86546fd

Browse files
committed
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 #9264 Discussed in https://core.trac.wordpress.org/ticket/63694 Props dmsnell, jonsurrell. See #63694 git-svn-id: https://develop.svn.wordpress.org/trunk@60971 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 843b569 commit 86546fd

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/phpunit/tests/media.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,34 @@ public function test_img_caption_shortcode_with_old_format_and_class() {
222222
}
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

235255
public function test_new_img_caption_shortcode_new_format() {

0 commit comments

Comments
 (0)