Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for use_output_buffer
  • Loading branch information
westonruter committed Aug 17, 2023
commit add3a0448d1f9297ee202e5cb1184cb956447e1b
54 changes: 50 additions & 4 deletions tests/server-timing/perflab-server-timing-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,56 @@ public function data_get_header() {
);
}

public function test_use_output_buffer() {
$this->assertFalse( $this->server_timing->use_output_buffer() );
public function get_data_to_test_use_output_buffer() {
$enable_option = static function () {
$option = (array) get_option( PERFLAB_SERVER_TIMING_SETTING );
$option['output_buffering'] = true;
update_option( PERFLAB_SERVER_TIMING_SETTING, $option );
};
$disable_option = static function () {
$option = (array) get_option( PERFLAB_SERVER_TIMING_SETTING );
$option['output_buffering'] = false;
update_option( PERFLAB_SERVER_TIMING_SETTING, $option );
};

add_filter( 'perflab_server_timing_use_output_buffer', '__return_true' );
$this->assertTrue( $this->server_timing->use_output_buffer() );
return array(
'default' => array(
'set_up' => static function () {},
'expected' => false,
),
'option-enabled' => array(
'set_up' => $enable_option,
'expected' => true,
),
'option-disabled' => array(
'set_up' => $disable_option,
'expected' => false,
),
'filter-enabled' => array(
'set_up' => static function () use ( $disable_option ) {
$disable_option();
add_filter( 'perflab_server_timing_use_output_buffer', '__return_true' );
},
'expected' => true,
),
'filter-disabled' => array(
'set_up' => static function () use ( $enable_option ) {
$enable_option();
add_filter( 'perflab_server_timing_use_output_buffer', '__return_false' );
},
'expected' => false,
),
);
}

/**
* @covers Perflab_Server_Timing::use_output_buffer
* @dataProvider get_data_to_test_use_output_buffer
* @param callable $set_up Set up.
* @param bool $expected Expected value.
Comment thread
westonruter marked this conversation as resolved.
*/
public function test_use_output_buffer( callable $set_up, $expected ) {
$set_up();
$this->assertSame( $expected, $this->server_timing->use_output_buffer() );
}
}