Skip to content

Commit

Permalink
Add integration test ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Dec 19, 2024
1 parent 52c362d commit 0a1722d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
8 changes: 5 additions & 3 deletions inc/ThirdParty/Plugins/Cookie/Termly.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions tests/Fixtures/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [
'shouldExcludeTermlyResources' => [
'config' => [
'excluded' => [],
'termly_display_auto_blocker' => 'on'
],
'excluded' => [
'app.termly.io/resource-blocker/(.*)',
]
]
];
31 changes: 31 additions & 0 deletions tests/Integration/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Tests\Integration\inc\ThirdParty\Plugins\Cookie;

use WP_Rocket\Tests\Integration\TestCase;
use WP_Rocket\ThirdParty\Plugins\Cookie\Termly;
use Brain\Monkey\Functions;

/**
* Test class covering \WP_Rocket\ThirdParty\Plugins\Cookies\Termly::clean_domain
*
* @group Plugins
*/
class Test_ExcludeDelayJs extends TestCase {

protected $path_to_test_data = '/inc/ThirdParty/Plugins/Cookie/excludeDelayJs.php';

/**
* @dataProvider configTestData
*/
public function testShouldReturnExpected( $config, $expected ) {
$termly = new Termly();

Functions\expect( 'get_option' )
->once()
->andReturn( $config['termly_display_auto_blocker'] );

$this->assertSame( $expected, $termly->exclude_defer_js( $config['excluded'] ) );
}
}

0 comments on commit 0a1722d

Please sign in to comment.