diff --git a/tests/test-template.php b/tests/test-template.php new file mode 100644 index 000000000..6d81766f0 --- /dev/null +++ b/tests/test-template.php @@ -0,0 +1,66 @@ +assertEquals( 10, has_action( 'wp_footer', 'wp_service_worker_offline_page_reload' ) ); + $this->assertEquals( 10, has_action( 'error_footer', 'wp_service_worker_offline_page_reload' ) ); + + // Check when method is GET but not offline or 500. + $actual_script = wp_service_worker_offline_page_reload(); + $this->assertEquals( $_SERVER['REQUEST_METHOD'], 'GET' ); + $this->assertFalse( is_offline() ); + $this->assertFalse( is_500() ); + $this->assertEmpty( $actual_script ); + + // Check if script is added when offline. + $error_template_url = add_query_arg( 'wp_error_template', 'offline', home_url( '/', 'relative' ) ); + $this->go_to( $error_template_url ); + + ob_start(); + wp_service_worker_offline_page_reload(); + $actual_script = ob_get_clean(); + $this->assertEquals( $_SERVER['REQUEST_METHOD'], 'GET' ); + $this->assertTrue( is_offline() ); + $this->assertFalse( is_500() ); + $this->assertStringContainsString( ' +