From 0a1722d2f18287529656ba3713abcb4fd64f2e64 Mon Sep 17 00:00:00 2001 From: Khadreal Date: Thu, 19 Dec 2024 15:14:11 +0100 Subject: [PATCH] Add integration test :sparkles: --- inc/ThirdParty/Plugins/Cookie/Termly.php | 8 +++-- .../Plugins/Cookie/excludeDelayJs.php | 13 ++++++++ .../Plugins/Cookie/excludeDelayJs.php | 31 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 tests/Fixtures/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php create mode 100644 tests/Integration/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php diff --git a/inc/ThirdParty/Plugins/Cookie/Termly.php b/inc/ThirdParty/Plugins/Cookie/Termly.php index d436f67de6..79e1ca783a 100644 --- a/inc/ThirdParty/Plugins/Cookie/Termly.php +++ b/inc/ThirdParty/Plugins/Cookie/Termly.php @@ -15,9 +15,7 @@ class Termly implements Subscriber_Interface { * @return array */ public static function get_subscribed_events() { - $termly_version = defined( 'TERMLY_VERSION' ); - - if ( ! $termly_version ) { + if ( ! defined( 'TERMLY_VERSION' ) ) { return []; } @@ -49,6 +47,10 @@ private function should_exclude(): bool { * @return array */ public function exclude_defer_js( array $exclude_delay_js ): array { + if ( ! $this->should_exclude() ) { + return $exclude_delay_js; + } + $exclude_delay_js[] = 'app.termly.io/resource-blocker/(.*)'; return $exclude_delay_js; diff --git a/tests/Fixtures/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php b/tests/Fixtures/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php new file mode 100644 index 0000000000..3ff6f30526 --- /dev/null +++ b/tests/Fixtures/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php @@ -0,0 +1,13 @@ + [ + 'config' => [ + 'excluded' => [], + 'termly_display_auto_blocker' => 'on' + ], + 'excluded' => [ + 'app.termly.io/resource-blocker/(.*)', + ] + ] +]; diff --git a/tests/Integration/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php b/tests/Integration/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php new file mode 100644 index 0000000000..f283cad7a9 --- /dev/null +++ b/tests/Integration/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php @@ -0,0 +1,31 @@ +once() + ->andReturn( $config['termly_display_auto_blocker'] ); + + $this->assertSame( $expected, $termly->exclude_defer_js( $config['excluded'] ) ); + } +}