Skip to content

Commit

Permalink
Eliminate standard mode requirement for script caching now that preca…
Browse files Browse the repository at this point in the history
…ching is removed
  • Loading branch information
westonruter committed Nov 11, 2024
1 parent f06c830 commit 44bcf22
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
2 changes: 1 addition & 1 deletion includes/class-amp-service-worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function init() {
);
}

if ( $enabled_options['cdn_script_caching'] && amp_is_canonical() ) {
if ( $enabled_options['cdn_script_caching'] ) {
add_action( 'wp_front_service_worker', [ __CLASS__, 'add_cdn_script_caching' ] );
}
if ( $enabled_options['image_caching'] ) {
Expand Down
21 changes: 2 additions & 19 deletions tests/php/test-class-amp-service-worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,23 @@ public function set_up() {
}
}

public function data_to_test_default_init_hooks() {
return [
'standard' => [
'template_mode' => 'standard',
],
'legacy' => [
'template_mode' => 'reader',
],
];
}

/**
* Test default hooks in init.
*
* @covers \AMP_Service_Worker::init()
* @dataProvider data_to_test_default_init_hooks
*/
public function test_default_init_hooks( $template_mode ) {
public function test_default_init_hooks() {
remove_all_filters( 'query_vars' );
remove_all_actions( 'parse_request' );
remove_all_actions( 'wp' );
remove_all_actions( 'wp_front_service_worker' );
AMP_Options_Manager::update_option( Option::THEME_SUPPORT, $template_mode );

AMP_Service_Worker::init();
$this->assertSame( 10, has_filter( 'query_vars', [ 'AMP_Service_Worker', 'add_query_var' ] ) );
$this->assertSame( 10, has_action( 'parse_request', [ 'AMP_Service_Worker', 'handle_service_worker_iframe_install' ] ) );
$this->assertSame( 10, has_action( 'wp', [ 'AMP_Service_Worker', 'add_install_hooks' ] ) );

if ( amp_is_canonical() ) {
$this->assertEquals( 10, has_action( 'wp_front_service_worker', [ 'AMP_Service_Worker', 'add_cdn_script_caching' ] ) );
} else {
$this->assertFalse( has_action( 'wp_front_service_worker', [ 'AMP_Service_Worker', 'add_cdn_script_caching' ] ) );
}
$this->assertSame( 10, has_action( 'wp_front_service_worker', [ 'AMP_Service_Worker', 'add_cdn_script_caching' ] ) );
$this->assertFalse( has_action( 'wp_front_service_worker', [ 'AMP_Service_Worker', 'add_image_caching' ] ) );
$this->assertFalse( has_action( 'wp_front_service_worker', [ 'AMP_Service_Worker', 'add_google_fonts_caching' ] ) );
}
Expand Down

0 comments on commit 44bcf22

Please sign in to comment.