You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$this->assertCount( 1, $action_args, 'Expected the wp_send_late_headers action to have been passed only one argument.' );
731
+
$this->assertSame( $processed_output, $action_args[0], 'Expected the arg passed to wp_send_late_headers to be the same as the processed output buffer.' );
710
732
}
711
733
712
734
/**
713
735
* Tests that wp_start_template_enhancement_output_buffer() starts the expected output buffer but ending with cleaning prevents any processing.
@@ -734,6 +761,14 @@ static function ( string $buffer ) use ( &$applied_filter ): string {
734
761
}
735
762
);
736
763
764
+
$mock_action_callback = newMockAction();
765
+
add_filter(
766
+
'wp_send_late_headers',
767
+
array( $mock_action_callback, 'action' ),
768
+
10,
769
+
PHP_INT_MAX
770
+
);
771
+
737
772
$this->assertCount( 0, headers_list(), 'Expected no headers to have been sent during unit tests.' );
738
773
ini_set( 'default_mimetype', 'text/html' ); // Since sending a header won't work.
739
774
@@ -765,34 +800,41 @@ static function ( string $buffer ) use ( &$applied_filter ): string {
765
800
766
801
$this->assertSame( $initial_ob_level, ob_get_level(), 'Expected the output buffer to be back at the initial level.' );
767
802
768
-
$this->assertFalse( $applied_filter, 'Expected the wp_template_enhancement_output_buffer filter to not have applied.' );
769
-
$this->assertSame( 0, did_action( 'wp_final_template_output_buffer' ), 'Expected the wp_final_template_output_buffer action to not have fired.' );
803
+
$this->assertSame( 0, $mock_filter_callback->get_call_count(), 'Expected the wp_template_enhancement_output_buffer filter to not have applied.' );
770
804
771
805
// Obtain the output via the wrapper output buffer.
772
806
$output = ob_get_clean();
773
807
$this->assertIsString( $output, 'Expected ob_get_clean() to return a string.' );
774
808
$this->assertStringNotContainsString( '<title>Unprocessed</title>', $output, 'Expected output buffer to not have string since the template was overridden.' );
775
809
$this->assertStringNotContainsString( '<title>Processed</title>', $output, 'Expected output buffer to not have string since the filter did not apply.' );
776
810
$this->assertStringContainsString( '<title>Output Buffer Not Processed</title>', $output, 'Expected output buffer to have string since the output buffer was ended with cleaning.' );
811
+
812
+
$this->assertSame( 0, did_action( 'wp_send_late_headers' ), 'Expected the wp_send_late_headers action to not have fired.' );
813
+
$this->assertSame( 0, $mock_action_callback->get_call_count(), 'Expected wp_send_late_headers action callback to have been called once.' );
777
814
}
778
815
779
816
/**
780
817
* Tests that wp_start_template_enhancement_output_buffer() starts the expected output buffer and cleaning allows the template to be replaced.
$this->assertTrue( wp_start_template_enhancement_output_buffer(), 'Expected wp_start_template_enhancement_output_buffer() to return true indicating the output buffer started.' );
866
932
$this->assertSame( 1, did_action( 'wp_template_enhancement_output_buffer_started' ), 'Expected the wp_template_enhancement_output_buffer_started action to have fired.' );
@@ -894,6 +960,12 @@ public function test_wp_start_template_enhancement_output_buffer_for_json(): voi
894
960
$output = ob_get_clean();
895
961
$this->assertIsString( $output, 'Expected ob_get_clean() to return a string.' );
896
962
$this->assertSame( $json, $output, 'Expected output to not be processed.' );
963
+
964
+
$this->assertSame( 1, did_action( 'wp_send_late_headers' ), 'Expected the wp_send_late_headers action to have fired even though the wp_template_enhancement_output_buffer filter did not apply.' );
965
+
$this->assertSame( 1, $mock_action_callback->get_call_count(), 'Expected wp_send_late_headers action callback to have been called once.' );
0 commit comments