Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed failing test on wp version < 6.1.0
Browse files Browse the repository at this point in the history
jeawhanlee committed Apr 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f7c6663 commit 11e12d9
Showing 2 changed files with 31 additions and 9 deletions.
12 changes: 10 additions & 2 deletions tests/Integration/inc/functions/admin/rocketDeprecateAction.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

namespace WP_Rocket\Tests\Integration\inc\functions;

use WP_Rocket\Tests\Integration\IsolateHookTrait;
use WP_Rocket\Tests\Integration\TestCase;

/**
@@ -10,12 +11,19 @@
*/
class Test_RocketDeprecateAction extends TestCase {

use IsolateHookTrait;

public function set_up() {
add_filter( 'deprecated_hook_trigger_error', [ $this, 'return_false' ] );
parent::set_up();

add_action( 'deprecated_hook_run', [ $this, 'hook_callback' ] );
$this->unregisterAllCallbacksExcept('deprecated_hook_run', 'hook_callback');
}

public function tear_down() {
remove_filter( 'deprecated_hook_trigger_error', [ $this, 'return_true' ] );
$this->restoreWpHook('deprecated_hook_run');

parent::tear_down();
}

/**
28 changes: 21 additions & 7 deletions tests/Integration/inc/functions/admin/rocketDeprecateFilter.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

namespace WP_Rocket\Tests\Integration\inc\functions;

use WP_Rocket\Tests\Integration\IsolateHookTrait;
use WP_Rocket\Tests\Integration\TestCase;

/**
@@ -10,34 +11,47 @@
*/
class Test_RocketDeprecateFilter extends TestCase {

use IsolateHookTrait;

public function set_up() {
add_filter( 'deprecated_hook_trigger_error', [ $this, 'return_false' ] );
parent::set_up();

add_action( 'deprecated_hook_run', [ $this, 'action_hook_callback' ] );
$this->unregisterAllCallbacksExcept('deprecated_hook_run', 'action_hook_callback');
}

public function tear_down() {
remove_filter( 'deprecated_hook_trigger_error', [ $this, 'return_true' ] );
$this->restoreWpHook('deprecated_hook_run');

parent::tear_down();
}

/**
* @dataProvider providerTestData
*/
public function testShouldReturnExpected( $config, $expected ) {

add_filter( $config['old_hook'], [$this, 'hook_callback']);
global $wp_filters;

add_filter( $config['old_hook'], [$this, 'filter_hook_callback']);

rocket_deprecate_filter( $config['new_hook'], $config['args'], $config['version'], $config['old_hook'] );

$this->assertSame( $expected, did_filter( $config['new_hook'] ) );
$this->assertSame( $expected, did_filter( $config['old_hook'] ) );
$this->assertSame( $expected, $wp_filters[ $config['new_hook'] ] );

Check failure on line 40 in tests/Integration/inc/functions/admin/rocketDeprecateFilter.php

GitHub Actions / WP 5.8 with PHP 7.3 on ubuntu-latest.

Failed asserting that null is identical to 1.

Check failure on line 40 in tests/Integration/inc/functions/admin/rocketDeprecateFilter.php

GitHub Actions / WP 5.8 with PHP 7.3 on ubuntu-latest.

Failed asserting that null is identical to 1.
$this->assertSame( $expected, $wp_filters[ $config['old_hook'] ] );

remove_filter( $config['old_hook'], [$this, 'hook_callback']);
remove_filter( $config['old_hook'], [$this, 'filter_hook_callback']);
}

public function providerTestData() {
return $this->getTestData( __DIR__, basename( __FILE__, '.php' ) );
}

public function hook_callback() {
public function action_hook_callback() {
return;
}

public function filter_hook_callback() {
return true;
}

0 comments on commit 11e12d9

Please sign in to comment.