Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/wp-admin/includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,9 @@ function get_media_states( $post ) {
* @since 2.8.0
*/
function compression_test() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
?>
<script>
var compressionNonce = <?php echo wp_json_encode( wp_create_nonce( 'update_can_compress_scripts' ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>;
Expand Down
37 changes: 37 additions & 0 deletions tests/phpunit/tests/admin/includesTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,41 @@ public function data_get_submit_button_shorthand() {
'raw button-compact unchanged' => array( 'button-compact', 'button button-compact' ),
);
}

/**
* Tests that compression_test() has no effect for users who cannot
* manage_options, matching its own documented behavior.
*
* @ticket 65750
*
* @covers ::compression_test
*/
public function test_compression_test_outputs_nothing_for_user_without_manage_options() {
wp_set_current_user( self::$editor_id );

ob_start();
compression_test();
$output = ob_get_clean();
Comment on lines +562 to +564

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ob_start();
compression_test();
$output = ob_get_clean();
$output = get_echo( 'compression_test' );


$this->assertSame( '', $output );
}

/**
* Tests that compression_test() still outputs the test script for
* users who can manage_options.
*
* @ticket 65750
*
* @covers ::compression_test
*/
public function test_compression_test_outputs_script_for_user_with_manage_options() {
$admin_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
wp_set_current_user( $admin_id );

ob_start();
compression_test();
$output = ob_get_clean();
Comment on lines +581 to +583

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ob_start();
compression_test();
$output = ob_get_clean();
$output = get_echo( 'compression_test' );


$this->assertStringContainsString( 'testCompression', $output );
}
}
Loading