Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3498 Turn off "Delay JS" option when Safe Mode is activated #3574

Merged
merged 5 commits into from
Feb 16, 2021
Merged
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: 2 additions & 1 deletion inc/Engine/Admin/Deactivation/DeactivationIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public function activate_safe_mode() {
'rocket_safe_mode_reset_options',
[
'embeds' => 0,
'defer_all_js' => 0,
'async_css' => 0,
'lazyload' => 0,
'lazyload_iframes' => 0,
Expand All @@ -148,6 +147,8 @@ public function activate_safe_mode() {
'minify_concatenate_css' => 0,
'minify_js' => 0,
'minify_concatenate_js' => 0,
'defer_all_js' => 0,
'delay_js' => 0,
'minify_google_fonts' => 0,
'cdn' => 0,
]
Expand Down
1 change: 0 additions & 1 deletion inc/Engine/Optimization/DelayJS/Admin/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public static function get_subscribed_events() {
[ 'option_update_3_7_6_1', 13, 2 ],
],
'wp_ajax_rocket_restore_delay_js_defaults' => 'restore_defaults',
'rocket_safe_mode_reset_options' => 'add_options',
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

return [
'testShouldResetOptions' => [
'expected' => [
'embeds' => 0,
'async_css' => 0,
'lazyload' => 0,
'lazyload_iframes' => 0,
'lazyload_youtube' => 0,
'minify_css' => 0,
'minify_concatenate_css' => 0,
'minify_js' => 0,
'minify_concatenate_js' => 0,
'defer_all_js' => 0,
'delay_js' => 0,
'minify_google_fonts' => 0,
'cdn' => 0,
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function testShouldSendErrorWhenNoCapacity() {
$this->assertFalse( $response->success );
}

public function testShouldResetOptions() {
/**
* @dataProvider configTestData
*/
public function testShouldResetOptions( $expected ) {
CapTrait::setAdminCap();

$this->_setRole( 'administrator' );
Expand All @@ -53,24 +56,9 @@ public function testShouldResetOptions() {
$this->assertObjectHasAttribute( 'success', $response );
$this->assertTrue( $response->success );

$expected_subset = [
'embeds' => 0,
'defer_all_js' => 0,
'async_css' => 0,
'lazyload' => 0,
'lazyload_iframes' => 0,
'lazyload_youtube' => 0,
'minify_css' => 0,
'minify_concatenate_css' => 0,
'minify_js' => 0,
'minify_concatenate_js' => 0,
'minify_google_fonts' => 0,
'cdn' => 0,
];

$options = get_option( 'wp_rocket_settings' );

foreach ( $expected_subset as $key => $value ) {
foreach ( $expected as $key => $value ) {
$this->assertArrayHasKey( $key, $options );
$this->assertSame( $value, $options[$key] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,4 @@ public function testShouldDoExpectedForFirstInstallOptions( $input, $expected )
$this->assertSame( $expected, $actual );

}

/**
* @dataProvider configTestData
*/
public function testShouldDoExpectedForSafeModeResetOptions( $input, $expected ) {
$options = isset( $input['options'] ) ? $input['options'] : [];

$actual = apply_filters( 'rocket_safe_mode_reset_options', $options );

$this->assertSame( $expected, $actual );

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Mockery;
use Brain\Monkey\Functions;
use WPMedia\PHPUnit\Unit\TestCase;
use WP_Rocket\Tests\Unit\TestCase;
use WP_Rocket\Engine\Admin\Deactivation\DeactivationIntent;

/**
Expand Down Expand Up @@ -34,33 +34,21 @@ public function testShouldDoNothingWhenNoCapacity() {
$this->deactivation->activate_safe_mode();
}

public function testShouldResetOptions() {
$options = [
'embeds' => 0,
'defer_all_js' => 0,
'async_css' => 0,
'lazyload' => 0,
'lazyload_iframes' => 0,
'lazyload_youtube' => 0,
'minify_css' => 0,
'minify_concatenate_css' => 0,
'minify_js' => 0,
'minify_concatenate_js' => 0,
'minify_google_fonts' => 0,
'cdn' => 0,
];

/**
* @dataProvider configTestData
*/
public function testShouldResetOptions( $expected ) {
Functions\when( 'current_user_can' )->justReturn( true );

$this->options->shouldReceive( 'set_values' )
->once()
->with( $options );
->with( $expected );
$this->options->shouldReceive( 'get_options' )
->once()
->andReturn( $options );
->andReturn( $expected );
$this->options_api->shouldReceive( 'set' )
->once()
->with( 'settings', $options );
->with( 'settings', $expected );

Functions\expect( 'wp_send_json_success' )->once();

Expand Down