Skip to content

Commit 05dcc36

Browse files
Tests: Fix output buffer test to correctly capture callback-processed output
ob_get_flush() returns the original unprocessed buffer content, not the callback-processed result. Use a nested buffer approach instead: start an outer buffer, flush the inner buffer (triggering the callback), then get the processed content from the outer buffer. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 291c608 commit 05dcc36

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

tests/phpunit/tests/media/wpStartCrossOriginIsolationOutputBuffer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,15 @@ public function test_filter_can_force_disable_dip() {
118118
public function test_output_buffer_adds_crossorigin_attributes() {
119119
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36';
120120

121+
// Start an outer buffer to capture the callback-processed output.
122+
ob_start();
123+
121124
wp_start_cross_origin_isolation_output_buffer();
122125
echo '<img src="https://external.example.com/image.jpg" />';
123126

124-
// Flush the output buffer to trigger the callback.
125-
$output = ob_get_flush();
127+
// Flush the inner buffer to trigger the callback, sending processed output to the outer buffer.
128+
ob_end_flush();
129+
$output = ob_get_clean();
126130

127131
$this->assertStringContainsString( 'crossorigin="anonymous"', $output );
128132
}

0 commit comments

Comments
 (0)